Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split users/models.py into individual files #421

Merged
merged 12 commits into from
Feb 9, 2023
47 changes: 47 additions & 0 deletions users/custom_user_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from django.contrib.auth.models import BaseUserManager
import datetime
from django.utils.translation import gettext_lazy as _


class CustomUserManager(BaseUserManager):
def create_superuser(self, email, first_name, last_name, phone, password):
user = self.model(
email=email, first_name=first_name, last_name=last_name, phone=phone
)
user.set_password(password)
user.is_staff = True
user.is_superuser = True

# fill in some dummy data as they are required.
# when registration works this wont be needed (we just need a way
# of elevating a user to staff status)
user.birthday = datetime.datetime.now()

user.save(using=self.db)
return user

def create_customuser(
self,
email,
first_name,
last_name,
phone,
birthday,
municipality,
nick,
):
if not email:
raise ValueError(_("User must have an email address"))

user = self.model(
email=email,
first_name=first_name,
last_name=last_name,
phone=phone,
birthday=birthday,
municipality=municipality,
nick=nick,
)

user.save(using=self.db)
return user
Loading