Skip to content

Commit

Permalink
feat: usability improvements for client creation form
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Nov 24, 2021
1 parent 94f06ad commit 80cf489
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@
"rest_framework_datatables.renderers.DatatablesRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
"rest_framework.renderers.AdminRenderer",
"rest_framework.renderers.HTMLFormRenderer",
"rest_framework.renderers.StaticHTMLRenderer",
),
"DEFAULT_PARSER_CLASSES": (
"rest_framework.parsers.JSONParser",
Expand Down
2 changes: 1 addition & 1 deletion mycarehub/clients/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def validate_date_past(value):
def get_facility_choices():
choices = []
for facility in Facility.objects.all():
choices.append((facility.pk, facility.name))
choices.append((facility.name, facility.name))

return choices

Expand Down
2 changes: 1 addition & 1 deletion mycarehub/clients/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_client_registration_view_valid(user_with_all_permissions, client):
response = client.post(
url,
data={
"facility": facility.pk,
"facility": facility.name,
"client_type": "PMTCT",
"name": fake.name(),
"gender": "MALE",
Expand Down
13 changes: 5 additions & 8 deletions mycarehub/clients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ class ClientFacilityViewSet(ModelViewSet):

class ClientRegistrationView(APIView):
queryset = Client.objects.all() # to enable model permissions
serializer_class = ClientRegistrationSerializer

@transaction.atomic
def post(self, request, format=None):
serializer_data = request.data
serializer_data["organisation"] = request.user.organisation
serializer_data["user"] = request.user

serializer = ClientRegistrationSerializer(data=serializer_data)
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
data = serializer.validated_data
request_user = request.user
Expand Down Expand Up @@ -113,9 +110,9 @@ def post(self, request, format=None):
},
)

# retrieve the facility
facility_id = data["facility"]
facility = Facility.objects.get(pk=facility_id)
# 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(
Expand Down

0 comments on commit 80cf489

Please sign in to comment.