Пример #1
0
class Product(Base):
    PRICE_CHOICES = (
        ('specified', 'معین'),
        ('call', 'تماس'),
    )
    product_owner = models.ForeignKey(Identity, related_name="identity_products", on_delete=models.CASCADE,
                                      db_index=True, help_text='Integer')
    product_category = models.ForeignKey(Category, related_name="category_products", on_delete=models.CASCADE,
                                         db_index=True, help_text='Integer')
    name = models.CharField(max_length=100, db_index=True, help_text='String(100)')
    product_related_country = models.ForeignKey(BaseCountry, related_name='country_products', on_delete=models.CASCADE,
                                                db_index=True, help_text='Integer')
    product_related_province = models.ForeignKey(BaseProvince, related_name='province_products', on_delete=models.CASCADE,
                                                 db_index=True, help_text='Integer')
    product_related_town = models.ForeignKey(BaseTown, related_name='country_products', on_delete=models.CASCADE,
                                             db_index=True, help_text='Integer')
    description = models.CharField(max_length=1000, blank=True, db_index=True, help_text='String(1000)')
    attrs = JSONField(null=True, blank=True, help_text='JSON')
    custom_attrs = JSONField(null=True, blank=True, help_text='JSON')
    product_user = models.ForeignKey(User, related_name="user_products", on_delete=models.CASCADE, db_index=True, help_text="Integer")
    product_price_type = models.CharField(max_length=10, db_index=True, choices=PRICE_CHOICES, default='specified', help_text='specified | call')

    objects = BaseManager()

    def __str__(self):
        return self.name
Пример #2
0
class CategoryField(Base):
    STRING = 'string'
    FLOAT = 'float'
    CHOICES = 'choices'
    BOOL = 'bool'
    TYPE_CHOICES = (
        (STRING, 'ارزش آن بصورت استرینگ پر شود'),
        (FLOAT, 'ارزش آن بصورت عدد پر شود'),
        (CHOICES, 'ارائه ارزش بصورت انتخابی'),
        (BOOL, 'ارئه ارزش بصورت چک باکس')
    )

    field_category = models.ForeignKey(Category, related_name="category_fields", on_delete=models.CASCADE,
                                       db_index=True, help_text='Integer')
    name = models.CharField(max_length=100, unique=True, db_index=True, help_text='String(100)')
    title = models.CharField(max_length=100, db_index=True, help_text='String(100)')
    type = models.CharField(max_length=50, choices=TYPE_CHOICES, default=STRING, db_index=True,
                            help_text='string | float | choices | bool')
    order = models.IntegerField(default=0, db_index=True, help_text='Integer')
    option = JSONField(null=True, blank=True, db_index=True, help_text='JSON')

    objects = BaseManager()

    def __str__(self):
        return self.name
Пример #3
0
class Ability(Base):
    ability_organization = models.ForeignKey(Organization, db_index=True, related_name='abilities',
                                             on_delete=models.CASCADE, help_text='Integer')
    title = models.CharField(max_length=50, db_index=True, help_text='String(50)')
    text = models.TextField(help_text='Text', db_index=True)

    objects = BaseManager()
Пример #4
0
class ExchangeIdentity(Base):
    JOIN_TYPES = (
        ('join', 'عضو'),
        ('quest', 'مهمان'),
        ('admin', 'ادمین'),
    )
    exchange_identity_related_exchange = models.ForeignKey(
        Exchange,
        related_name="identities_exchange",
        help_text='Integer',
        on_delete=models.CASCADE,
        db_index=True
    )
    exchange_identity_related_identity = models.ForeignKey(
        Identity,
        related_name="exchanges_identities",
        help_text='Integer',
        on_delete=models.CASCADE,
        db_index=True,
    )
    join_type = models.CharField(
        choices=JOIN_TYPES,
        max_length=10,
        default='join',
        help_text='join | quest',
        db_index=True,
    )
    active_flag = models.BooleanField(default=True, help_text='Boolean', db_index=True)
    indicator_flag = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()
