Beispiel #1
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    nickname = models.CharField(max_length=128, unique=True, db_index=True)
    name = models.CharField(max_length=128, blank=True)
    surname = models.CharField(max_length=128, blank=True)
    email = models.EmailField(max_length=128, unique=True, db_index=True)
    phone = models.CharField(max_length=12, unique=True, db_index=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    last_login = models.DateTimeField(blank=True, null=True)

    objects = CustomUserManager()

    USERNAME_FIELD = 'phone'
    REQUIRED_FIELDS = ['nickname','name', 'surname', 'email', ]

    class Meta:
        verbose_name = 'custom user'
        verbose_name_plural = 'custom users'

    @property
    def get_full_name(self):
        return '{} {}'.format(self.nickname.title(), self.email.title())

    @property
    def get_short_name(self):
        return self.nickname

    def send_user_mail(self, subject, message):
        pass
Beispiel #2
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(_('username'),
                                max_length=150,
                                blank=True,
                                null=True,
                                default="")
    email = models.EmailField(_('email address'), unique=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(default=timezone.now)
    degree = models.ManyToManyField("content.Degree")
    pic = models.ImageField(default='default.png', upload_to='profile_pics')
    purchased_notes = models.ManyToManyField("content.Note")
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    def get_courses(self):
        degree_id = self.degree.all().values_list('id')
        return Course.objects.filter(degree__in=degree_id)

    def get_full_name(self):
        return self.username

    def is_owner(self, resource):
        return resource.owner == self

    def has_purchased_note(self, note):
        return self.purchased_notes.filter(id=note.id).count() > 0
Beispiel #3
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
	email = models.EmailField(verbose_name="email", max_length=60, unique=True)
	first_name = models.CharField(max_length=30)
	last_name = models.CharField(max_length=30)
	genre = models.CharField(choices=GENRE_CHOICES, max_length=10)
	bio = models.TextField(max_length=500)
	picture = models.ImageField(upload_to=user_directory_path, default='images/default.jpg')
	location = models.PointField(max_length=40, null=True, default=paris_location, blank=True)


	# Other required Fields
	date_joined = models.DateTimeField(verbose_name='date joined', auto_now_add=True)
	last_login = models.DateTimeField(verbose_name='last login', auto_now=True)
	is_admin = models.BooleanField(default=False)
	is_active = models.BooleanField(default=True)
	is_staff = models.BooleanField(default=False)
	is_superuser = models.BooleanField(default=False)

	USERNAME_FIELD = 'email'
	REQUIRED_FIELDS = ['first_name', 'last_name', 'genre', 'bio', 'location']

	objects = CustomUserManager()


	def __str__(self):
		return self.first_name + " " + self.last_name


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

	def has_module_perms(self, app_label):
				return True
Beispiel #4
0
class Payments(models.Model):
    '''This model holds details of all the monetary transactions of the drycleaning shop'''
    id = models.AutoField(primary_key=True)
    payment_mode = models.ForeignKey(PaymentModes,
                                     on_delete=models.CASCADE,
                                     related_name='payment',
                                     null=True,
                                     blank=True)
    order = models.ForeignKey(Order,
                              on_delete=models.CASCADE,
                              related_name='payment',
                              null=True,
                              blank=True)
    enterprise = models.ForeignKey(Enterprise,
                                   on_delete=models.CASCADE,
                                   related_name='payment',
                                   null=True,
                                   blank=True)

    #The amount field is filled automatically when the drycleaner selects an order whose monetary details need to be filled
    @property
    def amount(self):
        amount = self.order.total_amount
        return amount

    objects = CustomUserManager()

    def __str__(self):
        return f"{self.id} {self.enterprise} {self.amount}"
Beispiel #5
0
class Employee(models.Model):
    '''This model class creates Employee table in the database to store employee details'''
    class Meta:
        verbose_name_plural = "Employees"

    id = models.AutoField(primary_key=True)
    enterprise = models.ForeignKey(Enterprise,
                                   on_delete=models.CASCADE,
                                   related_name='employee',
                                   blank=True,
                                   null=True)
    role = models.ForeignKey(Role,
                             on_delete=models.CASCADE,
                             related_name='employee',
                             blank=True,
                             null=True)
    employee_name = models.CharField(max_length=100)
    employee_email = models.EmailField(null=True, blank=True, unique=True)
    employee_phone = models.CharField(null=True, blank=True, max_length=13)
    employee_address = models.CharField(max_length=200)

    objects = CustomUserManager()

    def __str__(self):
        return f"{self.id} {self.enterprise} - {self.employee_name} {self.employee_phone}"
Beispiel #6
0
class Person(AbstractBaseUser, PermissionsMixin):
    name = models.CharField(max_length=50)
    email = models.EmailField(_('email address'), primary_key=True)
    password = models.CharField(max_length=1000)
    phone = models.CharField(max_length=25)
    person_type = models.BooleanField(default=False)
    is_paid = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_god = models.BooleanField(default=False)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name', 'password', 'phone', person_type]

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        img = Image.open(self.image.path)

        if img.height > 300 or img.width > 300:
            output_size = (300, 300)
            img.thumbnail(output_size)
            img.save(self.image.path)
Beispiel #7
0
class User(AbstractUser):
    USERNAME_FIELD = 'email'
    username = models.CharField(max_length=40, unique=False, default='')
    last_name = models.CharField(verbose_name='Фамилия',
                                 max_length=20,
                                 blank=True)
    first_name = models.CharField(verbose_name='Имя',
                                  max_length=20,
                                  blank=True)
    middle_name = models.CharField(verbose_name='Отчество',
                                   max_length=20,
                                   blank=True)
    email = models.EmailField(
        verbose_name='Адрес электронной\nпочты',
        unique=True,
    )
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

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

    def __str__(self):
        return self.get_full_name()
Beispiel #8
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    """Custom user model."""

    email = models.EmailField(_('email address'), unique=True)
    name = models.CharField('name', max_length=200, default='')
    image = models.ImageField(
        'image',
        upload_to='avatars',
        null=True,
        blank=True,
    )
    description = models.TextField('description', blank=True, default='')
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(default=timezone.now)
    friends = models.ManyToManyField(
        'self',
        symmetrical=False,
        verbose_name='friends',
        related_name='my_friends',
        blank=True,
    )

    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return f'{self.pk}: {self.email}'

    def get_absolute_url(self):
        return reverse('user', kwargs={'pk': self.pk})
Beispiel #9
0
class CustomUser(AbstractUser):
    BENEFICIARY = 0
    FACILITATOR = 1
    INVESTOR = 2
    ADMINISTRATOR = 3

    USER_TYPES = (
        (BENEFICIARY, "Beneficiary"),
        (FACILITATOR, "Facilitator"),
        (INVESTOR, "Investor"),
        (ADMINISTRATOR, "Administrator"),
    )

    username = None
    email = models.EmailField(_('email address'), unique=True)
    type = models.PositiveSmallIntegerField(choices=USER_TYPES,
                                            default=BENEFICIARY)
    first_name = models.CharField(max_length=255, blank=True)
    last_name = models.CharField(max_length=255, blank=True)
    phone = models.CharField(max_length=16, blank=True)
    village = models.CharField(max_length=255, blank=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    @property
    def opted_in(self):
        return Transaction.objects.filter(from_account__user=self,
                                          status=Transaction.CONFIRMED,
                                          action=Transaction.OPT_IN).exists()
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), unique=True)
    username = models.CharField(_('username'), unique=True, max_length=255)

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

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

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    class Meta:
        verbose_name = "User"
        verbose_name_plural = "Users"

    def __str__(self):
        return self.email

    def save(self, **kwargs):
        """
        Example for unique random username generation.
        """
        # if User is being created, generate new username
        if not self.id:
            highest_id_user = CustomUser.objects.order_by('id').last()
            next_id = highest_id_user.id if highest_id_user else 1
            random_string = ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase, k=6))
            self.username = '******'.format(random_string, next_id)
        super().save(**kwargs)
