Beispiel #1
0
class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=40, unique=True)
    date_joined = models.DateTimeField(_('Katılma Tarihi'), auto_now_add=True)
    is_active = models.BooleanField(_('active'), default=True)
    is_staff = models.BooleanField(_('Yetkili Mi?'), default=False)
    forms = models.ManyToManyField(Form)

    # Profile Part
    first_name = models.CharField(_('İsim'), max_length=100, null=True)
    last_name = models.CharField(_('Soyisim'), max_length=100, null=True)
    dob = models.DateField(null=True)
    phone = models.CharField(
        _('Telefon'),
        max_length=16,
        null=True,
    )
    address = models.CharField(_('Adres'),
                               max_length=300,
                               null=True,
                               blank=True)
    country = models.CharField(max_length=50, null=True)
    city = models.CharField(max_length=50, null=True)
    zip = models.CharField(max_length=5, null=True)

    objects = UserManager()

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
Beispiel #2
0
class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField('username',
                                max_length=30,
                                blank=True,
                                unique=True)
    email = models.EmailField('email address', unique=True)
    first_name = models.CharField('first name', max_length=30, blank=True)
    last_name = models.CharField('last name', max_length=30, blank=True)
    date_joined = models.DateTimeField('date joined',
                                       auto_now_add=True,
                                       editable=True)
    is_active = models.BooleanField('active', default=True)
    is_staff = models.BooleanField(
        'staff status',
        default=True,
    )
    otp_code = models.CharField(max_length=9, null=True, blank=True)
    phone_regex = RegexValidator(
        regex=r'^\+?1?\d{9,15}$',
        message="Phone number must be entered in the format: "
        "'+999999999'. Up to 15 digits allowed.")
    phone = models.CharField('phone number',
                             validators=[phone_regex],
                             max_length=15,
                             unique=True)
    avatar = models.ImageField(upload_to='avatars/', null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True, editable=True)
    USERNAME_FIELD = 'username'
    objects = UserManager()

    class Meta:
        verbose_name = 'user'
        verbose_name_plural = 'users'