Пример #5
0
class Follow(Base):
    follow_followed = models.ForeignKey('users.Identity', related_name='followed', db_index=True,
                                        on_delete=models.CASCADE, help_text='Integer')
    follow_follower = models.ForeignKey('users.Identity', related_name='followers', db_index=True,
                                        on_delete=models.CASCADE, help_text='Integer')
    follow_accepted = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()
Пример #6
0
class Message(Base):
    message_sender = models.ForeignKey(
        Identity,
        related_name='messages_sender',
        on_delete=models.CASCADE,
        default=None,
        db_index=True,
        help_text='Integer',
    )
    message_receiver = models.ForeignKey(
        Identity,
        related_name='message_receivers',
        on_delete=models.CASCADE,
        default=None,
        db_index=True,
        help_text='Integer',
    )
    message_replay = models.ForeignKey(
        'self',
        related_name='replays',
        on_delete=models.CASCADE,
        default=None,
        blank=True,
        null=True,
        db_index=True,
        help_text='Integer',
    )
    message_forward = models.ForeignKey(
        'self',
        related_name='forwards',
        on_delete=models.CASCADE,
        default=None,
        blank=True,
        null=True,
        db_index=True,
        help_text='Integer',
    )
    send_date = models.DateTimeField(auto_now_add=True)
    seen_date = models.DateTimeField(blank=True, null=True, default=None)
    body = models.TextField(blank=True,
                            null=True,
                            default=None,
                            db_index=True,
                            help_text='Text')
    seen = models.BooleanField(default=False, help_text='Boolean')
    message_file = models.ForeignKey(
        Media,
        related_name="message",
        on_delete=models.CASCADE,
        default=None,
        blank=True,
        null=True,
        help_text='Integer',
    )

    objects = BaseManager()
Пример #7
0
class Customer(Base):
    customer_organization = models.ForeignKey(Organization, related_name='customer_organization', db_index=True,
                                              on_delete=models.CASCADE, help_text='Integer')
    related_customer = models.ForeignKey('users.Identity', related_name='customers', db_index=True,
                                         on_delete=models.CASCADE, help_text='Integer')
    title = models.CharField(max_length=100, db_index=True, help_text='String(100)')
    customer_picture = models.ForeignKey(Media, on_delete=models.CASCADE, help_text='Integer', db_index=True)
    customer_active = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()
Пример #8
0
class Staff(Base):
    staff_organization = models.ForeignKey(Organization, related_name='staffs', db_index=True, on_delete=models.CASCADE,
                                           help_text='Integer')
    staff_user = models.ForeignKey(User, related_name='users', db_index=True, on_delete=models.CASCADE,
                                   help_text='Integer')

    position = models.CharField(max_length=50, db_index=True, help_text='String(50)')
    post_permission = models.BooleanField(default=False, help_text='Boolean', db_index=True)

    objects = BaseManager()
Пример #9
0
class Category(Base):
    category_parent = models.ForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, db_index=True,
                                        help_text='Integer')
    name = models.CharField(max_length=100, unique=True, db_index=True, help_text='String(100)')
    title = models.CharField(max_length=100, db_index=True, help_text='String(100)')
    creatable = models.BooleanField(default=False, help_text='Boolean', db_index=True)

    objects = BaseManager()

    def __str__(self):
        return self.name
Пример #10
0
class Comment(Base):
    comment_product = models.ForeignKey(Product, related_name="product_comments", on_delete=models.CASCADE,
                                        db_index=True, help_text='Integer')
    comment_user = models.ForeignKey(User, related_name="user_product_comments", on_delete=models.CASCADE,
                                     db_index=True, help_text='Integer')
    text = models.TextField(db_index=True, help_text='Text')

    objects = BaseManager()

    def __str__(self):
        return '%s(%s)' % (self.comment_product.name, self.comment_user.username)
