user_validation.py 872 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from tastypie.validation import Validation
  4. class UserValidation(Validation):
  5. '''
  6. '''
  7. def is_valid(self, bundle, request=None):
  8. if not bundle.data:
  9. return {
  10. '__all__': 'data not provided in bundle'
  11. }
  12. errors = {}
  13. if not 'first_name' in bundle.data:
  14. errors['first_name'] = 'this field is required'
  15. if not 'last_name' in bundle.data:
  16. errors['last_name'] = 'this field is required'
  17. if not 'username' in bundle.data:
  18. errors['username'] = 'this field is required'
  19. if not 'email' in bundle.data:
  20. errors['email'] = 'this field is required'
  21. if not 'password' in bundle.data:
  22. errors['password'] = 'this field is required'
  23. return errors