def obj_create(self, bundle, **kwargs): #Validate that the needed fields exist validator = CustomFormValidation(form_class=UserForm, model_type=self._meta.resource_name) errors = validator.is_valid(bundle) if isinstance(errors, ErrorDict): raise BadRequest(errors.as_text()) #Extract needed fields username, password, email = bundle.data['username'], bundle.data['password'], bundle.data['email'] data_dict = {'username' : username, 'email' : email, 'password' : password, 'password1' : password, 'password2' : password} #Pass the fields to django-allauth. We want to use its email verification setup. signup_form = SignupForm() signup_form.cleaned_data = data_dict try: try: user = signup_form.save(bundle.request) profile, created = UserProfile.objects.get_or_create(user=user) except AssertionError: #If this fails, the user has a non-unique email address. user = User.objects.get(username=username) user.delete() raise BadRequest("Email address has already been used, try another.") #Need this so that the object is added to the bundle and exists during the dehydrate cycle. html = complete_signup(bundle.request, user, "") bundle.obj = user except IntegrityError: raise BadRequest("Username is already taken, try another.") return bundle
class Meta: queryset = EssayGrade.objects.all() resource_name = 'essaygrade' serializer = default_serialization() authorization= default_authorization() authentication = default_authentication() always_return_data = True model_type = EssayGrade throttle = default_throttling() validation = CustomFormValidation(form_class=EssayGradeForm, model_type=resource_name)
class Meta: queryset = Problem.objects.all() resource_name = 'problem' serializer = default_serialization() authorization= default_authorization() authentication = default_authentication() always_return_data = True model_type = Problem throttle = default_throttling() validation = CustomFormValidation(form_class=ProblemForm, model_type=resource_name)