Пример #11
0
class OrganizationPicture(Base):
    picture_organization = models.ForeignKey(Organization, related_name="organization_pictures",
                                             on_delete=models.CASCADE, help_text='Integer', db_index=True)
    picture_media = models.ForeignKey(Media, on_delete=models.CASCADE, related_name="organization_picture_media",
                                      help_text='Integer', db_index=True)
    order = models.IntegerField(default=0, help_text='Integer', db_index=True)
    description = models.TextField(blank=True, help_text='Text', db_index=True)

    def __str__(self):
        return self.picture_organization.official_name

    objects = BaseManager()
Пример #12
0
class Picture(Base):
    picture_product = models.ForeignKey(Product, related_name="product_pictures", on_delete=models.CASCADE,
                                        db_index=True, help_text='Integer')
    picture_media = models.ForeignKey(Media, db_index=True, on_delete=models.CASCADE, related_name="product_picture_media",
                                      help_text='Integer')
    order = models.IntegerField(default=0, help_text='Integer', db_index=True)
    description = models.TextField(blank=True, db_index=True, help_text='Text')
    picture_original = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()

    def __str__(self):
        return self.picture_product.name
Пример #13
0
class Confirmation(Base):
    confirmation_corroborant = models.ForeignKey('users.Identity', related_name='confirmation_corroborant',
                                                 db_index=True, on_delete=models.CASCADE, help_text='Integer')
    confirmation_confirmed = models.ForeignKey('users.Identity', related_name='confirmation_confirmed', db_index=True,
                                               on_delete=models.CASCADE, help_text='Integer', blank=True, null=True)
    title = models.CharField(max_length=50, db_index=True, help_text='String(String(50))')
    description = models.TextField(help_text='Text', db_index=True)
    link = models.CharField(max_length=200, help_text='String(200)', db_index=True)
    confirm_flag = models.BooleanField(default=False, help_text='Boolean', db_index=True)
    confirmation_parent = models.ForeignKey(Base, related_name='base_confirmation', db_index=True,
                                            on_delete=models.CASCADE, help_text='Integer')

    objects = BaseManager()
Пример #14
0
class Identity(Base):
    identity_user = models.OneToOneField(User,
                                         related_name="identity",
                                         on_delete=models.CASCADE,
                                         db_index=True,
                                         null=True,
                                         blank=True,
                                         help_text='Integer')
    identity_organization = models.OneToOneField(Organization,
                                                 related_name="identity",
                                                 on_delete=models.CASCADE,
                                                 db_index=True,
                                                 null=True,
                                                 blank=True,
                                                 help_text='Integer')
    name = models.CharField(max_length=150,
                            db_index=True,
                            unique=True,
                            help_text='String(150)')
    accepted = models.BooleanField(default=False, db_index=True)
    mobile_verified = models.BooleanField(default=False, db_index=True)
    email_verified = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()

    def clean(self):
        if not self.identity_user and not self.identity_organization:
            raise ValidationError(_('User or Organization should be set'))
        if self.identity_user and self.identity_organization:
            raise ValidationError(
                _('Only on of User or Organization should be set'))

    def __str__(self):
        return self.name

    def validate_user(self, identity_user):
        if self.identity_user and self.identity_user == identity_user:
            return True
        elif self.identity_organization and self.identity_organization.owner == identity_user:
            return True
        return False

    def validate_organization(self, identity_organization):
        if self.identity_organization == identity_organization:
            return True
        return False

    def save(self, *args, **kwargs):
        self.full_clean()
        super(Identity, self).save(*args, **kwargs)