Beispiel #11
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True, null=True)
    first_name = models.CharField(max_length=150, default="Unknown")
    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 = CustomUserManager()

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

    def get_full_name(self):
        return self.email

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

    def __str__(self):
        return self.email
Beispiel #12
0
class User(AbstractBaseUser, PermissionsMixin):
    # name = models.CharField(_('name'), max_length=100)
    email = models.EmailField(_('email'), unique=True)
    username = models.CharField(_('username'), unique=True, max_length=100)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    first_name = models.CharField(_('nama depan'), max_length=100)
    last_name = models.CharField(_('nama belakang'), max_length=100)
    classes = models.CharField(_('kelas'), max_length=100, blank=True)
    sekolah = models.CharField(_('sekolah'), max_length=100, blank=True)

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

    objects = CustomUserManager()

    def get_unanswered_questions(self, quiz):
        answered_questions = self.murid \
            .filter(quiz_answers__answer__question__specific_Competency=quiz) \
            .values_list('quiz_answers__answer__question__id', flat=True)
        questions = quiz.indikator.exclude(pk__in=answered_questions)
        return questions

    def __str__(self):
        return self.username
class User(AbstractUser):
    username = None
    is_merchant = models.BooleanField(default=False)
    is_driver = models.BooleanField(default=False)
    phone_number = models.CharField(max_length=20, unique=True)

    USERNAME_FIELD = 'phone_number'

    objects = CustomUserManager()
