Skip to content

Commit

Permalink
Merge pull request #123 from vigilate/issue_105-eax
Browse files Browse the repository at this point in the history
Use instance.id instead of data['id'] + add {'detail': } in error msg
  • Loading branch information
eax64 committed Aug 10, 2016
2 parents c900ab0 + fb608d4 commit adc5344
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions vigilate_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def create(self, validated_data):
return user

def validate(self, data):
if not 'id' in data :
if not hasattr(self.instance, "id"):
return data

prev_state = models.User.objects.get(id=data['id'])
prev_state = models.User.objects.get(id=self.instance.id)
if 'default_alert_type' in data and data['default_alert_type'] == models.User.SMS and\
(('phone' in data and not data['phone']) or (not 'phone' in data and not prev_state.phone)):
raise serializers.ValidationError('Cannot enable sms alert for an user without a phone number registered')
raise serializers.ValidationError({'detail': 'Cannot enable sms alert for an user without a phone number registered'})
return data

def update(self, instance, validated_data):
Expand Down Expand Up @@ -65,7 +65,7 @@ def create(self, validated_data):
def validate(self, data):
if (not 'alert_type_default' in data or not data['alert_type_default']) and\
('sms_enabled' in data and data['sms_enabled']) and not data['user'].phone:
raise serializers.ValidationError('Cannot enable sms alert for an user without a phone number registered')
raise serializers.ValidationError({'detail': 'Cannot enable sms alert for an user without a phone number registered'})
return data

def update(self, instance, validated_data):
Expand Down

0 comments on commit adc5344

Please sign in to comment.