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

136 lines
3.8 KiB

from flask_jwt_extended import current_user
from mongoengine import *
from werkzeug.security import generate_password_hash
from internal_lib.EncryptedField import EncryptedStringField
from models.EmbededDocuments import Descriptions
from models.Group import Group, PaymentGroup
from models.Union import Union
from restapi import Methods
class UserCustomFields(EmbeddedDocument):
name = StringField()
value = StringField()
value_type = StringField()
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')
],
"auto_generated": ['union','deleted','member_no']
}
deleted = BooleanField(default=False)
union = ReferenceField(Union)
member_no = LongField()
username = StringField(required=True)
photo = ImageField(thumbnail_size=(85, 120))
password = StringField(required=True)
name = StringField(required=True)
middle_name = StringField()
last_name = StringField(required=True)
gov_id = EncryptedStringField(required=True)
mother_name = EncryptedStringField()
father_name = EncryptedStringField()
email = EncryptedStringField()
place_of_birth = EncryptedStringField()
date_of_birth = EncryptedStringField(required=True)
telephone = EncryptedStringField(required=True)
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)
custom_fields = ListField(EmbeddedDocumentField(UserCustomFields))
user_group = ReferenceField(Group)
payment_group = ReferenceField(PaymentGroup)
def __unicode__(self):
try:
return ' '.join([self.name, self.middle_name, self.last_name])
except:
return str(self.id)
def save(self, *args, **kwargs):
if self.union:
self.member_no = User.objects.filter(union=self.union).count()
if self.password.find('pbkdf2:') == -1:
self.password = generate_password_hash(self.password)
super(User, self).save(*args, **kwargs)