mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -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,
|
SetLetterBranding,
|
||||||
)
|
)
|
||||||
from app.main.views.service_settings import get_branding_as_value_and_label
|
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.models.user import InvitedOrgUser, User
|
||||||
from app.utils import user_has_permissions, user_is_platform_admin
|
from app.utils import user_has_permissions, user_is_platform_admin
|
||||||
|
|
||||||
@@ -54,17 +54,7 @@ def add_organisation():
|
|||||||
form = NewOrganisationForm()
|
form = NewOrganisationForm()
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
organisations_client.create_organisation(
|
Organisation.create_from_form(form)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
return redirect(url_for('.organisations'))
|
return redirect(url_for('.organisations'))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|||||||
@@ -38,6 +38,27 @@ class Organisation(JSONModel):
|
|||||||
def from_service(cls, service_id):
|
def from_service(cls, service_id):
|
||||||
return cls(organisations_client.get_service_organisation(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):
|
def __init__(self, _dict):
|
||||||
|
|
||||||
super().__init__(_dict)
|
super().__init__(_dict)
|
||||||
|
|||||||
@@ -32,11 +32,16 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
|||||||
raise error
|
raise error
|
||||||
|
|
||||||
@cache.delete('organisations')
|
@cache.delete('organisations')
|
||||||
def create_organisation(self, name):
|
def create_organisation(self, name, crown, organisation_type, agreement_signed):
|
||||||
data = {
|
return self.post(
|
||||||
"name": name
|
url="/organisations",
|
||||||
}
|
data={
|
||||||
return self.post(url="/organisations", data=data)
|
"name": name,
|
||||||
|
"crown": crown,
|
||||||
|
"organisation_type": organisation_type,
|
||||||
|
"agreement_signed": agreement_signed,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@cache.delete('domains')
|
@cache.delete('domains')
|
||||||
@cache.delete('organisations')
|
@cache.delete('organisations')
|
||||||
|
|||||||
Reference in New Issue
Block a user