class User(BaseModel, TimestampMixin, db.Model): __tablename__ = 'auth_user' ROLE_USER = '******' ROLE_ADMIN = 'admin' ROLES = (ROLE_USER, ROLE_ADMIN) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(80), nullable=True) role = db.Column(db.String(80), default=ROLE_USER) allow_datetime = db.Column( db.DateTime, default=func.current_timestamp().op('AT TIME ZONE')('UTC'), nullable=False) active = db.Column(db.Boolean, default=True) @staticmethod def makepswd(secret): return hashlib.md5( secret.encode('utf-8').join( 'SECRET_ljas^&k12asssdgg')).hexdigest() def generatepswd(self): return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(12)) def __unicode__(self): return u'{0}'.format(self.email)
class User(BaseModel, TimestampMixin, db.Model): __tablename__ = 'users' ROLE_USER = '******' ROLE_ADMIN = 'admin' ROLES = ( ROLE_USER, ROLE_ADMIN ) name = db.Column(db.String(80), nullable=False) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) role = db.Column(db.String(80), default=ROLE_USER) allow_datetime = db.Column( db.DateTime, default=func.current_timestamp().op('AT TIME ZONE')('UTC'), nullable=False ) active = db.Column(db.Boolean, default=True) avatar_id = db.Column(db.Integer, db.ForeignKey('files.id')) avatar = db.relationship('File', foreign_keys=avatar_id) def __unicode__(self): return '{0}'.format(self.email)
class Invite(BaseModel, TimestampMixin, db.Model): __tablename__ = 'invites' TYPE_INTERNAL = 'internal' TYPE_EXTERNAL = 'external' TYPES = ( TYPE_INTERNAL, TYPE_EXTERNAL ) STATUS_PENDING = 'pending' STATUS_ACCEPTED = 'accepted' STATUS_REJECTED = 'rejected' STATUSES = ( STATUS_PENDING, STATUS_ACCEPTED, STATUS_REJECTED ) invite_type = db.Column(db.String(16), default=TYPE_EXTERNAL) status = db.Column(db.String(16), default=STATUS_PENDING) project_id = db.Column( db.Integer, db.ForeignKey('projects.id') ) project = db.relationship( 'Project', foreign_keys=project_id, backref=db.backref( 'invites', lazy='dynamic', cascade="all, delete" ) ) email = db.Column(db.String(80), nullable=False) invite_link = db.Column(db.String(250)) code = db.Column(db.String(80))
class Task(BaseModel, TimestampMixin, db.Model): __tablename__ = 'tasks' creator_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) creator = db.relationship('User', foreign_keys=creator_id, backref=db.backref('created_tasks', lazy='dynamic', cascade="all, delete")) project_id = db.Column(db.Integer, db.ForeignKey('projects.id'), nullable=False) project = db.relationship('Project', foreign_keys=project_id, backref=db.backref('tasks', lazy='dynamic', cascade="all, delete")) text = db.Column(db.String(80), nullable=False) note = db.Column(db.Text) notification_date = db.Column(db.DateTime(timezone=True)) is_completed = db.Column(db.Boolean, default=False) completion_date = db.Column(db.DateTime(timezone=True)) completed_by_user_id = db.Column(db.Integer, db.ForeignKey('users.id')) completed_by_user = db.relationship('User', foreign_keys=completed_by_user_id, backref=db.backref( 'completed_tasks', lazy='dynamic', cascade="all, delete")) completed_at = db.Column(db.DateTime(timezone=True)) assigned_to_user_id = db.Column(db.Integer, db.ForeignKey('users.id')) assigned_to_user = db.relationship('User', foreign_keys=assigned_to_user_id, backref=db.backref( 'assigned_tasks', lazy='dynamic', cascade="all, delete")) is_deleted = db.Column(db.Boolean, default=False)
class Project(BaseModel, TimestampMixin, db.Model): __tablename__ = 'projects' owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) owner = db.relationship('User', foreign_keys=owner_id, backref=db.backref('projects', lazy='dynamic', cascade="all, delete")) collaborators = db.relationship('User', secondary='collaborators', backref=db.backref('invited_projects', lazy='dynamic', cascade="all, delete"), lazy='dynamic') name = db.Column(db.String(80), nullable=False) tasks_order = db.Column(ARRAY(db.Integer), default=[]) is_shared = db.Column(db.Boolean, default=False) is_deleted = db.Column(db.Boolean, default=False)
class File(BaseModel, TimestampMixin, db.Model): __tablename__ = 'files' name = db.Column(db.String(250)) key = db.Column(db.String(250))
class Spark(BaseModel, db.Model): __tablename__ = "sparks" name = db.Column(db.String(80))
class User(db.Model, BaseModel, TimestampModel): __tablename__ = "users" name = db.Column(db.String(80), nullable=False) email = db.Column(db.String(80), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False)