Пример #15
0
class Exchange(Base):
    owner = models.ForeignKey(Identity, related_name='exchanges', db_index=True, on_delete=models.CASCADE,
                              help_text='Integer')
    name = models.CharField(max_length=32, validators=[MinLengthValidator(2)], db_index=True, help_text='String(30)')
    exchange_image = models.ForeignKey(
        Media,
        related_name="exchange",
        blank=True,
        null=True,
        help_text='Integer',
    )
    exchange_banner = models.ForeignKey(
        Media,
        related_name="exchange_banner",
        blank=True,
        null=True,
        help_text="Integer",
        db_index=True,
    )
    link = models.URLField(blank=True, help_text='Url', db_index=True)
    biography = models.CharField(max_length=100, null=True, blank=True, db_index=True, help_text='معرفی مختصر درباره پنجره')
    description = models.TextField(
        max_length=700,
        blank=True,
        db_index=True,
        help_text='Integer',
    )
    exchange_hashtag = models.ForeignKey(
        Hashtag,
        related_name="exchange",
        blank=True,
        null=True,
        db_index=True,
        help_text='Integer',
    )
    private = models.BooleanField(default=False, help_text='Boolean', db_index=True)
    members_count = models.BigIntegerField(default=100, help_text='BigInteger', db_index=True)
    is_default_exchange = models.BooleanField(default=False, help_text='Boolean', db_index=True)
    active_flag = models.BooleanField(default=True, help_text='Boolean', db_index=True)
    supply_count = models.IntegerField(default=0, db_index=True)
    demand_count = models.IntegerField(default=0, db_index=True)
    post_count = models.IntegerField(default=0, db_index=True)
    posts_comments_count = models.PositiveIntegerField(default=0, db_index=True)

    objects = BaseManager()

    def __str__(self):
        return str(self.pk) + ': ' + self.name
Пример #16
0
class Skill(Base):
    skill_user = models.ForeignKey(User,
                                   related_name="skills",
                                   db_index=True,
                                   on_delete=models.CASCADE,
                                   help_text='Integer')
    title = models.CharField(max_length=250,
                             help_text='String(250)',
                             db_index=True)
    tag = ArrayField(models.CharField(max_length=50),
                     blank=True,
                     help_text='50',
                     db_index=True)
    description = models.TextField(blank=True, help_text='Text', db_index=True)

    objects = BaseManager()

    def __str__(self):
        return "%s(%s)" % (self.skill_user.username, self.title)
Пример #17
0
class Certificate(Base):
    certificate_user = models.ForeignKey(User,
                                         related_name="certificates",
                                         db_index=True,
                                         on_delete=models.CASCADE,
                                         help_text='Integer')
    title = models.CharField(max_length=250,
                             help_text='String(250)',
                             db_index=True)
    picture_media = models.ForeignKey(Media,
                                      on_delete=models.SET_NULL,
                                      blank=True,
                                      null=True,
                                      db_index=True,
                                      help_text='Integer')

    objects = BaseManager()

    def __str__(self):
        return "%s(%s)" % (self.certificate_user.username, self.title)
Пример #18
0
class Price(Base):
    CURRENCY_CHOICES = (
        ('IRR', 'ریال'),
        ('USD', 'دلار'),
        ('EUR', 'یورو'),
        ('JPY', 'ژاپن'),
        ('GBP', 'پوند'),
        ('AUD', 'دلار استرالیا'),
        ('CAD', 'دلار کانادا'),
        ('CHF', 'یوان'),
        ('CNY', 'کرونا سوئد'),
    )
    price_product = models.ForeignKey(Product, related_name="prices", on_delete=models.CASCADE, db_index=True,
                                      help_text='Integer')
    value = models.FloatField(help_text='Float')
    price_currency = models.CharField(max_length=20, db_index=True, choices=CURRENCY_CHOICES, default='IRR', help_text='IRR | USD | EUR | JPY | GBP | AUD | CAD | CHF | CNY')

    objects = BaseManager()

    def __str__(self):
        return '%s(%s)' % (self.price_product.name, self.price_product)
Пример #19
0
class Media(models.Model):
    file_related_parent = models.ForeignKey(
        Base,
        related_name='file_related_parent',
        on_delete=models.CASCADE,
        blank=True,
        null=True,
        help_text='این فیلد بیانگر شناسه مدلی است که فایل به آن مربوط هست')
    identity = models.ForeignKey('users.Identity',
                                 related_name="identity_medias",
                                 on_delete=models.CASCADE,
                                 db_index=True,
                                 blank=True,
                                 null=True)
    file = models.FileField(upload_to=get_upload_path,
                            storage=media_file_storage,
                            blank=True,
                            null=True,
                            help_text='فایل مورد نظر برای ذخیره')
    uploader = models.ForeignKey(
        User,
        related_name="medias",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        db_index=True,
        help_text=
        'شناسه کاربری است که آپلود فایل را انجام می دهد. این فیلد به صورت سیستمی ذخیره می شود و نیازی نیست توسط فرانت مقدار بگیرد'
    )
    create_time = models.DateTimeField(auto_now_add=True, db_index=True)
    info = models.TextField(default='{}', db_index=True)
    delete_flag = models.BooleanField(db_index=True, default=False)

    objects = BaseManager()

    def __str__(self):
        return basename(self.file.file.name)
