<s> '''<STR_LIT>''' <EOL> from datetime import datetime <EOL> from sqlalchemy . orm import relationship , backref <EOL> from sqlalchemy import Column , Integer , String , ForeignKey , Boolean , DateTime <EOL> from odm import declared_attr <EOL> from odm . types import IPAddressType , UUIDType , JSONType <EOL> from lux . extensions import odm <EOL> from lux . extensions . rest import UserMixin , SessionMixin <EOL> Model = odm . model_base ( '<STR_LIT>' ) <EOL> users_groups = Model . create_table ( <EOL> '<STR_LIT>' , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> ) <EOL> groups_permissions = Model . create_table ( <EOL> '<STR_LIT>' , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class User ( Model , UserMixin ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> username = Column ( String ( <NUM_LIT:50> ) , unique = True ) <EOL> first_name = Column ( String ( <NUM_LIT:30> ) ) <EOL> last_name = Column ( String ( <NUM_LIT:30> ) ) <EOL> email = Column ( String ( <NUM_LIT> ) , unique = True ) <EOL> password = Column ( String ( <NUM_LIT> ) ) <EOL> active = Column ( Boolean ) <EOL> superuser = Column ( Boolean ) <EOL> joined = Column ( DateTime , default = datetime . utcnow ) <EOL> def __repr__ ( self ) : <EOL> return self . username or self . email <EOL> def has_permission ( self , permission ) : <EOL> return self . is_superuser or permission in self . permissions <EOL> def is_active ( self ) : <EOL> return self . active <EOL> def is_superuser ( self ) : <EOL> return self . superuser <EOL> @ property <EOL> def full_name ( self ) : <EOL> name = '<STR_LIT>' <EOL> if self . first_name : <EOL> name = self . first_name <EOL> if self . last_name : <EOL> name = '<STR_LIT>' % ( name , self . last_name ) <EOL> elif self . last_name : <EOL> name = self . last_name <EOL> else : <EOL> name = self . username or self . email <EOL> return name <EOL> class Group ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT> ) , unique = True ) <EOL> @ declared_attr <EOL> def users ( cls ) : <EOL> return relationship ( "<STR_LIT>" , <EOL> secondary = '<STR_LIT>' , <EOL> backref = '<STR_LIT>' ) <EOL> @ declared_attr <EOL> def permissions ( cls ) : <EOL> return relationship ( "<STR_LIT>" , <EOL> secondary = '<STR_LIT>' , <EOL> backref = "<STR_LIT>" ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> __str__ = __repr__ <EOL> class Permission ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT> ) , unique = True ) <EOL> description = Column ( String ( <NUM_LIT> ) ) <EOL> policy = Column ( JSONType ) <EOL> class Token ( Model , SessionMixin ) : <EOL> """<STR_LIT>""" <EOL> id = Column ( UUIDType ( binary = False ) , primary_key = True ) <EOL> created = Column ( DateTime , default = datetime . utcnow ) <EOL> expiry = Column ( DateTime ) <EOL> ip_address = Column ( IPAddressType ) <EOL> user_agent = Column ( String ( <NUM_LIT> ) ) <EOL> last_access = Column ( DateTime , default = datetime . utcnow ) <EOL> session = Column ( Boolean , default = True ) <EOL> description = Column ( String ( <NUM_LIT> ) ) <EOL> @ declared_attr <EOL> def user_id ( cls ) : <EOL> return Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> @ declared_attr <EOL> def user ( cls ) : <EOL> return relationship ( <EOL> '<STR_LIT>' , <EOL> backref = backref ( "<STR_LIT>" , cascade = "<STR_LIT>" ) ) <EOL> def get_key ( self ) : <EOL> return self . id . hex <EOL> class Registration ( Model ) : <EOL> id = Column ( String ( <NUM_LIT> ) , primary_key = True ) <EOL> expiry = Column ( DateTime , nullable = False ) <EOL> confirmed = Column ( Boolean ) <EOL> @ declared_attr <EOL> def user_id ( cls ) : <EOL> return Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> @ declared_attr <EOL> def user ( cls ) : <EOL> return relationship ( <EOL> '<STR_LIT>' , <EOL> backref = backref ( "<STR_LIT>" , cascade = "<STR_LIT>" ) ) <EOL> class MailingList ( Model ) : <EOL> id = Column ( Integer , primary_key = True ) <EOL> email = Column ( String ( <NUM_LIT> ) , unique = True ) <EOL> topic = Column ( String ( <NUM_LIT> ) ) <EOL> @ declared_attr <EOL> def user_id ( cls ) : <EOL> return Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> @ declared_attr <EOL> def user ( cls ) : <EOL> return relationship ( <EOL> '<STR_LIT>' , <EOL> backref = backref ( "<STR_LIT>" , cascade = "<STR_LIT>" ) ) </s>
