<s> import datetime <EOL> from flask import g <EOL> from flask_appbuilder . security . sqla . models import User <EOL> from sqlalchemy import Column , Integer , String , ForeignKey , Date , DateTime <EOL> from sqlalchemy . orm import relationship <EOL> from sqlalchemy . ext . declarative import declared_attr <EOL> from flask_appbuilder . models . mixins import AuditMixin <EOL> from flask . ext . appbuilder import Model <EOL> mindate = datetime . date ( datetime . MINYEAR , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> class Company ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:50> ) , unique = True , nullable = False ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> class MyUser ( User ) : <EOL> emp_number = Column ( String ( <NUM_LIT> ) ) <EOL> company_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = True ) <EOL> company = relationship ( "<STR_LIT>" ) <EOL> class ContactGroup ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:50> ) , unique = True , nullable = False ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> class Gender ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:50> ) , unique = True , nullable = False ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> def get_user_id ( cls ) : <EOL> try : <EOL> return g . user . id <EOL> except Exception as e : <EOL> return None <EOL> class Contact ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT> ) , unique = True , nullable = False ) <EOL> address = Column ( String ( <NUM_LIT> ) ) <EOL> birthday = Column ( Date , nullable = True ) <EOL> personal_phone = Column ( String ( <NUM_LIT:20> ) ) <EOL> personal_celphone = Column ( String ( <NUM_LIT:20> ) ) <EOL> contact_group_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> contact_group = relationship ( "<STR_LIT>" ) <EOL> gender_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> gender = relationship ( "<STR_LIT>" ) <EOL> created_on = Column ( DateTime , default = datetime . datetime . now , nullable = False ) <EOL> @ declared_attr <EOL> def created_by_fk ( cls ) : <EOL> return Column ( Integer , ForeignKey ( '<STR_LIT>' ) , <EOL> default = cls . get_user_id , nullable = False ) <EOL> @ declared_attr <EOL> def created_by ( cls ) : <EOL> return relationship ( "<STR_LIT>" , primaryjoin = '<STR_LIT>' % cls . __name__ , enable_typechecks = False ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> def month_year ( self ) : <EOL> date = self . birthday or mindate <EOL> return datetime . datetime ( date . year , date . month , <NUM_LIT:1> ) or mindate <EOL> def year ( self ) : <EOL> date = self . birthday or mindate <EOL> return datetime . datetime ( date . year , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> @ classmethod <EOL> def get_user_id ( cls ) : <EOL> try : <EOL> return g . user . id <EOL> except Exception as e : <EOL> return None </s>