Пример #20
0
class Research(Base):
    research_user = models.ForeignKey(User,
                                      related_name="researches",
                                      db_index=True,
                                      on_delete=models.CASCADE,
                                      help_text='Integer')
    title = models.CharField(max_length=250,
                             help_text='String(250)',
                             db_index=True)
    url = models.URLField(blank=True, help_text='URL', db_index=True)
    author = ArrayField(models.CharField(max_length=100),
                        db_index=True,
                        blank=True,
                        help_text='Array(String(100))')
    publication = models.CharField(max_length=100,
                                   db_index=True,
                                   blank=True,
                                   help_text='String(100)')
    year = models.IntegerField(null=True,
                               blank=True,
                               db_index=True,
                               help_text='Integer')
    page_count = models.IntegerField(null=True,
                                     db_index=True,
                                     blank=True,
                                     help_text='Integer')
    research_link = models.CharField(max_length=255,
                                     db_index=True,
                                     blank=True,
                                     null=True,
                                     help_text='String(255)')

    objects = BaseManager()

    def __str__(self):
        return "%s(%s)" % (self.research_user.username, self.title)
Пример #21
0
class Education(Base):
    EDUCATION_GRADE = (
        ('Bachelor', "کارشناسی"),
        ('Master', "کارشناسی ارشد"),
        ('Phd', "دکتری"),
    )
    education_user = models.ForeignKey(User,
                                       related_name="educations",
                                       db_index=True,
                                       on_delete=models.CASCADE,
                                       help_text='Integer')
    grade = models.CharField(choices=EDUCATION_GRADE,
                             db_index=True,
                             default='Bachelor',
                             max_length=10,
                             help_text='Bachelor | Master | Phd')
    university = models.CharField(max_length=100,
                                  db_index=True,
                                  help_text='String(100)')
    field_of_study = models.CharField(max_length=100,
                                      db_index=True,
                                      help_text='String(100)')
    from_date = models.CharField(max_length=10,
                                 db_index=True,
                                 blank=True,
                                 null=True,
                                 help_text='String(7)')
    to_date = models.CharField(max_length=10,
                               db_index=True,
                               blank=True,
                               null=True,
                               help_text='String(7)')
    average = models.FloatField(
        validators=[MaxValueValidator(20),
                    MinValueValidator(0)],
        null=True,
        blank=True,
        help_text='Float')
    description = models.TextField(blank=True,
                                   db_index=True,
                                   help_text='Text',
                                   max_length=30)

    objects = BaseManager()

    def __str__(self):
        return "%s(%s - %s)" % (self.education_user.username, self.grade,
                                self.field_of_study)

    def clean(self):
        p = re.compile('^\d{4}-\d{2}$')
        from_date = to_date = None
        if self.from_date:
            from_date = self.from_date
            if not re.match(p, from_date):
                raise ValidationError(_('Invalid from date'))

        if self.to_date:
            to_date = self.to_date
            if not re.match(p, to_date):
                raise ValidationError(_('Invalid to date'))

        if from_date and to_date and from_date > to_date:
            raise ValidationError(_('To date must be greater than from date'))
Пример #22
0
class WorkExperience(Base):
    STATUSES = (
        ('WITHOUT_CONFIRM', 'بدون تایید'),
        ('WAIT_FOR_CONFIRM', 'منتظر تایید'),
        ('CONFIRMED', 'تایید شده'),
        ('UNCONFIRMED', 'تایید نشده'),
    )

    work_experience_user = models.ForeignKey(User,
                                             related_name="work_experiences",
                                             db_index=True,
                                             on_delete=models.CASCADE,
                                             help_text='Integer')
    name = models.CharField(max_length=100,
                            blank=True,
                            help_text='String(100)',
                            db_index=True)
    work_experience_organization = models.ForeignKey(
        Organization,
        related_name="work_experience_organization",
        on_delete=models.CASCADE,
        help_text='Integer',
        db_index=True)
    position = models.CharField(max_length=100,
                                blank=True,
                                help_text='String(100)',
                                db_index=True)
    from_date = models.CharField(max_length=10,
                                 blank=True,
                                 null=True,
                                 help_text='String(10)',
                                 db_index=True)
    to_date = models.CharField(max_length=10,
                               blank=True,
                               null=True,
                               help_text='String(10)',
                               db_index=True)
    status = models.CharField(
        choices=STATUSES,
        max_length=20,
        default='WITHOUT_CONFIRM',
        db_index=True,
        help_text='WITHOUT_CONFIRM | WAIT_FOR_CONFIRM | CONFIRMED | UNCONFIRMED'
    )

    objects = BaseManager()

    def __str__(self):
        return "%s(%s)" % (self.work_experience_user.username, self.name)

    def clean(self):
        if not self.work_experience_organization and not self.name:
            raise ValidationError(_('Please enter name or organization'))

        if self.work_experience_organization and self.name:
            raise ValidationError(_('Please enter name or organization'))

        if self.name and self.status != 'WITHOUT_CONFIRM':
            raise ValidationError(_('Invalid status'))

        p = re.compile('^\d{4}-\d{2}$')
        from_date = to_date = None
        if self.from_date:
            from_date = self.from_date
            if not re.match(p, from_date):
                raise ValidationError(_('Invalid from date'))

        if self.to_date:
            to_date = self.to_date
            if not re.match(p, to_date):
                raise ValidationError(_('Invalid to date'))

        if from_date and to_date and from_date > to_date:
            raise ValidationError(_('To date must be greater than from date'))
Пример #23
0
class Profile(Base):
    GENDER = (('male', 'مرد'), ('female', 'زن'))
    profile_user = models.OneToOneField(User,
                                        related_name="profile",
                                        db_index=True,
                                        on_delete=models.CASCADE,
                                        help_text='Integer')
    public_email = models.EmailField(null=True,
                                     blank=True,
                                     help_text='Email',
                                     db_index=True)
    national_code = models.CharField(max_length=10,
                                     blank=True,
                                     db_index=True,
                                     validators=[RegexValidator('^\d{10}$')],
                                     help_text='String(20)')
    profile_media = models.ForeignKey(Media,
                                      on_delete=models.CASCADE,
                                      db_index=True,
                                      related_name="users_profile_media",
                                      help_text='Integer',
                                      blank=True,
                                      null=True)
    birth_date = models.CharField(max_length=10,
                                  blank=True,
                                  db_index=True,
                                  null=True,
                                  help_text='String(10)')
    web_site = models.CharField(max_length=256,
                                blank=True,
                                db_index=True,
                                null=True,
                                help_text='Text')
    phone = models.CharField(max_length=11,
                             blank=True,
                             null=True,
                             help_text='Phone',
                             validators=[RegexValidator('^[0][0-9]{10,10}$')],
                             db_index=True)
    mobile = models.CharField(
        max_length=11,
        blank=True,
        null=True,
        help_text='Phone',
        validators=[RegexValidator('^[0][9][0-9]{9,9}$')],
        db_index=True)
    auth_mobile = models.CharField(
        max_length=11,
        blank=True,
        null=True,
        unique=True,
        db_index=True,
        validators=[RegexValidator('^[0][9][0-9]{9,9}$')],
        help_text='Phone')
    fax = PhoneField(blank=True, help_text='Phone', db_index=True)
    telegram_account = models.CharField(max_length=256,
                                        blank=True,
                                        db_index=True,
                                        help_text='String(256)')
    instagram_account = models.CharField(max_length=256,
                                         db_index=True,
                                         blank=True,
                                         help_text='String(256)')
    linkedin_account = models.CharField(max_length=256,
                                        db_index=True,
                                        blank=True,
                                        help_text='String(256)')
    twitter_account = models.CharField(
        max_length=256,
        db_index=True,
        blank=True,
        help_text='شناسه اکانت توئیتر که نهایت 256 کاراکتر ذخیره می کند')
    description = models.TextField(blank=True,
                                   db_index=True,
                                   help_text='Text',
                                   max_length=70)
    gender = models.CharField(
        choices=GENDER,
        max_length=7,
        default='Male',
        help_text='Male | Female',
        db_index=True,
    )
    is_plus_user = models.BooleanField(default=False, db_index=True)
    is_user_organization = models.BooleanField(default=False, db_index=True)
    google_plus_address = models.CharField(max_length=255,
                                           blank=True,
                                           null=True,
                                           db_index=True)
    social_image_url = models.CharField(max_length=255,
                                        blank=True,
                                        null=True,
                                        db_index=True)
    linkedin_headline = models.CharField(max_length=255,
                                         blank=True,
                                         null=True,
                                         db_index=True)
    linkedin_positions = models.TextField(blank=True, null=True, db_index=True)
    yahoo_contacts = models.TextField(blank=True, null=True, db_index=True)
    profile_strength = models.SmallIntegerField(default=10, db_index=True)
    address = models.CharField(max_length=100,
                               blank=True,
                               null=True,
                               db_index=True)
    profile_related_country = models.ForeignKey(BaseCountry,
                                                related_name='profile_country',
                                                db_index=True,
                                                blank=True,
                                                null=True,
                                                on_delete=models.CASCADE,
                                                help_text='Integer')
    profile_related_province = models.ForeignKey(
        BaseProvince,
        related_name='profile_province',
        db_index=True,
        blank=True,
        null=True,
        on_delete=models.CASCADE,
        help_text='Integer')
    profile_related_town = models.ForeignKey(BaseTown,
                                             related_name='profile_town',
                                             db_index=True,
                                             blank=True,
                                             null=True,
                                             on_delete=models.CASCADE,
                                             help_text='Integer')
    profile_banner = models.ForeignKey(Media,
                                       on_delete=models.CASCADE,
                                       related_name="users_banner_media",
                                       help_text='Integer',
                                       blank=True,
                                       null=True,
                                       db_index=True)
    profile_secret_key = models.CharField(blank=True,
                                          null=True,
                                          max_length=100,
                                          db_index=True)

    objects = BaseManager()

    def __str__(self):
        return self.profile_user.username

    @property
    def related_organization_id(self):
        if self.is_user_organization:
            organization_username = self.profile_user.username
            organization = Organization.objects.filter(
                username=organization_username)
            if organization.count() > 0:
                return organization[0].id
            else:
                return None
        return None

    def clean(self):
        if self.birth_date:
            p = re.compile('^\d{4}-\d{2}-\d{2}$')
            birth_date = self.birth_date
            if not re.match(p, birth_date):
                raise ValidationError(_('Invalid birth date'))
            now = timezone.now().date().strftime('%Y-%m-%d')
            if birth_date > now:
                raise ValidationError(_('Invalid birth date'))
Пример #24
0
class Organization(Base):
    OWNERSHIP_TYPES = (
        ('idi', 'موسسه انفرادی'),
        ('org', 'شرکت'),
        ('cop', 'تعاونی'),
        ('pvt', 'سهامی خاص'),
        ('llp', 'سهامی عام'),
        ('gco', 'شرکت دولتی'),
        ('oth', 'سایر'),
    )

    BUSINESS_TYPES = (
        ('producer', 'تولید کننده'),
        ('investor', 'سرمایه گذار'),
        ('service provider', 'ارائه دهنده خدمات'),
    )

    owner = models.ForeignKey(User, related_name="organizations", db_index=True,
                              on_delete=models.CASCADE, help_text='Integer', blank=True, null=True)
    admins = models.ManyToManyField(User,
                                    related_name="organization_admins",
                                    blank=True,
                                    help_text='Integer')
    username = models.CharField(max_length=32, unique=True, help_text='String(32)', validators=[MinLengthValidator(3)], db_index=True)
    email = models.EmailField(blank=True, null=True, help_text='Text', db_index=True)
    public_email = models.EmailField(blank=True, null=True, help_text='Text', db_index=True)
    nike_name = models.CharField(max_length=20, db_index=True, null=True, blank=True, help_text='String(100)')
    official_name = models.CharField(max_length=50, db_index=True, unique=True, help_text='String(50)')
    national_code = models.CharField(max_length=11, db_index=True, null=True, blank=True, help_text='String(20)')
    registration_ads_url = models.URLField(db_index=True, null=True, blank=True, help_text='URL')
    registrar_organization = models.CharField(max_length=100, db_index=True, null=True, blank=True,
                                              help_text='String(100)')
    country = models.CharField(max_length=50, db_index=True, null=True, blank=True, help_text='String(50)')
    province = models.CharField(max_length=50, db_index=True, null=True, blank=True, help_text='String(50)')
    city = models.CharField(max_length=50, db_index=True, null=True, blank=True, help_text='String(50)')
    address = models.TextField(blank=True, null=True, db_index=True, help_text='Text')
    phone = models.CharField(max_length=11, blank=True, null=True, help_text='Phone', validators=[RegexValidator('^[0][0-9]{10,10}$')], db_index=True)
    web_site = models.TextField(max_length=100, null=True, db_index=True, blank=True, help_text='URL')
    established_year = models.PositiveIntegerField(null=True, db_index=True, blank=True, help_text='Integer', validators=[MinValueValidator(1300)])
    ownership_type = models.CharField(
        choices=OWNERSHIP_TYPES,
        max_length=20,
        null=True,
        blank=True,
        db_index=True,
    )
    business_type = models.CharField(
        choices=BUSINESS_TYPES,
        max_length=30,
        null=True,
        blank=True,
        help_text='Array(String(30))',
        db_index=True,
    )
    organization_logo = models.ForeignKey(
        Media,
        related_name='organization_logo_media',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        help_text='Integer',
        db_index=True)
    organization_banner = models.ForeignKey(
        Media,
        related_name='organization_banner_media',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        help_text='Integer',
        db_index=True)
    biography = models.TextField(max_length=700, blank=True, null=True, help_text='String(70)', db_index=True)
    description = models.TextField(blank=True, null=True, help_text='Text', max_length=1000, db_index=True)
    correspondence_language = ArrayField(models.CharField(max_length=50), blank=True, null=True, default=[],
                                         help_text='Array(String(50))', db_index=True)
    social_network = ArrayField(models.CharField(max_length=100), blank=True, null=True, default=[],
                                help_text='Array(String(100))', db_index=True)
    telegram_account = models.CharField(
        max_length=256, blank=True, null=True, db_index=True, help_text='String(256)')
    instagram_account = models.CharField(max_length=256, db_index=True, blank=True, null=True, help_text='String(256)')
    linkedin_account = models.CharField(max_length=256, db_index=True, blank=True, null=True, help_text='String(256)')
    twitter_account = models.CharField(max_length=256, db_index=True, blank=True, help_text='شناسه اکانت توئیتر که نهایت 256 کاراکتر ذخیره می کند')
    staff_count = models.IntegerField(null=True, blank=True, help_text='تعداد پرسنل این سازمان که در سامانه حضور دارند را نمایش می دهد', db_index=True)
    active_flag = models.BooleanField(default=False, db_index=True)

    objects = BaseManager()

    def __str__(self):
        return str(self.pk) + ': ' + self.official_name

    def save(self, *args, **kwargs):
        from users.models import Identity
        with transaction.atomic():
            super(Organization, self).save(*args, **kwargs)
            if hasattr(self, 'identity'):
                identity = self.identity
            else:
                identity = Identity(identity_organization=self)
            identity.name = self.official_name
            identity.save()
            if self.staff_count:
                StaffCount.objects.create(identity_organization=self, staff_count=self.staff_count)