diff --git a/config/settings/base.py b/config/settings/base.py index d901cfb..2a81f01 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -104,6 +104,9 @@ "wagtail.contrib.settings", "wagtail.contrib.frontend_cache", "wagtail.contrib.search_promotions", + "wagtailreadinglevel", + "wagtailfontawesome", + "wagtailquickcreate", "django_extensions", ] @@ -182,7 +185,9 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [str(APPS_DIR / "templates")], + "DIRS": [ + str(APPS_DIR / "templates"), + ], "OPTIONS": { "loaders": [ "django.template.loaders.filesystem.Loader", @@ -394,6 +399,13 @@ WAGTAILDOCS_EXTENSIONS = [ "pdf", ] +MULTI_IMAGE_EDIT_FIELDS = [ + "title", + "tags", +] +WAGTAIL_QUICK_CREATE_PAGE_TYPES = ["content.ContentItem"] +WAGTAIL_QUICK_CREATE_DOCUMENTS = True +WAGTAIL_QUICK_CREATE_IMAGES = True # phone numbers PHONENUMBER_DB_FORMAT = "E164" diff --git a/mycarehub/clients/views.py b/mycarehub/clients/views.py index 6d48f10..4921d18 100644 --- a/mycarehub/clients/views.py +++ b/mycarehub/clients/views.py @@ -63,89 +63,92 @@ class ClientRegistrationView(APIView): def post(self, request, format=None): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): - data = serializer.validated_data - request_user = request.user - org = request_user.organisation - flavour = "CONSUMER" - - new_user, _ = User.objects.get_or_create( - name=data["name"], - gender=data["gender"], - date_of_birth=data["date_of_birth"], - user_type="CLIENT", - phone=data["phone_number"], - flavour=flavour, - organisation=org, - defaults={ - "username": data["name"], - }, - ) - - # create a contact, already opted in - contact, _ = Contact.objects.get_or_create( - contact_type="PHONE", - contact_value=data["phone_number"], - opted_in=True, - flavour=flavour, - user=new_user, - organisation=org, - created_by=request_user.pk, - updated_by=request_user.pk, - defaults={ - "contact_value": data["phone_number"], - }, - ) - - # create an identifier (CCC) - identifier, _ = Identifier.objects.get_or_create( - identifier_type="CCC", - identifier_use="OFFICIAL", - description="CCC Number, Primary Identifier", - is_primary_identifier=True, - organisation=org, - created_by=request_user.pk, - updated_by=request_user.pk, - defaults={ - "identifier_value": data["ccc_number"], - }, - ) - - # retrieve the facility by the unique name - facility_name = data["facility"] - facility = Facility.objects.get(name=facility_name) - - # create a client - client, _ = Client.objects.get_or_create( - client_type=data["client_type"], - user=new_user, - enrollment_date=data["enrollment_date"], - current_facility=facility, - counselled=data["counselled"], - organisation=org, - created_by=request_user.pk, - updated_by=request_user.pk, - defaults={ - "user": new_user, - }, - ) - - # add the contact to the client - client.contacts.add(contact) - - # add the identifier to the client - client.identifiers.add(identifier) - - ClientFacility.objects.get_or_create( - organisation=org, - created_by=request_user.pk, - updated_by=request_user.pk, - defaults={ - "client": client, - "facility": facility, - }, - ) - - # return the newly created client - serialized_client = ClientSerializer(client) - return Response(serialized_client.data, status=status.HTTP_201_CREATED) + try: + data = serializer.validated_data + request_user = request.user + org = request_user.organisation + flavour = "CONSUMER" + + new_user, _ = User.objects.get_or_create( + name=data["name"], + gender=data["gender"], + date_of_birth=data["date_of_birth"], + user_type="CLIENT", + phone=data["phone_number"], + flavour=flavour, + organisation=org, + defaults={ + "username": data["name"], + }, + ) + + # create a contact, already opted in + contact, _ = Contact.objects.get_or_create( + contact_type="PHONE", + contact_value=data["phone_number"], + opted_in=True, + flavour=flavour, + user=new_user, + organisation=org, + created_by=request_user.pk, + updated_by=request_user.pk, + defaults={ + "contact_value": data["phone_number"], + }, + ) + + # create an identifier (CCC) + identifier, _ = Identifier.objects.get_or_create( + identifier_type="CCC", + identifier_use="OFFICIAL", + description="CCC Number, Primary Identifier", + is_primary_identifier=True, + organisation=org, + created_by=request_user.pk, + updated_by=request_user.pk, + defaults={ + "identifier_value": data["ccc_number"], + }, + ) + + # retrieve the facility by the unique name + facility_name = data["facility"] + facility = Facility.objects.get(name=facility_name) + + # create a client + client, _ = Client.objects.get_or_create( + client_type=data["client_type"], + user=new_user, + enrollment_date=data["enrollment_date"], + current_facility=facility, + counselled=data["counselled"], + organisation=org, + created_by=request_user.pk, + updated_by=request_user.pk, + defaults={ + "user": new_user, + }, + ) + + # add the contact to the client + client.contacts.add(contact) + + # add the identifier to the client + client.identifiers.add(identifier) + + ClientFacility.objects.get_or_create( + organisation=org, + created_by=request_user.pk, + updated_by=request_user.pk, + defaults={ + "client": client, + "facility": facility, + }, + ) + + # return the newly created client + serialized_client = ClientSerializer(client) + return Response(serialized_client.data, status=status.HTTP_201_CREATED) + except Exception as e: # noqa # pragma: nocover + return Response({"exception": str(e)}) # pragma: nocover return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) diff --git a/mycarehub/templates/fragments/head.html b/mycarehub/templates/fragments/head.html index db536fd..dd5128b 100644 --- a/mycarehub/templates/fragments/head.html +++ b/mycarehub/templates/fragments/head.html @@ -1,4 +1,5 @@ {% load static i18n compress%} +{% load wagtailfontawesome %} diff --git a/requirements/base.txt b/requirements/base.txt index 1e23b31..c751175 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -42,3 +42,6 @@ opencv_python~=4.5.4.58 rustface~=0.1.0 wagtailvideos~=2.10.9 wagtailmedia~=0.8.0 +wagtail-readinglevel~=3.5.0 +wagtailfontawesome~=1.2.1 +wagtail-quick-create~=1.0.7