Beispiel #14
0
class CustomUser(AbstractUser):
    email = models.EmailField(blank=True)
    username = models.CharField(max_length=50, unique=True)
    extra_detail_url = models.CharField(max_length=100)

    objects = CustomUserManager()
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.username
Beispiel #15
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    """
    A custom user model that takes an email address as the username field.
    """
    email = models.EmailField(_('email address'), unique=True)
    first_name = models.CharField(_('first name'),
                                  max_length=60,
                                  blank=False,
                                  null=False)
    last_name = models.CharField(_('last name'),
                                 max_length=60,
                                 blank=False,
                                 null=False)
    date_joined = models.DateTimeField(default=timezone.now)
    is_active = models.BooleanField(
        _('Active'),
        default=True,
        help_text=_(
            'Designates whether this user account should be considered active.'
        ),
    )
    is_staff = models.BooleanField(
        _('Staff'),
        default=False,
        help_text=_('Designates whether this user can access the admin site.'),
    )
    is_superuser = models.BooleanField(
        _('Superuser'),
        default=False,
        help_text=
        _('Designates that this user has all permissions without explicitly assigning them.'
          ),
    )

    objects = CustomUserManager()

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

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

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

    def get_short_name(self):
        return self.first_name

    def __str__(self):
        return self.email

    @property
    def full_name(self):
        return self.get_full_name()
