mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-13 02:18:50 -04:00
Refactor create organisation code into model
So the view layer is cleaner.
This commit is contained in:
@@ -31,7 +31,7 @@ from app.main.forms import (
|
||||
SetLetterBranding,
|
||||
)
|
||||
from app.main.views.service_settings import get_branding_as_value_and_label
|
||||
from app.models.organisation import Organisations
|
||||
from app.models.organisation import Organisation, Organisations
|
||||
from app.models.user import InvitedOrgUser, User
|
||||
from app.utils import user_has_permissions, user_is_platform_admin
|
||||
|
||||
@@ -54,17 +54,7 @@ def add_organisation():
|
||||
form = NewOrganisationForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
organisations_client.create_organisation(
|
||||
name=form.name.data,
|
||||
crown={
|
||||
'crown': True,
|
||||
'non-crown': False,
|
||||
'unknown': None,
|
||||
}.get(form.crown_status.data),
|
||||
organisation_type=form.organisation_type.data,
|
||||
agreement_signed=False,
|
||||
)
|
||||
|
||||
Organisation.create_from_form(form)
|
||||
return redirect(url_for('.organisations'))
|
||||
|
||||
return render_template(
|
||||
|
||||
@@ -38,6 +38,27 @@ class Organisation(JSONModel):
|
||||
def from_service(cls, service_id):
|
||||
return cls(organisations_client.get_service_organisation(service_id))
|
||||
|
||||
@classmethod
|
||||
def create_from_form(cls, form):
|
||||
return cls.create(
|
||||
name=form.name.data,
|
||||
crown={
|
||||
'crown': True,
|
||||
'non-crown': False,
|
||||
'unknown': None,
|
||||
}.get(form.crown_status.data),
|
||||
organisation_type=form.organisation_type.data,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create(cls, name, crown, organisation_type, agreement_signed=False):
|
||||
return cls(organisations_client.create_organisation(
|
||||
name=name,
|
||||
crown=crown,
|
||||
organisation_type=organisation_type,
|
||||
agreement_signed=agreement_signed,
|
||||
))
|
||||
|
||||
def __init__(self, _dict):
|
||||
|
||||
super().__init__(_dict)
|
||||
|
||||
@@ -32,11 +32,16 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
||||
raise error
|
||||
|
||||
@cache.delete('organisations')
|
||||
def create_organisation(self, name):
|
||||
data = {
|
||||
"name": name
|
||||
}
|
||||
return self.post(url="/organisations", data=data)
|
||||
def create_organisation(self, name, crown, organisation_type, agreement_signed):
|
||||
return self.post(
|
||||
url="/organisations",
|
||||
data={
|
||||
"name": name,
|
||||
"crown": crown,
|
||||
"organisation_type": organisation_type,
|
||||
"agreement_signed": agreement_signed,
|
||||
}
|
||||
)
|
||||
|
||||
@cache.delete('domains')
|
||||
@cache.delete('organisations')
|
||||
|
||||
Reference in New Issue
Block a user