Пример #1
0
class Profile(models.Model):
    EDUCATION_CHOICES = (
        (enums.EducationEnum.NONE.value, 'None'),
        (enums.EducationEnum.ELEMENTARY_SCHOOL.value, 'Elementary school'),
        (enums.EducationEnum.MIDDLE_SCHOOL.value, 'Middle school'),
        (enums.EducationEnum.HIGH_SCHOOL.value, 'High school'),
    )
    landline_phone = modelfields.PhoneNumberField(blank=True)
    cell_phone = modelfields.PhoneNumberField(blank=True)
    certificates = models.TextField(blank=True)
    other_skills = models.TextField(blank=True)
    job = models.CharField(max_length=256)
    hire_date = models.DateField()
    photo = models.ImageField(upload_to=get_upload_path, blank=True)
    education = models.IntegerField(choices=EDUCATION_CHOICES)
    department = models.ForeignKey('departments.Departments',
                                   related_name='profiles')
    languages = models.ManyToManyField('Language', related_name='profiles')
    driving_licences = models.ManyToManyField('DrivingLicence',
                                              related_name='profiles',
                                              blank=True)
    user = models.OneToOneField('auth.User',
                                on_delete=models.CASCADE,
                                related_name='profile')

    @property
    def education_label(self):
        for value, label in self.EDUCATION_CHOICES:
            if value == self.education:
                return label
        return ''

    def __str__(self):
        return self.user.get_full_name()
Пример #2
0
 def test_deconstruct_region(self):
     phone_field = modelfields.PhoneNumberField(region="CH")
     _name, path, args, kwargs = phone_field.deconstruct()
     self.assertEqual("phonenumber_field.modelfields.PhoneNumberField",
                      path)
     self.assertEqual([], args)
     self.assertEqual({"max_length": 128, "region": "CH"}, kwargs)
Пример #3
0
class Customer(models.Model):
    first_name = models.CharField(max_length=60,
                                  db_index=True,
                                  null=True,
                                  verbose_name="ім'я")
    last_name = models.CharField(max_length=60,
                                 db_index=True,
                                 null=True,
                                 verbose_name="прізвище")
    phone = modelfields.PhoneNumberField(db_index=True,
                                         null=True,
                                         blank=False,
                                         verbose_name='номер телефону')
    email = models.EmailField(max_length=60,
                              db_index=True,
                              blank=True,
                              null=True,
                              verbose_name='емейл')
    create_at = models.DateTimeField(auto_now_add=True,
                                     verbose_name='датою заповнення')
    update_at = models.DateTimeField(auto_now=True,
                                     verbose_name='дата оновлення')

    def __str__(self):
        return f'{self.phone}({self.first_name})'

    class Meta:
        verbose_name = 'клієнт'
        verbose_name_plural = 'клієнти'
Пример #4
0
 def test_desconstruct_does_not_use_default_region(self):
     field = modelfields.PhoneNumberField()
     _name, path, args, kwargs = field.deconstruct()
     self.assertEqual("phonenumber_field.modelfields.PhoneNumberField",
                      path)
     self.assertEqual([], args)
     self.assertEqual({"max_length": 128, "region": None}, kwargs)
Пример #5
0
class Account(AbstractBaseUser):
    username = models.CharField(max_length=30, unique=True)
    phone = modelfields.PhoneNumberField(null=False, blank=False, unique=True)
    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 = 'username'
    REQUIRED_FIELDS = ['phone']

    objects = MyAccountManager()

    def __str__(self):
        return self.username

# For checking permissions. to keep it simple all admin have ALL permissons

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

# Does this user have permission to view this app? (ALWAYS YES FOR SIMPLICITY

    def has_module_perms(self, app_label):
        return True
Пример #6
0
class User(AbstractUser):
    email = models.EmailField(_('email address'), unique=True)
    phone = modelfields.PhoneNumberField(_('phone_number'),
                                         max_length=255,
                                         blank=True,
                                         null=True)

    username_validator = UnicodeUsernameValidator()
    username = models.CharField(
        _('username'),
        max_length=150,
        help_text=
        _('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'
          ),
        validators=[username_validator],
        blank=True,
        null=True)

    photo_urls = ArrayField(models.URLField(max_length=2048), default=list)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    def __str__(self):
        return self.email
