# Path: user/forms.py
# class UserChangeForm(BaseUserChangeForm):
#     """For UserAdmin."""
# 
#     class Meta(BaseUserChangeForm.Meta):
#         model = get_user_model()
# 
# class UserCreationForm(
#         ActivationMailFormMixin,
#         BaseUserCreationForm):
# 
#     name = forms.CharField(
#         max_length=255,
#         help_text=(
#             "The name displayed on your "
#             "public profile."))
# 
#     mail_validation_error = (
#         'User created. Could not send activation '
#         'email. Please try again later. (Sorry!)')
# 
#     class Meta(BaseUserCreationForm.Meta):
#         model = get_user_model()
#         fields = ('name', 'email')
# 
#     def clean_name(self):
#         name = self.cleaned_data['name']
#         disallowed = (
#             'activate',
#             'create',
#             'disable',
#             'login',
#             'logout',
#             'password',
#             'profile',
#         )
#         if name in disallowed:
#             raise ValidationError(
#                 "A user with that name"
#                 " already exists.")
#         return name
# 
#     def save(self, **kwargs):
#         user = super().save(commit=False)
#         if not user.pk:
#             user.is_active = False
#             send_mail = True
#         else:
#             send_mail = False
#         user.save()
#         self.save_m2m()
#         Profile.objects.update_or_create(
#             user=user,
#             defaults={
#                 'name': self.cleaned_data['name'],
#                 'slug': slugify(
#                     self.cleaned_data['name']),
#             })
#         if send_mail:
#             self.send_mail(user=user, **kwargs)
#         return user
# 
# Path: user/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(
#         settings.AUTH_USER_MODEL)
#     name = models.CharField(
#         max_length=255)
#     slug = models.SlugField(
#         max_length=30,
#         unique=True)
#     about = models.TextField()
#     joined = models.DateTimeField(
#         "Date Joined",
#         auto_now_add=True)
# 
#     objects = ProfileManager()
# 
#     def __str__(self):
#         return self.user.get_username()
# 
#     def get_absolute_url(self):
#         return reverse(
#             'dj-auth:public_profile',
#             kwargs={'slug': self.slug})
# 
#     def get_update_url(self):
#         return reverse('dj-auth:profile_update')
# 
#     def natural_key(self):
#         return (self.slug,)
#     natural_key.dependencies = ['user.user']
# 
# class User(AbstractBaseUser, PermissionsMixin):
#     email = models.EmailField(
#         'email address',
#         max_length=254,
#         unique=True)
#     is_staff = models.BooleanField(
#         'staff status',
#         default=False,
#         help_text=(
#             'Designates whether the user can '
#             'log into this admin site.'))
#     is_active = models.BooleanField(
#         'active',
#         default=True,
#         help_text=(
#             'Designates whether this user should '
#             'be treated as active. Unselect this '
#             'instead of deleting accounts.'))
# 
#     USERNAME_FIELD = 'email'
# 
#     objects = UserManager()
# 
#     def __str__(self):
#         return self.email
# 
#     def get_absolute_url(self):
#         return self.profile.get_absolute_url()
# 
#     def get_full_name(self):
#         return self.profile.name
# 
#     def get_short_name(self):
#         return self.profile.name
# 
#     def published_posts(self):
#         return self.blog_posts.filter(
#             pub_date__lt=date.today())
# 
#     def natural_key(self):
#         return (self.email,)


from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin.options import \
    IS_POPUP_VAR
from django.contrib.admin.utils import unquote
from django.contrib.auth import \
    update_session_auth_hash
from django.contrib.auth.forms import \
    AdminPasswordChangeForm
from django.contrib.messages import success
from django.core.exceptions import \
    PermissionDenied
from django.http import (
    Http404, HttpResponseRedirect)
from django.template.response import \
    TemplateResponse
from django.utils.decorators import \
    method_decorator
from django.utils.encoding import force_text
from django.utils.html import escape
from django.views.decorators.debug import \
    sensitive_post_parameters
from .forms import (
    UserChangeForm, UserCreationForm)
from .models import Profile, User
    ordering = ('email',)
    search_fields = ('email',)
    # form view
    fieldsets = (
        (None, {
            'fields': ('email', 'password')}),
        ('Permissions', {
            'classes': ('collapse',),
            'fields': (
                'is_active',
                'is_staff',
                'is_superuser',
                'groups',
                'user_permissions')}),
        ('Important dates', {
            'classes': ('collapse',),
            'fields': ('last_login',)}),
    )
    filter_horizontal = (
        'groups', 'user_permissions',)
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': (
                'name',
                'email',
                'password1',
                'password2')
        }),
    )

# Path: user/forms.py
# class UserChangeForm(BaseUserChangeForm):
#     """For UserAdmin."""
# 
#     class Meta(BaseUserChangeForm.Meta):
#         model = get_user_model()
# 
# class UserCreationForm(
#         ActivationMailFormMixin,
#         BaseUserCreationForm):
# 
#     name = forms.CharField(
#         max_length=255,
#         help_text=(
#             "The name displayed on your "
#             "public profile."))
# 
#     mail_validation_error = (
#         'User created. Could not send activation '
#         'email. Please try again later. (Sorry!)')
# 
#     class Meta(BaseUserCreationForm.Meta):
#         model = get_user_model()
#         fields = ('name', 'email')
# 
#     def clean_name(self):
#         name = self.cleaned_data['name']
#         disallowed = (
#             'activate',
#             'create',
#             'disable',
#             'login',
#             'logout',
#             'password',
#             'profile',
#         )
#         if name in disallowed:
#             raise ValidationError(
#                 "A user with that name"
#                 " already exists.")
#         return name
# 
#     def save(self, **kwargs):
#         user = super().save(commit=False)
#         if not user.pk:
#             user.is_active = False
#             send_mail = True
#         else:
#             send_mail = False
#         user.save()
#         self.save_m2m()
#         Profile.objects.update_or_create(
#             user=user,
#             defaults={
#                 'name': self.cleaned_data['name'],
#                 'slug': slugify(
#                     self.cleaned_data['name']),
#             })
#         if send_mail:
#             self.send_mail(user=user, **kwargs)
#         return user
# 
# Path: user/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(
#         settings.AUTH_USER_MODEL)
#     name = models.CharField(
#         max_length=255)
#     slug = models.SlugField(
#         max_length=30,
#         unique=True)
#     about = models.TextField()
#     joined = models.DateTimeField(
#         "Date Joined",
#         auto_now_add=True)
# 
#     objects = ProfileManager()
# 
#     def __str__(self):
#         return self.user.get_username()
# 
#     def get_absolute_url(self):
#         return reverse(
#             'dj-auth:public_profile',
#             kwargs={'slug': self.slug})
# 
#     def get_update_url(self):
#         return reverse('dj-auth:profile_update')
# 
#     def natural_key(self):
#         return (self.slug,)
#     natural_key.dependencies = ['user.user']
# 
# class User(AbstractBaseUser, PermissionsMixin):
#     email = models.EmailField(
#         'email address',
#         max_length=254,
#         unique=True)
#     is_staff = models.BooleanField(
#         'staff status',
#         default=False,
#         help_text=(
#             'Designates whether the user can '
#             'log into this admin site.'))
#     is_active = models.BooleanField(
#         'active',
#         default=True,
#         help_text=(
#             'Designates whether this user should '
#             'be treated as active. Unselect this '
#             'instead of deleting accounts.'))
# 
#     USERNAME_FIELD = 'email'
# 
#     objects = UserManager()
# 
#     def __str__(self):
#         return self.email
# 
#     def get_absolute_url(self):
#         return self.profile.get_absolute_url()
# 
#     def get_full_name(self):
#         return self.profile.name
# 
#     def get_short_name(self):
#         return self.profile.name
# 
#     def published_posts(self):
#         return self.blog_posts.filter(
#             pub_date__lt=date.today())
# 
#     def natural_key(self):
#         return (self.email,)


# Path: user/admin.py
from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin.options import \
    IS_POPUP_VAR
from django.contrib.admin.utils import unquote
from django.contrib.auth import \
    update_session_auth_hash
from django.contrib.auth.forms import \
    AdminPasswordChangeForm
from django.contrib.messages import success
from django.core.exceptions import \
    PermissionDenied
from django.http import (
    Http404, HttpResponseRedirect)
from django.template.response import \
    TemplateResponse
from django.utils.decorators import \
    method_decorator
from django.utils.encoding import force_text
from django.utils.html import escape
from django.views.decorators.debug import \
    sensitive_post_parameters
from .forms import (
    UserChangeForm, UserCreationForm)
from .models import Profile, User

    ordering = ('email',)
    search_fields = ('email',)
    # form view
    fieldsets = (
        (None, {
            'fields': ('email', 'password')}),
        ('Permissions', {
            'classes': ('collapse',),
            'fields': (
                'is_active',
                'is_staff',
                'is_superuser',
                'groups',
                'user_permissions')}),
        ('Important dates', {
            'classes': ('collapse',),
            'fields': ('last_login',)}),
    )
    filter_horizontal = (
        'groups', 'user_permissions',)
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': (
                'name',
                'email',
                'password1',
                'password2')
        }),
    )

    add_form = UserCreationForm