from flask_jwt_extended import current_user from mongoengine import * 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], "indexes": [ ('union'), ('username', 'union'), ('accept_date') ] } union = ReferenceField(Union) member_no = LongField() username = StringField() photo = ImageField(thumbnail_size=(85, 120)) password = StringField() name = StringField() middle_name = StringField() last_name = StringField() gov_id = EncryptedStringField() mother_name = EncryptedStringField() father_name = EncryptedStringField() email = EncryptedStringField() place_of_birth = EncryptedStringField() date_of_birth = EncryptedStringField() telephone = EncryptedStringField() 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' )) 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 current_user: self.union = current_user.union self.member_no = User.objects.filter(union=self.union).count() super(User, self).save(*args, **kwargs)