robogals / myrobogals

myRobogals is the global intranet and record-keeping tool for Robogals. It has been built to simplify many of our day-to-day tasks including organising school visits, maintaining a member database, communicating with members, storing records reliably for future generations and easily collecting statistics on a global scale.
https://my.robogals.org
10 stars 21 forks source link

Fix user manager operation for user saving #85

Closed manhinli closed 7 years ago

manhinli commented 10 years ago

We have specific procedures when saving users which are not adhered to in admin forms because they use our custom form myrg_users.forms.RobogalsUserCreationForm.

Attempt to use the existing user validation/correction method under myrg_users.models.RobogalsUserManager

manhinli commented 10 years ago

This affects the REST API as well.

yfcheung commented 10 years ago

http://stackoverflow.com/questions/10574218/creating-an-add-user-form-in-django problem:

user = super(RobogalsUserCreationForm, self).save(commit=False) # form checks is involved
vs
user = RobogalsUser.objects.create_user(**self.cleaned_data) # manager check is involved

what about using both:

user = super(RobogalsUserCreationForm, self).save(commit=False)
user = RobogalsUser.objects.create_user(**user.__dict__)

settings.py: where is

AUTH_USER_MODEL = 'myrg_users.models.RobogalsUser'
manhinli commented 10 years ago

Could you fork and add your code as appropriate? Because I need to see how this fits in.

yfcheung commented 10 years ago

Approach 1:

clean_<field>() # add the individual field cleaner

Approach 2

clean() # over ride the original cleaner and add extra manager checks in addition to the original form checks

How to avoid the problem of: changing in multiple places?

manhinli commented 10 years ago

As I said before, can you implement at least one to show how you would do it?