Beispiel #16
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    username = models.CharField(max_length=150, unique=True)
    email = models.EmailField(unique=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    objects = CustomUserManager()

    USERNAME_FIELD = "email"
Beispiel #17
0
class User(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.get_full_name()
class PaymentModes(models.Model):
	'''This model is for payment modes(eg. credit card, cash, UPI etc.)'''
	class Meta:
		verbose_name_plural="Payment modes"

	id=models.AutoField(primary_key=True)
	payment_mode_name=models.CharField(max_length=50)
	enterprise=models.ForeignKey(Enterprise,on_delete=models.CASCADE,related_name='payment_mode',null=True,blank=True)
	objects=CustomUserManager()

	def __str__(self):
		return f"{self.id}  {self.payment_mode_name}"
Beispiel #19
0
class CustomUser(AbstractUser):
    username = None
    email = models.EmailField(_("email address"), unique=True)
    school = models.ForeignKey(School, on_delete=models.CASCADE)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email
Beispiel #20
0
class User(AbstractUser):
    username = None
    email = models.EmailField(_('email_address'), unique=True)
    city = models.CharField(max_length=100)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email
Beispiel #21
0
class CustomUser(AbstractUser):
    username = None
    email = models.EmailField(_('email_address'), unique=True)
    # define the unique identifier for the User model
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    # specifies that all objects for the class come from CustomUserManager
    objects = CustomUserManager()

    def __str__(self):
        return self.email
Beispiel #22
0
class CustomUser(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    telephone = PhoneNumberField(_('phone number'), blank=True, null=True)

    def __str__(self):
        return self.email
class ProductType(models.Model):
	'''This mocel is for product types (eg. shirt,pant,saree etc.)'''
	class Meta:
		verbose_name_plural = "Product types"

	id=models.AutoField(primary_key=True)
	product_type_name=models.CharField(max_length=100,blank=True)
	enterprise=models.ForeignKey(Enterprise,on_delete=models.CASCADE,related_name='product',blank=True,null=True)
	price=models.DecimalField(max_digits=6,decimal_places=2,blank=True,null=True)
	objects=CustomUserManager()

	def __str__(self):
		return f"{self.id}- {self.product_type_name} {self.enterprise}"
class ServiceType(models.Model):
	'''This model is for service types (eg. drycleaning, petrol wash, darning etc.)'''
	class Meta:
		verbose_name_plural = "Service types"

	id=models.AutoField(primary_key=True)
	
	service_type_name=models.CharField(max_length=100,blank=True)
	enterprise=models.ForeignKey(Enterprise,on_delete=models.CASCADE,related_name='service',blank=True,null=True)
	price=models.DecimalField(max_digits=6,decimal_places=2,blank=True,null=True)
	objects=CustomUserManager()

	def __str__(self):
		return f"{self.id}- {self.service_type_name} {self.enterprise}"
Beispiel #25
0
class User(AbstractUser):
    
    user_options = [("DONOR", "Donor"), ("HOSPITAL", "Hospital")]
    user_type = models.CharField(max_length=20, choices=user_options, null=False, blank=False)
    email = models.EmailField('email address', unique=True, null=True)
    username = None

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email
Beispiel #26
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    class Meta:
        db_table = 'auth_user'

    email = models.EmailField(unique=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()
Beispiel #27
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    email = models.EmailField(_('email address'),
                              unique=True,
                              null=True,
                              blank=True)
    name = models.CharField(_('uname'),
                            max_length=250,
                            unique=True,
                            null=True,
                            blank=True)
    last_name = models.CharField(_('uname'),
                                 max_length=250,
                                 unique=True,
                                 null=True,
                                 blank=True)
    mobile = PhoneNumberField()
    uname = models.CharField(_('uname'),
                             max_length=250,
                             unique=True,
                             null=True,
                             blank=True)
    uid = models.IntegerField(_('uid'),
                              db_index=True,
                              unique=True,
                              null=True,
                              blank=True)
    date_reg = models.DateTimeField(_('date_reg'), auto_now_add=True)
    shop_id = models.CharField(_('shop_id'),
                               primary_key=True,
                               unique=True,
                               max_length=250,
                               default='1000')
    cart_number = models.CharField(_('cart_number'),
                                   max_length=250,
                                   null=True,
                                   blank=True)
    id_moaref = models.CharField(_('id_moaref'),
                                 max_length=250,
                                 null=True,
                                 blank=True)

    objects = CustomUserManager()

    USERNAME_FIELD = 'uname'
    REQUIRED_FIELDS = ['email']

    def __str__(self):
        return self.email
class CustomUser(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)
    first_name = models.CharField(_('first name'), max_length=250, blank=False)
    last_name = models.CharField(_('last name'), max_length=250, blank=False)
    image = models.ImageField(upload_to='profile_pic', blank=True)
    bio = models.TextField(_('Bio'), blank=True)
    time = models.DateField(auto_now=True)
    on_leave_till = models.DateField(auto_now_add=True,
                                     editable=True,
                                     null=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    def full_name(self):
        return self.first_name + ' ' + self.last_name

    def accepted_applications(self):
        from applications.models import ApplicationModel
        accepted = []
        leave_appli = ApplicationModel.objects.filter(applicant=self)
        for apl in leave_appli:
            if apl.status == 'APPROVED':
                accepted.append(apl)
        return accepted

    def rejected_applications(self):
        from applications.models import ApplicationModel
        rejected = []
        leave_appli = ApplicationModel.objects.filter(applicant=self)
        for apl in leave_appli:
            if apl.status == 'DENAYED':
                rejected.append(apl)
        return rejected

    def panding_applications(self):
        from applications.models import ApplicationModel
        panding = []
        leave_appli = ApplicationModel.objects.filter(applicant=self)
        for apl in leave_appli:
            if apl.status == 'PANDING':
                panding.append(apl)
        return panding
Beispiel #29
0
class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True, null=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this 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.'
        ),
    )

    email_verified = models.BooleanField(
        ('email_verified'),
        default=False,
        help_text=_(
            'Designates whether this user has verified the email supplied'
        ),
    )

    name = models.CharField(
        _('name'),
        max_length=255
    )

    is_super_admin = models.BooleanField(default=False)

    # Special Roles;
    is_sales = models.BooleanField(default=True)
    is_procurement = models.BooleanField(default=False)
    is_delivery = models.BooleanField(default=False)
    is_human_resource = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
    objects = CustomUserManager()

    def __str__(self):
        return self.email

    def get_full_name(self):
        return self.email

    def get_short_name(self):
        return self.email
Beispiel #30
0
class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), unique=True)
    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 = CustomUserManager()

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

    def __str__(self):
        return self.email