Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Aug 9, 2019
1 parent 321a200 commit 43c2a39
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/etools/applications/audit/serializers/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AuditorStaffMemberSerializer(BaseStaffMemberSerializer):
def validate(self, attrs):
validated_data = super().validate(attrs)
user_pk = validated_data.pop('user_pk', None)

if user_pk:
if hasattr(user_pk, 'purchase_order_auditorstaffmember'):
firm = user_pk.purchase_order_auditorstaffmember.auditor_firm
Expand All @@ -47,12 +48,13 @@ def validate(self, attrs):
validated_data['user'] = user_pk
elif 'user' not in validated_data:
raise serializers.ValidationError({'user': _('This field is required.')})
else:
try:
email = validated_data['user'].get('email', 'invalid')
validated_data['user'] = get_user_model().objects.get(email=email)
except get_user_model().DoesNotExist:
pass
elif 'user' in validated_data:
email = validated_data['user'].get('email', None)
if not AuditorStaffMember.objects.filter(user__email=email).exists():
try:
validated_data['user'] = get_user_model().objects.get(email=email, email__isnull=False)
except get_user_model().DoesNotExist:
pass

return validated_data

Expand Down

0 comments on commit 43c2a39

Please sign in to comment.