예제 #1
0
파일: models2.py 프로젝트: xuejunshuang/hue
class OrganizationUser(AbstractUser):
    """User model in a multi tenant setup."""

    username = None
    email = models.EmailField(_t('Email address'), unique=True)
    token = models.CharField(_t('Token'), max_length=128, default=None, null=True)
    customer_id = models.CharField(_t('Customer id'), max_length=128, default=None, null=True)
    organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
    is_admin = models.BooleanField(default=False)
    # settings are in UserProfile

    groups = models.ManyToManyField(
        OrganizationGroup,
        verbose_name=_t('groups'),
        blank=True,
        help_text=_t(
            'The groups this user belongs to. A user will get all permissions '
            'granted to each of their groups.'
        ),
        related_name="user_set",
        related_query_name="user",
    )

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    @property
    def username(self):
      return self.email

    @username.setter
    def username(self, value):
      pass
예제 #2
0
class Supplier(models.Model):
    supplier = models.CharField(verbose_name=_('Supplier Name'), max_length=32)
    default_markup = models.PositiveIntegerField(
        verbose_name=_('Default Markup'), default=0, max_length=255)
    description = models.TextField(blank=True, verbose_name=_('Description'))
    company = models.CharField(verbose_name=_('Company'), max_length=32)
    first_name = models.CharField(verbose_name=_('First Name'), max_length=32)
    last_name = models.CharField(verbose_name=_('Last Name'), max_length=32)
    archived = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)
    phone = models.CharField(verbose_name=_('Phone'),
                             max_length=60,
                             null=True,
                             blank=True)
    mobile = models.CharField(verbose_name=_('Mobile Phone'),
                              max_length=60,
                              null=True,
                              blank=True)
    fax = models.CharField(verbose_name=_('Fax'),
                           max_length=60,
                           null=True,
                           blank=True)
    email = models.EmailField(unique=True,
                              verbose_name=_('Email'),
                              null=False,
                              blank=False)
    website = models.URLField(verbose_name=_('Website'), null=True, blank=True)
    street = models.CharField(verbose_name=_('Street'),
                              max_length=32,
                              null=True,
                              blank=True)
    suburb = models.CharField(verbose_name=_('Suburb'),
                              max_length=32,
                              null=True,
                              blank=True)
    city = models.CharField(verbose_name=_('City'),
                            max_length=32,
                            null=True,
                            blank=True)
    postcode = models.CharField(verbose_name=_('Post Code'),
                                max_length=8,
                                null=True,
                                blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    country = CountryField(blank_label='(select a country)')

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

    def save(self, *args, **kwargs):
        """
        On save, update timestamps
        """
        if not self.id:
            self.created = datetime.today()
        return super(Supplier, self).save(*args, **kwargs)
예제 #3
0
class UserModel(AbstractUser):
    email = models.EmailField(verbose_name='Email address', unique=True)

    class Meta:
        db_table = 'auth_user'
        verbose_name = 'Пользователь'
        verbose_name_plural = 'Пользователи'
        ordering = ['username', 'date_joined', ]
예제 #4
0
 class Meta:
     model = User
     email = models.EmailField(unique=True)
     fields = [
         'username',
         'email',
         'first_name',
         'last_name',
         'password1',
         'password2',
     ]
예제 #5
0
class Customer(models.Model):
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)
    email = models.EmailField(null=True, blank=True)
    phone = models.CharField(max_length=32, null=True, blank=True)
    profile_key = models.CharField(max_length=32, null=True, blank=True)
    address = models.CharField(max_length=32, null=True, blank=True)
    rewards_points = models.IntegerField(null=True, blank=True)
    account_number = models.CharField(max_length=64, blank=True)
    notes = models.TextField(null=True, blank=True)
    archived = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)
    city = models.CharField(verbose_name=_('City'),
                            max_length=58,
                            null=True,
                            blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    zipcode = models.CharField(verbose_name=_('Zip code'),
                               max_length=8,
                               null=True,
                               blank=True)
    group = models.ForeignKey(CustomerGroup,
                              blank=True,
                              null=True,
                              related_name='taskin_group')

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

    def save(self, *args, **kwargs):
        """
        On save, update timestamps
        """
        if not self.id:
            self.created = datetime.today()
        return super(Customer, self).save(*args, **kwargs)

    def get_full_name(self):
        return self.first_name + ' ' + self.last_name
예제 #6
0
class Employee(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True,
                              verbose_name=_('Email'),
                              null=False,
                              blank=False)
    photo = models.ImageField(upload_to='employee_photo/',
                              verbose_name=_('P'),
                              blank=True,
                              default='employee_photo/def.jpg')
    name = models.CharField(verbose_name=_('Name'), max_length=32)
    address = models.CharField(verbose_name=_('Address'),
                               max_length=32,
                               null=True,
                               blank=True)
    address2 = models.CharField(verbose_name=_("Address2"),
                                null=True,
                                blank=True,
                                max_length=32)
    city = models.CharField(verbose_name=_('City'),
                            max_length=32,
                            null=True,
                            blank=True)
    state = models.CharField(verbose_name=_('State'),
                             max_length=2,
                             choices=STATE_CHOICES,
                             null=True,
                             blank=True)
    zipcode = models.CharField(verbose_name=_('Zip code'),
                               max_length=8,
                               null=True,
                               blank=True)
    phone = models.CharField(verbose_name=_('Phone'),
                             max_length=60,
                             null=True,
                             blank=True)
    pin = models.IntegerField(verbose_name=_('Pin'), unique=True, null=True)
    role = models.IntegerField(verbose_name=_('Role'), choices=ROLES)
    vein_string = models.TextField(blank=True, verbose_name=_('Vein String'))
    hourly_rate = models.DecimalField(blank=True,
                                      null=True,
                                      verbose_name=_('Hourly Rate'),
                                      decimal_places=2,
                                      max_digits=5)
    archived = models.BooleanField(default=False)
    store = models.ForeignKey(Store,
                              verbose_name='Store',
                              blank=True,
                              null=True)

    USERNAME_FIELD = 'email'

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    created = models.DateTimeField(editable=False)

    objects = EmployeeManager()

    def __unicode__(self):
        return u"%s" % self.name

    def get_full_name(self):
        return self.name

    def get_short_name(self):
        return self.name

    def check_is_owner(self):
        return self.role == ROLES[0][0]

    def return_id(self):
        return self.id

    def save(self, *args, **kwargs):
        ''' On save, update timestamps '''
        if self.photo:
            try:
                self.photo = resize_image(self.photo,
                                          newsize=EMPLOYEE_PHOTO_SIZE)
            except:
                logger.exception("Error resizing image for product %s" %
                                 self.pk)
                pass
        if not self.id:
            self.created = datetime.today()
        return super(Employee, self).save(*args, **kwargs)