Beispiel #3
0
class User(AbstractBaseUser, PermissionsMixin, ActivationMixin):
    email = models.EmailField(_('email address'), max_length=254, unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=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.'))
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
    browser_language = models.CharField(_('browser language'), max_length=5, choices=settings.LANGUAGES, blank=True)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name']

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        app_label = 'account'

    def get_full_name(self):
        """Returns the first_name plus the last_name, with a space in between."""
        full_name = '{0} {1}'.format(self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        """Returns the short name for the user."""
        return self.first_name

    def has_identity_set(self):
        """Identity is set when both first name and last name are set"""
        if self.first_name and self.last_name:
            return True
        return False
Beispiel #4
0
class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField(max_length=30, verbose_name=text("Nom"))
    last_name = models.CharField(max_length=30, verbose_name=text("Prenom"))
    username = models.CharField(max_length=30, unique=True)
    email = models.EmailField(max_length=255,
                              unique=True,
                              verbose_name=text("Adresse Email"))
    group = models.ForeignKey(Group,
                              on_delete=models.CASCADE,
                              verbose_name=text("Groupe"),
                              related_name='user_group',
                              null=True,
                              blank=True)
    has_group = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    is_manager = models.BooleanField(
        verbose_name="Peut-il devenir Chef de Groupe ?", default=False)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    is_superuser = models.BooleanField(default=False)
    profil_image = models.ImageField(upload_to=profilimage_directory_path,
                                     null=True,
                                     blank=True)

    objects = UserManager()
    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = ["first_name", "last_name", "username"]

    def __str__(self):
        return self.last_name

    def clean(self):
        super().clean()
        self.email = self.__class__.objects.normalize_email(self.email)
Beispiel #5
0
class User(AbstractUser):
    is_customer = models.BooleanField(default=False)
    is_company = models.BooleanField(default=False)

    email = models.EmailField(_("Email"), max_length=254, unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    profile_img = models.ImageField(_("Profile image"),
                                    upload_to='profile-pictures/',
                                    null=True,
                                    blank=True)
    date_joined = models.DateTimeField(_('date joined'), auto_now_add=True)

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def __str__(self):
        return self.email
Beispiel #6
0
class User(AbstractBaseUser):
    email = models.EmailField(
        verbose_name='email',
        max_length=255,
        unique=True,
    )
    nickname = models.CharField(max_length=20, null=False, unique=True)
    phone_number = models.CharField(max_length=14, null=False, unique=True)
    date_of_birth = models.DateField()
    is_admin = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['date_of_birth', 'nickname', 'phone_number']

    def __str__(self):
        return self.email

    def has_perm(self, perm, obj=None):
        return True

    def has_module_perms(self, app_label):
        return True

    @property
    def is_staff(self):
        return self.is_admin
class User(AbstractUser):
    username = None
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []
    objects = UserManager()

    email = models.EmailField(_('email_address'), unique=True)
    follower_count = models.PositiveIntegerField(default=0)

    def __str__(self):
        return self.email
Beispiel #8
0
class User(AbstractUser):
    username = None
    first_name = None
    last_name = None
    email = models.EmailField(_('email address'), unique=True)
    clients = models.ManyToManyField('hospital.Client', through='hospital.Account')
    name = models.CharField(_('name'), max_length=255, null=True, blank=False)
    default_client = models.ForeignKey('hospital.Client', on_delete=models.DO_NOTHING, null=True, blank=True,
                                       related_name='+')
    image = models.ImageField(upload_to=partial(make_imagefield_filepath, 'users'), null=True, blank=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()
Beispiel #9
0
class User(AbstractBaseUser, PermissionsMixin):
    username = models.EmailField(_('username'), unique=True)
    email = models.EmailField(_('email address'), unique=True)
    first_name = models.CharField(_('first name'),
                                  max_length=50,
                                  blank=False,
                                  null=False,
                                  default='nombre')
    last_name = models.CharField(_('last name'), max_length=50, blank=True)
    date_joined = models.DateTimeField(_('date joined'), auto_now_add=True)
    is_active = models.BooleanField(_('active'), default=True)
    is_staff = models.BooleanField(_('is staff'), default=False)
    is_superuser = models.BooleanField(_('is superuser'), default=False)
    # avatar = models.ImageField(upload_to='avatars/', null=True, blank=True)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = [
        # 'first_name',
        # 'email'
    ]

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def get_full_name(self):
        '''
        Returns the first_name plus the last_name, with a space in between.
        '''
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        '''
        Returns the short name for the user.
        '''
        return self.first_name

    def email_user(self, subject, message, from_email=None, **kwargs):
        '''
        Sends an email to this User.
        '''
        send_mail(subject, message, from_email, [self.email], **kwargs)
Beispiel #10
0
class User(AbstractUser):
    username_validator = UnicodeUsernameValidator  # username silmek(overwrite elemek)
    username = models.CharField(
        _('username'),
        max_length=150,
        blank=True,
        null=True,
        unique=False,
        help_text=
        _('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'
          ),
        validators=[username_validator],
        error_messages={
            'unique': _("A user with that username already exists."),
        },
    )

    #informations
    email = models.EmailField(_('Email'), unique=True)
    first_name = models.CharField(_("Name"), max_length=50)
    last_name = models.CharField(_("Surname"), max_length=50)
    image = models.ImageField(_("Image"),
                              upload_to='profile_photo',
                              blank=True,
                              null=True)
    phonenumber = models.CharField(_("Phone"), max_length=50)
    is_agreement = models.BooleanField(_("Agreement"), default=False)
    is_notifaction_email = models.BooleanField(_("Notifaction for email"),
                                               default=False)
    is_notifaction_phone = models.BooleanField(_("Notifaction for phone"),
                                               default=False)
    rewardpoints = models.IntegerField(_("rewardpoints"), default=0)

    #moderations
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(default=timezone.now)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    def __str__(self):
        return self.email
class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField(_("First name"), max_length=50)
    last_name = models.CharField(_("Last name"), max_length=50)
    email = models.EmailField(_('email address'), unique=True)
    bio = models.TextField(_("User bio"), blank=True, null=True)
    profile_img = models.ImageField(_("Profile Image"),
                                    upload_to='profile-pictures/',
                                    blank=True)
    date_joined = models.DateTimeField(default=timezone.now)

    ratings = models.ManyToManyField('self',
                                     blank=True,
                                     through='RatingUser',
                                     related_name='users')

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    def __str__(self):
        return self.email

    @property
    def avatar(self):
        if self.profile_img:
            return self.profile_img.url
        return 'https://user-images.githubusercontent.com/11250/39013954-f5091c3a-43e6-11e8-9cac-37cf8e8c8e4e.jpg'

    @property
    def rating(self):
        point = self.rating_users.all().aggregate(models.Avg('point'))
        print(point)
        if not point or not point.get('point__avg'):
            return 0.0
        return "{:.1f}".format(point.get('point__avg', 0))
Beispiel #12
0
class User(AbstractBaseUser):
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)
    phone = models.CharField(max_length=32)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name', 'phone']

    def __str__(self):
        return self.email

    def has_perm(self, perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, app_label):
        "Does the user have permissions to view the app `app_label`?"
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_staff(self):
        "Is the user a member of staff?"
        # Simplest possible answer: All admins are staff
        return self.is_admin
Beispiel #13
0
class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=50, unique=True)
    email = models.EmailField(_('email address'), unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    date_joined = models.DateTimeField(_('date joined'), auto_now_add=True)
    is_active = models.BooleanField(_('active'), default=True)
    avatar = models.ImageField(upload_to='avatars/', null=True, blank=True)
    is_admin = models. BooleanField(default=False)
    is_subadmin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_teacher = models.BooleanField(default=False)
    is_parent = models.BooleanField(default=False)
    is_student = models.BooleanField(default=False)
    created_at = models.BooleanField(default=False)
    updated_at = models.BooleanField(default=False)
    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        # permissions = [
        #     ("view_all_users", "Can view all users"),
        #     ("change_all_users", "Can change all users"),
        #     ("add_all_user", "Can change all users"),
        #     ("remove_all_users", "Can change all users"),

        #     ("view_all_teachers", "Can view all teachers"),
        #     ("change_all_teachers", "Can change all teachers"),
        #     ("add_all_teachers", "Can change all teachers"),
        #     ("remove_all_teachers", "Can change all teachers"),
            
        #     ("view_all_students", "Can view all students"),
        #     ("change_all_students", "Can change all students"),
        #     ("add_all_students", "Can change all students"),
        #     ("remove_all_students", "Can change all tudents"),


        # ]

    def get_full_name(self):
        '''
        Returns the first_name plus the last_name, with a space in between.
        '''
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        '''
        Returns the short name for the user.
        '''
        return self.first_name

    def email_user(self, subject, message, from_email=None, **kwargs):
        '''
        Sends an email to this User.
        '''
        send_mail(subject, message, from_email, [self.email], **kwargs)
Beispiel #14
0
class User(AbstractBaseUser, PermissionsMixin, OpenIdMixin):

    username = models.CharField(
        max_length=128,
        unique=True
    )

    phone = models.CharField(
        max_length=32,
        unique=True,
        null=True,
        blank=True,
    )

    email = models.CharField(
        max_length=48,
        unique=True,
        null=True,
        blank=True
    )

    nickname = models.CharField(
        max_length=32,
        blank=True,
        null=True
    )
    nickname_change_date = models.DateField(
        default=timezone.now
    )

    remark_name = models.CharField(
        max_length=16,
        blank=True,
        null=True
    )

    avatar = models.URLField(
        max_length=256,
        blank=True,
        null=True
    )

    avatar_change_date = models.DateField(
        default=timezone.now
    )

    gender = models.PositiveSmallIntegerField(
        choices=account_constant.GENDER_CHOICES,
        null=True,
        blank=True,
    )

    is_staff = models.BooleanField(
        default=False
    )

    is_active = models.BooleanField(
        default=True
    )

    # 能够在后台赋予权限时可见
    is_cms = models.BooleanField(
        default=False
    )

    date_joined = models.DateTimeField(
        auto_now_add=True
    )

    register_type = models.PositiveSmallIntegerField(
        default=account_constant.ACCOUNT_REGISTER_TYPE_EMAIL
    )

    @property
    def display_name(self):
        return self.nickname or self.display_email or self.display_username

    @property
    def display_username(self):
        """
            展示的用户名
        :return:
        """
        return self.username[0:5] + "*"*4 + self.username[:3]


    @property
    def display_phone(self):
        if self.phone is None:
            return ""

        return self.phone[:3] + "*"*4 + self.phone[-4:]

    @property
    def display_email(self):
        if self.email is None:
            return ""
        else:
            return fuzzy_real_email(self.email)

    @property
    def display_avatar(self):
        return self.avatar or account_constant.DEFAULT_AVATAR_URL

    @property
    def display_info(self):
        info_data = dict()
        info_data["display_name"] = self.display_name
        # info_data["phone"] = self.display_phone
        # info_data["email"] = self.display_email
        info_data["avatar"] = self.display_avatar
        info_data["open_id"] = self.open_id
        return info_data

    @property
    def display_admin_info(self):
        info_data = dict()
        info_data["nickname"] = self.display_name
        info_data["avatar"] = self.display_avatar
        info_data["perm_list"] = self.get_all_permissions()
        return info_data

    @property
    def display_user_info(self):
        now_date = timezone.datetime.now().date()
        nickname_interval_date = now_date - self.nickname_change_date
        avatar_interval_date = now_date - self.avatar_change_date

        info_data = dict()
        info_data["avatar"] = self.display_avatar
        info_data["avatar_interval_days"] = avatar_interval_date.days
        info_data["nickname"] = self.display_name
        info_data["nickname_interval_days"] = nickname_interval_date.days
        info_data["email"] = self.display_email
        info_data["open_id"] = self.open_id
        return info_data


    @classmethod
    def get_all_permission_list(cls):
        """
            获取Account所有的权限 列表
        :return:
        """
        return [item[0] for item in cls._meta.permissions]

    @classmethod
    def get_all_permission_dict(cls):
        """
            获取Account所有的权限 字典
        :return:
        """
        return [{'codename': item[0], 'name': item[1]} for item in cls._meta.permissions]

    def change_pwd(self, password):
        """
            修改用户密码
        :param password:
        :return:
        """
        try:
            self.set_password(password)
            self.save()
            return 1
        except Exception as e:
            logger.error(e)
            raise LogicException(f'修改失败:未知错误修改失败')

    def change_nickname(self, nickname):
        """
            修改昵称
        :param nickname:
        :return:
        """
        now_date = timezone.datetime.now().date()
        interval_date = now_date - self.nickname_change_date
        if account_constant.NICKNAME_CHANGE_INTERVAL_DAY > interval_date.days:
            raise LogicException(f'修改失败:在最近的{account_constant.NICKNAME_CHANGE_INTERVAL_DAY}天内你修改过了昵称,现在不能修改了')
        if User.objects.filter(nickname=nickname).exists():
            raise LogicException(f'修改失败:昵称{nickname}已经存在了!请更换一个')
        self.nickname = nickname
        self.nickname_change_date = now_date
        self.save()
        return 1

    def change_default_avatar(self, avatar_code):
        """
            挑选默认头像替换原头像
        :param avatar_code:
        :return:
        """
        now_date = timezone.datetime.now().date()
        interval_date = now_date - self.avatar_change_date
        if account_constant.AVATAR_CHANGE_INTERVAL_DAY > interval_date.days:
            raise LogicException(f'修改失败:在最近的{account_constant.AVATAR_CHANGE_INTERVAL_DAY}天内你修改过了头像,现在不能修改了')

        avatar = UserDefaultAvatar.objects.filter(open_code=avatar_code).first()
        if avatar is None:
            raise LogicException(f'修改失败:你所选的头像不是python-dog提供的默认头像集内的')
        self.avatar = avatar.avatar_url
        self.avatar_change_date = now_date
        self.save()
        return 1

    def bind_email(self, email):
        """
            绑定邮箱
        :param email:
        :return:
        """
        if self.email:
            return self.email

        self.email = email
        self.save()
        return email



    USERNAME_FIELD = "username"

    objects = UserManager()

    class Meta:
        verbose_name = _("User")
        verbose_name_plural = _("Users")
        swappable = "AUTH_USER_MODEL"

        permissions = (
            # usual
            (ap_constant.CAN_LOGIN_CMS, "能登录CMS"),
            # dashboard
            (ap_constant.CMS_MANAGE_DASHBOARD, "CMS-管理数据"),
            # article
            (ap_constant.CMS_MANAGE_SELF_ARTICLE, "CMS-管理自己的文章"),
            (ap_constant.CMS_MANAGE_ALL_ARTICLE, "CMS-管理全部的文章"),
            ## tag
            (ap_constant.CMS_MANAGE_ARTICLE_TAGS, "CMS-管理所有标签"),
            # photo wall
            (ap_constant.CMS_MANAGE_PHOTO_WALL, "CMS-管理图片墙"),
            # timeline
            (ap_constant.CMS_MANAGE_TIMELINE, "CMS-管理时间线"),
            # banner
            ## slide show
            (ap_constant.CMS_MANAGE_BANNER_SLIDE_SHOW, "CMS-管理横幅-首页轮播"),
            # permission
            (ap_constant.CMS_MANAGE_PERMISSIONS, "CMS-管理用户权限"),
            # account
            (ap_constant.CMS_MANAGE_ACCOUNTS, "CMS-管理所有账号")
        )