Пример #7
0
class CustomUser(AbstractUser):
    phone = modelfields.PhoneNumberField(null=False, blank=False)
    bank_account = models.IntegerField(
        validators=[MinLengthValidator(24),
                    MaxLengthValidator(24)], null=True)
    address = models.ForeignKey("Address", on_delete=models.CASCADE, null=True)
    is_customer = models.BooleanField(default=False)
    is_seller = models.BooleanField(default=False)
Пример #8
0
class Application(models.Model):
    written_username = models.CharField(max_length=100, verbose_name='Имя')
    written_phone = modelfields.PhoneNumberField(region='RU', unique=True, verbose_name='Телефон')
    written_cover_letter = models.TextField(verbose_name='Сопроводительное письмо')
    vacancy = models.ForeignKey(Vacancy, related_name='applications', on_delete=models.CASCADE)
    user = models.ForeignKey(User, related_name='applications', on_delete=models.CASCADE)

    def __str__(self):
        return f'{self.pk} {self.written_username}'
Пример #9
0
class Contact(models.Model):
    """Store the details about contacted persions"""
    email = models.EmailField()
    country = models.CharField(max_length=50)
    phone = modelfields.PhoneNumberField(null=False, blank=False)
    msg = models.TextField()
    date = models.DateField(auto_now=True)

    def __str__(self):
        return f"{self.email} {self.country}"
Пример #10
0
class Agency(models.Model):
    key_name = models.CharField(max_length=60, primary_key=True)
    name = models.CharField(max_length=60, unique=True)
    location = models.ForeignKey(Location, related_name='agency_location_fk')
    manager = models.OneToOneField(
        User,
        related_name='manager_fk',
        limit_choices_to=models.Q(groups__name='managers'))
    phone = phonemodel.PhoneNumberField()
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)
Пример #11
0
class Profile(models.Model):
    user = models.OneToOneField(User, related_name='profile_fk')
    location = models.ForeignKey(Location, related_name='profile_location_fk')
    phone = phonemodel.PhoneNumberField()
    social_avatar = models.URLField()
    avatar = models.ImageField(upload_to=storage.upload_file,
                               storage=storage.MyFileSystemStorage(),
                               null=True,
                               blank=True)
    last_edit = models.DateTimeField(auto_now_add=True)
    #Aplica solo para administradores:
    is_manager = models.BooleanField(default=False)
Пример #12
0
class JobApplication(models.Model):
    name = models.CharField(max_length=35)
    last_name = models.CharField(max_length=35)
    birth_date = models.DateTimeField(auto_now=False, auto_now_add=False)
    sex_list = (('M', 'Male'), ('F', 'Female'))
    sex = models.CharField(max_length=1, choices=sex_list)
    country = country_fields.CountryField()
    phone_number = phonenumber_fields.PhoneNumberField()
    about = models.CharField(max_length=250)

    def __str__(self):
        return "{0} {1}".format(self.name, self.last_name)
Пример #13
0
class Participant(models.Model):
    """ Representation of a person who can participate in a Event """
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    phone_number = modelfields.PhoneNumberField(null=True, blank=True)
    secondary_phone = modelfields.PhoneNumberField(null=True, blank=True)
    email = models.EmailField(blank=True)
    address = models.ForeignKey(Address, blank=True)
    institution = models.ForeignKey(Institution, null=True, blank=True)

    def __str__(self):
        return "{first_name} {last_name}".format(first_name=self.first_name,
                                                 last_name=self.last_name)

    def name(self):
        """ The full name of the participant """
        return "{first} {last}".format(first=self.first_name,
                                       last=self.last_name)

    @property
    def events(self):
        """ List of all events participant is in """
        return Event.objects.filter(participants__in=[self]).all()
 def test_prep_value(self):
     """
     Tests correct db storage value against different setting of
     PHONENUMBER_DB_FORMAT
     Required output format is set as string constant to guarantee
     consistent database storage values
     """
     number = modelfields.PhoneNumberField()
     for frmt in ["E164", "RFC3966", "INTERNATIONAL"]:
         with override_settings(PHONENUMBER_DB_FORMAT=frmt):
             self.assertEqual(
                 number.get_prep_value(
                     to_python(self.storage_numbers[frmt][0])),
                 self.storage_numbers[frmt][1],
             )
