예제 #1
0
class Account(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    date_joined = models.DateTimeField(auto_now_add=True)
    is_active = models.BooleanField(default=True)

    objects = AccountManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = 'account'
        verbose_name_plural = 'accounts'

    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 account.
        '''
        return self.first_name

    def email_account(self, subject, message, from_email=None, **kwargs):
        '''
        Sends an email to this account.
        '''
        send_mail(subject, message, from_email, [self.email], **kwargs)
예제 #2
0
class Account(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    is_active = models.BooleanField(_('active'), default=True)
    email = models.EmailField(_('email address'), unique=True)
    profile_pic = models.ImageField(upload_to='profilepics/',
                                    null=True,
                                    blank=True)
    is_staff = models.BooleanField(_('staff status'), default=False)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = AccountManager()

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

    def get_full_name(self):
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        return self.first_name

    def email_user(self, subject, message, from_email=None, **kwargs):
        send_mail(subject, message, from_email, [self.email], **kwargs)

    def __str__(self):
        return self.first_name + ' ' + self.last_name + ' (' + self.email + ')'
예제 #3
0
class Account(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = AccountManager()

    def __str__(self):
        return self.email
예제 #4
0
class Account(AbstractUser):
    ROLE_CHOICES = (
        ("sa", "Super Admin"),
        ("wd", "Web Developer"),
        ("oa", "Organization Admin"),
        ("ou", "Organization User"),
    )

    created_at = models.DateTimeField(auto_now=True)
    updated_at = models.DateTimeField(auto_now=True)

    username = None
    email = models.EmailField(_("email address"), unique=True)
    role = models.CharField(max_length=2, choices=ROLE_CHOICES)
    organization = models.ForeignKey(Organization,
                                     blank=True,
                                     null=True,
                                     on_delete=models.SET_NULL)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    objects = AccountManager()

    confirmation_number = models.CharField(
        max_length=32, default=generate_confirmation_number)
    confirmed_at = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return self.email

    def save(self, *args, **kwargs):
        if self.pk == None:
            self.send_account_confirmation_email()

        if self.organization == None:
            self.organization = Organization.new_default_organization()

        return super().save()

    def get_absolute_url(self):
        return reverse_lazy("profile")

    def is_confirmed(self):
        return self.confirmed_at == None

    def send_account_confirmation_email(self):
        AccountMailer().account_confirmation_email(self)
예제 #5
0
class Account(AbstractUser, TimestampedModel):
    class Meta:
        verbose_name = _('Account')
        verbose_name_plural = _('Accounts')

    # Custom fields
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    email = models.EmailField(_('email address'), unique=True)

    # Removed fields
    username = None
    first_name = None
    last_name = None

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = AccountManager()

    def __str__(self):
        return self.email
예제 #6
0
class Account(AbstractBaseUser, PermissionsMixin):

    firstname = models.CharField(max_length=255)
    lastname = models.CharField(max_length=255)
    email = models.EmailField(unique=True, null=True, db_index=True)
    brasize = models.CharField(max_length=255, null=True, blank=True)
    pantysize = models.CharField(max_length=255, null=True, blank=True)
    bottomsize = models.CharField(max_length=255, null=True, blank=True)
    topsize = models.CharField(max_length=255, null=True, blank=True)

    is_active = models.BooleanField('active', default=True)

    date_joined = models.DateTimeField('date joined', default=timezone.now)

    REQUIRED_FIELDS = ['firstname', 'lastname']
    USERNAME_FIELD = 'email'

    objects = AccountManager()

    @property
    def is_staff(self):
        return self.is_superuser
예제 #7
0
class Account(AbstractBaseUser):
    uid = models.AutoField(primary_key=True)
    email = models.EmailField(
        unique=True,
        error_messages={"unique": "This email is already in use."})
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)

    address1 = models.CharField(max_length=48,
                                blank=True,
                                help_text="Street address, P.O. box")
    address2 = models.CharField(
        max_length=32,
        blank=True,
        help_text="Apartment, suite, unit, building, floor")
    city = models.CharField(max_length=32, blank=True)
    state = models.CharField(max_length=32,
                             blank=True,
                             help_text="Should use 2 letter ")
    zipcode = models.CharField(max_length=16, blank=True)
    country = CountryField(blank_label="", blank=True)

    is_superuser = models.BooleanField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    objects = AccountManager()

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

    class Meta:
        ordering = ["first_name"]

    def __str__(self):
        return self.get_full_name()

    def get_full_name(self):
        return self.first_name + " " + self.last_name
예제 #8
0
class Account(AbstractBaseUser):
    username = models.CharField(
        max_length=50,
        validators=[
            RegexValidator(
                regex=USERNAME_REGEX,
                message='Username can only contain alphanumeric characters and the following characters: . -',
                code='Invalid Username'
            )
        ],
        unique=False,

    )
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    user_type = models.PositiveSmallIntegerField(choices=USER_TYPE_CHOICES, default=None, null=True, blank=True)
    created = models.DateTimeField(null=False, auto_now_add=True)
    updated = models.DateTimeField(null=False, auto_now=True)

    # NonRelational data
    user_settings = JSONField(default=dict)

    # unused
    first_name = models.CharField(max_length=60, null=True, blank=True)
    last_name = models.CharField(max_length=60, null=True, blank=True)

    # Relationship Fields
    parent = models.ForeignKey("self", null=True, blank=True, related_name="account_children", on_delete=models.CASCADE)

    children = []
    parents = []

    objects = AccountManager()

    USERNAME_FIELD = 'email'

    # REQUIRED_FIELDS = ['username']

    def __str__(self):  # __unicode__ on Python 2
        return self.username

    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

    """
    Profile Functions
    """

    def base_profile(self):
        BaseProfile = apps.get_model('profiles.BaseProfile')
        try:
            return BaseProfile.objects.get(
                user=self,
                is_primary=True
            )
        except BaseProfile.DoesNotExist:
            profile = BaseProfile.objects.create(
                user=self,
                is_primary=True
            )
            return profile

    def settings_set_primary_profile(self):
        # TODO
        settings = self.user_settings

    def doctor_profile(self):
        DoctorProfile = apps.get_model('doctor_profiles.DoctorProfile')
        try:
            return DoctorProfile.objects.get(
                user=self,
                is_approved=True
            )
        except DoctorProfile.DoesNotExist:
            return False

    def create_doctor_profile(self):
        DoctorProfile = apps.get_model('doctor_profiles.DoctorProfile')
        profile = DoctorProfile.objects.create(
            user=self
        )
        return profile

    def receptionist_profile(self):
        ReceptionistProfile = apps.get_model('receptionist_profiles.ReceptionistProfile')
        try:
            return ReceptionistProfile.objects.get(
                user=self,
                is_approved=True
            )
        except ReceptionistProfile.DoesNotExist:
            return False

    def create_receptionist_profile(self):
        ReceptionistProfile = apps.get_model('receptionist_profiles.ReceptionistProfile')
        profile = ReceptionistProfile.objects.create(
            user=self
        )
        return profile
예제 #9
0
파일: models.py 프로젝트: tlrh314/mancelot
class UserModel(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_("email"), max_length=254, unique=True)
    full_name = models.CharField(_("full name"),
                                 max_length=150,
                                 null=True,
                                 help_text=_("First and last name"))
    address = models.CharField(
        _("address"),
        max_length=128,
        null=True,
        blank=True,
        help_text=_("Streetname and housenumber"),
    )
    zip_code = models.CharField(_("zip code"),
                                max_length=10,
                                null=True,
                                blank=True)
    city = models.CharField(_("city"), max_length=42, null=True, blank=True)
    country = CountryField(_("country"), default="NL", null=True, blank=True)

    # Support for monthly subscriptions
    PAYMENT_OPTIONS = (
        (0, _("Bank Transfer")),
        (1, _("Ideal")),
        (2, _("Paypal")),
    )
    iban = models.CharField(_("iban"), max_length=42, null=True, blank=True)
    balance = MoneyField(
        _("balance"),
        null=True,
        blank=True,
        max_digits=19,
        decimal_places=4,
        default_currency="EUR",
    )
    monthly_top_up = MoneyField(
        _("monthly top up"),
        null=True,
        blank=True,
        max_digits=19,
        decimal_places=4,
        default_currency="EUR",
    )
    payment_preference = models.PositiveSmallIntegerField(
        _("payment preference"),
        null=True,
        blank=True,
        choices=PAYMENT_OPTIONS,
        default=None,
    )

    # Django permission fields
    is_active = models.BooleanField(
        _("active"),
        default=False,
        help_text=_("Designates whether this user should be treated as "
                    "active. Unselect this instead of deleting accounts."),
    )
    is_staff = models.BooleanField(
        _("staff"),
        default=False,
        help_text=_(
            "Designates whether the user can log into this admin site."),
    )
    is_superuser = models.BooleanField(_("superuser"), default=False)

    # Bookkeeping of changes
    date_created = models.DateTimeField(_("date created"), auto_now_add=True)
    date_updated = models.DateTimeField(_("date Laatst Gewijzigd"),
                                        auto_now=True)
    last_updated_by = models.ForeignKey(
        "self",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="has_changed_accounts",
        verbose_name=_("last updated by"),
    )

    objects = AccountManager()

    USERNAME_FIELD = "email"  # email login rather than arbitrary username
    REQUIRED_FIELDS = ["full_name"]

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

    def __str__(self):
        return "{0} ({1})".format(self.full_name, self.email)

    def email_user(self,
                   subject,
                   text_content,
                   html_content,
                   from_email=settings.DEFAULT_FROM_EMAIL,
                   **kwargs):

        msg = EmailMultiAlternatives(
            subject=subject,
            body=text_content,
            from_email=from_email,
            to=[self.email],
            bcc=settings.ADMIN_BCC,
        )
        msg.attach_alternative(html_content, "text/html")
        msg.send()

    def send_welcome_email(self):
        subject = "Welkom bij Mancelot"
        text_content = "Welkom bij Mancelot!"
        html_content = render_to_string("accounts/welcome.html")
        self.email_user(subject, text_content, html_content)