You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Adunatio/models/User.py

135 lines
3.7 KiB

from flask_jwt_extended import current_user
4 years ago
from mongoengine import *
from werkzeug.security import generate_password_hash
4 years ago
from internal_lib.EncryptedField import EncryptedStringField
from models.EmbededDocuments import Descriptions
from models.Group import Group, PaymentGroup
4 years ago
from models.Union import Union
from restapi import Methods
4 years ago
class UserCustomFields(EmbeddedDocument):
name = StringField()
value = StringField()
value_type = StringField()
4 years ago
class User(Document):
meta = {
'index_background': True,
'index_cls': False,
'auto_create_index': True,
'can_query': True,
'with_sub_docs': True,
"quyery": {},
'ignore_fields': ['password'],
'methods': [Methods.Get, Methods.List, Methods.Create, Methods.Update],
"indexes": [
('union'),
('username', 'union'),
('accept_date')
]
}
deleted = BooleanField(default=False)
4 years ago
union = ReferenceField(Union)
member_no = LongField()
username = StringField(required=True)
photo = ImageField(thumbnail_size=(85, 120))
password = StringField(required=True)
name = StringField(required=True)
4 years ago
middle_name = StringField()
last_name = StringField(required=True)
gov_id = EncryptedStringField(required=True)
4 years ago
mother_name = EncryptedStringField()
father_name = EncryptedStringField()
email = EncryptedStringField()
place_of_birth = EncryptedStringField()
date_of_birth = EncryptedStringField(required=True)
telephone = EncryptedStringField(required=True)
4 years ago
job = StringField()
address = EncryptedStringField()
accept_date = DateTimeField()
dismissal_date = DateTimeField()
descriptions = ListField(EmbeddedDocumentField(Descriptions))
gender = StringField(choices=(
'Man',
'Women',
'Agender',
'Androgyne',
'Androgynous',
'Bigender',
'Cis',
'Cisgender',
'Cis Female',
'Cis Male',
'Cis Man',
'Cis Woman',
'Cisgender Female',
'Cisgender Male',
'Cisgender Man',
'Cisgender Woman',
'Female to Male',
'FTM',
'Gender Fluid',
'Gender Nonconforming',
'Gender Questioning',
'Gender Variant',
'Genderqueer',
'Intersex',
'Male to Female',
'MTF',
'Neither',
'Neutrois',
'Non-binary',
'Other',
'Pangender',
'Trans',
'Trans*',
'Trans Female',
'Trans* Female',
'Trans Male',
'Trans* Male',
'Trans Man',
'Trans* Man',
'Trans Person',
'Trans* Person',
'Trans Woman',
'Trans* Woman',
'Transfeminine',
'Transgender',
'Transgender Female',
'Transgender Male',
'Transgender Man',
'Transgender Person',
'Transgender Woman',
'Transmasculine',
'Transsexual',
'Transsexual Female',
'Transsexual Male',
'Transsexual Man',
'Transsexual Person',
'Transsexual Woman',
'Two-Spirit'
),required=True)
4 years ago
custom_fields = ListField(EmbeddedDocumentField(UserCustomFields))
4 years ago
user_group = ReferenceField(Group)
payment_group = ReferenceField(PaymentGroup)
4 years ago
def __unicode__(self):
try:
return ' '.join([self.name, self.middle_name, self.last_name])
except:
return str(self.id)
4 years ago
def save(self, *args, **kwargs):
if self.union:
self.member_no = User.objects.filter(union=self.union).count()
4 years ago
if self.password.find('pbkdf2:') == -1:
self.password = generate_password_hash(self.password)
super(User, self).save(*args, **kwargs)