Пример #15
0
class Address(models.Model):
    def __str__(self):
        return "{} \n{} {} \n{}, {} {} \n{}".format(self.addressee,
                                                    self.street, self.apt,
                                                    self.city, self.state,
                                                    self.zip_code,
                                                    self.country)

    addressee = models.CharField(max_length=255)
    street = models.CharField(max_length=255)
    apt = models.CharField(max_length=12, null=True, blank=True)
    city = models.CharField(max_length=255)
    state = models.CharField(max_length=255)
    zip_code = models.CharField(max_length=12)
    country = countries.CountryField(blank_label="Select Country")
    phone = phonenumber.PhoneNumberField(null=True, blank=True)
    email = models.EmailField(max_length=254)
Пример #16
0
class Team(models.Model):
    app_title = models.CharField(max_length=50, verbose_name='عنوان طرح')
    phone_number = modelfields.PhoneNumberField(error_messages={
        'invalid':
        'شماره موبایل صحیح نیست'
        '\nلطفا به فرمت 0913******* وارد کنید'
    },
                                                verbose_name='شماره موبایل')
    email = models.EmailField(verbose_name='ایمیل')
    app_file = models.FileField(upload_to='apps/%Y/%m',
                                verbose_name='فایل اپلیکیشن',
                                validators=[validate_archived_file])
    powerpoint_file = models.FileField(upload_to='powerpoints/%Y/%m',
                                       verbose_name='فایل ارائه',
                                       validators=[validate_powerpoint_file])

    def __str__(self):
        return self.app_title
Пример #17
0
class Accounts(AbstractBaseUser):
    name = models.CharField(max_length=50, verbose_name="Full Name", null=True)
    email = models.EmailField(verbose_name="email",
                              max_length=255,
                              unique=True)
    username = models.CharField(max_length=50, unique=True)
    # add user own fields to model account
    dob = models.DateField(verbose_name="Date of Birth", null=True)
    address = models.CharField(max_length=1024,
                               verbose_name="Address",
                               null=True)
    bio = models.CharField(max_length=1000, verbose_name="About", null=True)
    phone_number = modelfields.PhoneNumberField(blank=True)

    # ------------------ #
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')
    # ------------------ #
    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'  # field name which user should identifies Ex: email/username
    REQUIRED_FIELDS = [
        'username',
    ]  # field name which must be fill for creating accounts Ex: name, mobile, etc

    objects = AccountsManager()

    def __str__(self):
        return self.email  # data which should print when object of accounts class is printing

    def has_perm(self, perm, obj=None):
        return self.is_admin  # return true if user has permission to access Ex: it returns true if user is admin

    def has_module_perms(self, app_label):
        return True
class User(AbstractUser):
    INVALID_PIN = '##########'

    mobile = modelfields.PhoneNumberField(unique=True,
                                          verbose_name=_('mobile number'))
    is_verified = models.BooleanField(default=False,
                                      editable=False,
                                      verbose_name=_('verified'))
    is_registered = models.BooleanField(default=False,
                                        editable=False,
                                        verbose_name=_('registered'))
    pin = models.CharField(max_length=10,
                           editable=False,
                           verbose_name=_('PIN'))
    last_generated = models.DateTimeField(
        default=timezone.now,
        editable=False,
        verbose_name=_('last pin generated date'))

    REQUIRED_FIELDS = ['email', 'mobile']

    signer = TimestampSigner(sep=':', salt='membership.apps.User')

    def clean(self):
        if self.mobile and not str(
                getattr(self.mobile, 'country_code',
                        '')) in settings.VALID_MOBILE_COUNTRY_CODES:
            raise ValidationError({'mobile': _('Country code is not valid.')})

    def save(self, *args, **kwargs):
        if not self.username:
            self.username = '******' + str(self.mobile.national_number)

        # prevent staff members access_token hijacking through registration API
        if self.is_staff or self.is_superuser:
            self.is_verified = True
            self.is_registered = True
        super(User, self).save(*args, **kwargs)
Пример #19
0
 def test_region_none(self):
     field = modelfields.PhoneNumberField()
     self.assertIsNone(field.region)
Пример #20
0
 def test_region_uses_default_region(self):
     field = modelfields.PhoneNumberField()
     self.assertEqual("FR", field.region)
Пример #21
0
 class InvalidRegionModel(Model):
     phone_field = modelfields.PhoneNumberField(region="invalid")
Пример #22
0
class Protector(models.Model):
    name = models.CharField(max_length=75, validators=[validate_contains_only_letters, validate_minimum_length])
    last_name = models.CharField(max_length=75, validators=[validate_contains_only_letters, validate_minimum_length])
    phone_number = phonenumber_fields.PhoneNumberField()
    email = models.EmailField()