Created
September 7, 2016 13:53
-
-
Save loic/4f8726af88d5f0350cec7c5e2a1d8c11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/scope/foodnet/apps/mobile/importer.py b/scope/foodnet/apps/mobile/importer.py | |
index 2ce4f0e..f6db43c 100644 | |
--- a/scope/foodnet/apps/mobile/importer.py | |
+++ b/scope/foodnet/apps/mobile/importer.py | |
@@ -76,6 +76,10 @@ class MobileHouseholdImporter(object): | |
member = Person(uuid=member_uuid) | |
created = True | |
+ # Backwards compat for < 1.0.3 | |
+ if 'info' not in member_data: | |
+ member_data['info'] = member_data.copy() | |
+ | |
member.last_name = member_data.get('lastName', '') | |
member.first_name = member_data.get('firstName', '') | |
member.middle_name = member_data.get('middleName', '') | |
@@ -160,7 +164,6 @@ class MobileHouseholdImporter(object): | |
def import_household(self): | |
household = None | |
household_uuid = None | |
- household_name = None | |
cycle_subscription = None | |
if self.token_mapping == 'UUID': | |
diff --git a/scope/foodnet/apps/mobile/serializers.py b/scope/foodnet/apps/mobile/serializers.py | |
index 88eaf1e..3744f0a 100644 | |
--- a/scope/foodnet/apps/mobile/serializers.py | |
+++ b/scope/foodnet/apps/mobile/serializers.py | |
@@ -72,10 +72,7 @@ def get_attachment_key_for_fingerprint_template(person, fingerprint): | |
to_mobile_choice(FINGERPRINT_FINGER_MAPPING, fingerprint.finger), | |
) | |
- | |
-class PersonSerializer(serializers.Serializer): | |
- | |
- id = UUIDField(source='uuid') | |
+class PersonInfoSerializer(serializers.Serializer): | |
firstName = serializers.CharField(source='first_name') | |
middleName = serializers.CharField(source='middle_name') | |
@@ -114,6 +111,13 @@ class PersonSerializer(serializers.Serializer): | |
homePhone = serializers.CharField(source='phone_number') | |
mobilePhone = serializers.CharField(source='mobile_number') | |
+ | |
+class PersonSerializer(serializers.Serializer): | |
+ | |
+ id = UUIDField(source='uuid') | |
+ | |
+ info = PersonInfoSerializer(source='*') | |
+ | |
photo = serializers.SerializerMethodField() | |
def get_photo(self, obj): | |
diff --git a/scope/foodnet/apps/mobile/tests.py b/scope/foodnet/apps/mobile/tests.py | |
index 0f0ccbe..022c9b8 100644 | |
--- a/scope/foodnet/apps/mobile/tests.py | |
+++ b/scope/foodnet/apps/mobile/tests.py | |
@@ -6,7 +6,7 @@ from rest_framework.renderers import JSONRenderer | |
from foodnet.apps.mobile.constants import BENEFICIARY_TYPE_MAPPING, GENDER_MAPPING, ROLE_MAPPING, to_mobile_choice | |
from foodnet.apps.mobile.serializers import PersonSerializer, HouseholdSerializer, format_uuid, \ | |
- get_attachment_key_for_photo | |
+ get_attachment_key_for_photo, PersonInfoSerializer | |
from foodnet.apps.registration.factories import person_factory, household_factory | |
from foodnet.apps.wfp.factories import office_factory | |
@@ -25,18 +25,20 @@ class TestSerializers(TestCase): | |
def _get_control_data_for_person(self, person): | |
return { | |
'id': format_uuid(person.uuid), | |
- 'firstName': person.first_name, | |
- 'middleName': person.middle_name, | |
- 'lastName': person.last_name, | |
- 'gender': to_mobile_choice(GENDER_MAPPING, person.gender), | |
- 'dateOfBirth': str(person.date_of_birth), | |
- 'dateOfBirthExact': person.date_of_birth_is_exact, | |
- 'role': to_mobile_choice(ROLE_MAPPING, person.household_role), | |
- 'recipient': PersonSerializer().get_recipient(person), | |
- 'documentType': PersonSerializer().get_document_type(person), | |
- 'documentNumber': PersonSerializer().get_document_number(person), | |
- 'homePhone': person.phone_number, | |
- 'mobilePhone': person.mobile_number, | |
+ 'info': { | |
+ 'firstName': person.first_name, | |
+ 'middleName': person.middle_name, | |
+ 'lastName': person.last_name, | |
+ 'gender': to_mobile_choice(GENDER_MAPPING, person.gender), | |
+ 'dateOfBirth': str(person.date_of_birth), | |
+ 'dateOfBirthExact': person.date_of_birth_is_exact, | |
+ 'role': to_mobile_choice(ROLE_MAPPING, person.household_role), | |
+ 'recipient': PersonInfoSerializer().get_recipient(person), | |
+ 'documentType': PersonInfoSerializer().get_document_type(person), | |
+ 'documentNumber': PersonInfoSerializer().get_document_number(person), | |
+ 'homePhone': person.phone_number, | |
+ 'mobilePhone': person.mobile_number, | |
+ }, | |
'photo': get_attachment_key_for_photo(person), | |
'fingerprints': PersonSerializer().get_fingerprints(person), | |
'meta': {}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment