Beispiel #1
0
class EsiaCompatibleUserManager(
        UserManager.from_queryset(ESIACompatibleUserQuerySet)):
    use_for_related_fields = True

    def create_superuser(self,
                         username,
                         email=None,
                         password=None,
                         **extra_fields):
        extra_fields.setdefault('is_staff', True)
        extra_fields.setdefault('is_superuser', True)

        if extra_fields.get('is_staff') is not True:
            raise ValueError('Superuser must have is_staff=True.')
        if extra_fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(username, email, password, **extra_fields)
Beispiel #2
0
class User(AbstractUser):
    bio = MarkupField(blank=True,
                      default_markup_type=DEFAULT_MARKUP_TYPE,
                      escape_html=True)

    SEARCH_PRIVATE = 0
    SEARCH_PUBLIC = 1
    SEARCH_CHOICES = (
        (SEARCH_PUBLIC,
         'Allow search engines to index my profile page (recommended)'),
        (SEARCH_PRIVATE,
         "Don't allow search engines to index my profile page"),
    )
    search_visibility = models.IntegerField(choices=SEARCH_CHOICES,
                                            default=SEARCH_PUBLIC)

    EMAIL_PUBLIC = 0
    EMAIL_PRIVATE = 1
    EMAIL_NEVER = 2
    EMAIL_CHOICES = (
        (EMAIL_PUBLIC, 'Anyone can see my e-mail address'),
        (EMAIL_PRIVATE, 'Only logged-in users can see my e-mail address'),
        (EMAIL_NEVER, 'No one can ever see my e-mail address'),
    )
    email_privacy = models.IntegerField('E-mail privacy',
                                        choices=EMAIL_CHOICES,
                                        default=EMAIL_NEVER)

    public_profile = models.BooleanField('Make my profile public',
                                         default=True)

    objects = UserManager.from_queryset(UserQuerySet)()

    def get_absolute_url(self):
        return reverse('users:user_detail', kwargs={'slug': self.username})

    @property
    def has_membership(self):
        try:
            self.membership
            return True
        except Membership.DoesNotExist:
            return False
Beispiel #3
0
class CustomUserManager(UserManager.from_queryset(CustomUserQuerySet)):  # type: ignore
    def get_queryset(self):
        return super().get_queryset().select_related("profile")

    def create_student(
        self,
        username: str,
        field_age_group: "FieldOfStudyOfAgeGroup",
        first_name,
        last_name,
        membership_type: int = MembershipTypeChoices.NORMAL,
        email: Optional[str] = None,
        password: Optional[str] = None,
    ):
        from .models import Membership, UserProfile

        user = super(CustomUserManager, self).create_user(username, email, password)
        profile = UserProfile.objects.create(user=user)
        Membership.objects.create(
            profile=profile, field_age_group=field_age_group, type=membership_type
        )
        return user
Beispiel #4
0
from ore.core.models import Namespace, Organization
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, AnonymousUser, UserManager
from django.contrib.contenttypes.models import ContentType
from django.core.mail import send_mail
from django.db import models
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _t
import hashlib
from ore.core.util import UserFilteringQuerySet
import reversion


OreUserManagerBase = UserManager.from_queryset(UserFilteringQuerySet)


class OreUserManager(OreUserManagerBase):

    def _create_user(self, username, email, password, is_staff, is_superuser, **extra_fields):
        now = timezone.now()
        if not username:
            raise ValueError("The given username must be set")
        email = self.normalize_email(email)
        user = self.model(
            name=username,
            email=email,
            is_staff=is_staff,
            status=OreUser.STATUS.active,
            is_superuser=is_superuser,
            date_joined=now,
            **extra_fields
class AllObjectsUserManager(CustomUserMixin,
                            UserManager.from_queryset(AllObjectsQuerySet)):
    pass
Beispiel #6
0
class UserManager(DjangoUserManager.from_queryset(UserQuerySet)):
    # 'UserManager.use_in_migrations' is set to True in Django 1.8:
    # https://github.com/django/django/blob/1.8.18/django/contrib/auth/models.py#L166
    use_in_migrations = False