class Users(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False) email = db.Column(db.String(255), unique=True, nullable=False) phone = db.Column(db.String(1000), nullable=False) password = db.Column(db.String(255), nullable=False) user_type = db.Column(db.String(255)) user_group = db.Column(db.String(255)) address = db.relationship('Address', lazy='dynamic', cascade='all,delete', innerjoin=True, backref=db.backref('user', lazy='joined')) sar = db.relationship('Sar', lazy='dynamic', cascade='all,delete', innerjoin=True, foreign_keys='Sar.user_id', backref=db.backref('user', lazy='joined')) sar_assignedTo = db.relationship('Sar', lazy='dynamic', cascade='all,delete', innerjoin=True, foreign_keys='Sar.assignedTo', backref=db.backref('assignedTO', lazy='joined')) creation_time = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now()) modification_time = db.Column(db.DateTime, default=datetime.datetime.now()) created_by = db.Column(db.String(255)) modified_by = db.Column(db.String(255)) confirmed = db.Column(db.Boolean, nullable=False, default=False) confirmed_on = db.Column(db.DateTime, nullable=True) token = db.Column(db.String(255), nullable=True) password_reset_token = db.Column(db.String, nullable=True) organization = db.relationship("Organization", backref="users") def __init__(self, data, confirmed, confirmed_on=None, token=None,user_type=None,user_group=None): self.name = data["name"] self.email = data["email"] self.password = bcrypt.generate_password_hash( data["password"], current_app.config.get('BCRYPT_LOG_ROUNDS') ).decode('utf-8') self.user_type = user_type self.user_group = user_group self.phone = data["phone"] self.creation_time = datetime.datetime.now() # self.modification_time = data["modification_time"] self.created_by = data["created_by"] self.modified_by = data["modified_by"] self.confirmed = confirmed self.confirmed_on = confirmed_on self.token = token def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return self.id def __repr__(self): return '<users {0}>'.format(self.email) def to_dict(self): return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
class Sar(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) assignedTo = db.Column(db.Integer, db.ForeignKey(Users.id), nullable=False) otherInfo = db.Column(db.String(255)) sarDescription = db.Column(db.String(255)) externalUser = db.Column(db.String(255)) representative = db.Column(db.String(255)) user_confirmed = db.Column(db.String(255)) rep_confirmed = db.Column(db.String(255)) priority = db.Column(db.String(255)) completionTime = db.Column(db.DateTime) #completionTime = db.Column(db.String(255)) status = db.Column(db.String(255)) ticketinfo = db.relationship('TicketInfo', lazy='dynamic', backref=db.backref('sar', lazy='joined')) ticket = db.relationship('Ticket', lazy='dynamic', cascade='all,delete', innerjoin=True, primaryjoin="Sar.id == Ticket.sar_id", backref=db.backref('sar', lazy='joined')) sar_response = db.relationship('SARResponse', lazy='dynamic', cascade='all,delete', backref=db.backref('sar', lazy='joined')) user_id = db.Column(db.Integer, db.ForeignKey(Users.id), nullable=False) creation_time = db.Column(db.DateTime, nullable=False) modification_time = db.Column(db.DateTime, default=datetime.datetime.now()) created_by = db.Column(db.String(255)) modified_by = db.Column(db.String(255)) isEscalated = db.Column(db.Boolean) assigned_user = db.relationship('Users', foreign_keys='Sar.assignedTo') created_user = db.relationship('Users', foreign_keys='Sar.user_id') def __init__(self, data, user_id=None): self.assignedTo = data['assignedTo'] self.otherInfo = data['otherInfo'] self.sarDescription = data['sarDescription'] self.externalUser = data['externalUser'] self.representative = data['representative'] self.completionTime = datetime.datetime.now() self.status = data['status'] self.creation_time = datetime.datetime.now() # self.modification_time = data["modification_time"] self.created_by = data["created_by"] self.modified_by = data["modified_by"] self.isEscalated = data['isEscalated'] self.priority = data['priority'] self.user_id = data['user_id'] def to_dict(self): return { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs }
class SARResponse(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) sarattachment = db.relationship('sar_attachment', lazy='dynamic', cascade='all,delete', backref=db.backref('sarresponse', lazy='joined')) sar_id = db.Column(db.Integer, db.ForeignKey('sar.id'), nullable=False) fromUser = db.Column(db.String(255)) toUser = db.Column(db.String(255)) responseText = db.Column(db.String(255)) user_id = db.Column(db.Integer) user_name = db.Column(db.String(255)) def __init__(self, data, sar_id=None): self.fromUser = data['fromUser'] self.toUser = data['toUser'] self.responseText = data['responseText'] # self.user_name = data['user_name'] # self.user_id = data['user_id'] self.sar_id = sar_id # def to_dict(self): return { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs }
class Ticket(db.Model): # an email field and a password field uid = db.Column(db.Integer, primary_key=True, autoincrement=True) type = db.Column(db.String(120)) time = db.Column(BIGINT) changetime = db.Column(BIGINT) component = db.Column(db.String(100)) severity = db.Column(db.String(120)) priority = db.Column(db.String(120)) owner = db.Column(db.String(120)) reporter = db.Column(db.String(120)) cc = db.Column(db.String(120)) version = db.Column(db.String(120)) milestone = db.Column(db.String(120)) status = db.Column(db.String(120)) resolution = db.Column(db.String(120)) summary = db.Column(db.String(120)) description = db.Column(db.String(120)) keywords = db.Column(db.String(120)) product = db.Column(db.String(120)) id = db.Column(db.Integer) sar_id = db.Column(db.Integer, db.ForeignKey('sar.id')) created_time = db.Column(db.DateTime, default=datetime.datetime.now()) modified_time = db.Column(db.DateTime, default=None) ticketinfo2 = db.relationship('TicketInfo', lazy='dynamic', backref=db.backref('tickets', lazy='joined')) #ticket_id = db.Column(db.Integer, db.ForeignKey('ticket.uid'), nullable=False) def __init__(self, data, id, sar_id=None): self.type = data["type"] # self.updated_on = data["updated_on"] self.component = data["component"] self.severity = data["severity"] self.priority = data["priority"] self.owner = data["owner"] self.reporter = data["reporter"] self.cc = data["cc"] self.version = data["version"] self.milestone = data["milestone"] self.status = data["status"] self.resolution = data["resolution"] self.summary = data["summary"] self.description = data["description"] self.keywords = data["keywords"] self.product = data["product"] # self.modified_time = data["modified_time"] self.id = id self.sar_id = sar_id def to_dict(self): return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
class Department(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255)) defaultAssignedEmailId = db.Column(db.String(255)) ticketinfo = db.relationship('TicketInfo', lazy='dynamic', backref=db.backref('department', lazy='joined')) #tic ketinfo_id = db.Column(db.Integer, db.ForeignKey('ticket_info.id'), nullable=True) # ticketinfo = relationship("TicketInfo", uselist=False, back_populates="department") def __init__(self, data): self.name = data['name'] self.defaultAssignedEmailId = data['defaultAssignedEmailId'] def __repr__(self): return '<Department %r>' % (self.name) def to_dict(self): return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
class ExpenseList(db.Model): __tablename__ = 'expense_list' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(500), unique=True, nullable=False) money_spent = db.Column(db.Integer, nullable=False) #category_id = db.Column(db.Integer, db.ForeignKey('category_list.id')) category_id = db.Column(db.Integer, db.ForeignKey('category_list.id'), nullable=False) category = db.relationship('CategoryList', backref=db.backref('expense_list', lazy=True)) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) is_recurring = db.Column(db.Boolean, nullable=False, default=False) created_on = db.Column(db.DateTime, nullable=False) def __init__(self, name, money_spent, category_id, user_id, is_recurring, created_on): self.name = name self.money_spent = money_spent self.category_id = category_id self.user_id = user_id self.is_recurring = is_recurring self.created_on = datetime.datetime.now() @property def serialize(self): return { 'money_spent': self.money_spent, 'category': self.category_id, 'created_on': self.created_on, 'name': self.name, 'is_recurring': self.is_recurring } @property def graph_data(self): return { 'name': self.name, 'value': self.money_spent, }
class Donor(db.Model): __tablename__ = "donors" id = db.Column(db.Integer, primary_key=True, autoincrement=True) sn = db.Column(db.String, unique=True, nullable=False) email = db.Column(db.String(100), unique=True, nullable=False) donations = db.relationship('Donation', backref='donor', lazy=False) deferrals = db.relationship('Deferral', backref='donor', lazy=False) hospital_id = db.Column(db.Integer, db.ForeignKey('hospitals.id'), nullable=False) medical_conditions = db.Column(db.String(100)) current_medications = db.Column(db.String(100)) first_name = db.Column(db.String(100)) middle_name = db.Column(db.String(100)) last_name = db.Column(db.String(100)) home_address = db.Column(db.String(100)) city = db.Column(db.String(100)) region = db.Column(db.String(100)) phone1 = db.Column(db.String(100)) phone2 = db.Column(db.String(100)) cni = db.Column(db.String(100)) cni_doi = db.Column(db.DateTime()) cni_poi = db.Column(db.String()) dob = db.Column(db.DateTime()) pob = db.Column(db.String(100)) gender = db.Column(db.String(100)) blood_group = db.Column(db.String(100)) allergies = db.Column(db.String(100)) rhesus_factor = db.Column(db.String(100)) dolbd = db.Column(db.DateTime()) ndefbd = db.Column(db.DateTime()) status = db.Column(db.String(100)) referrer_id = db.Column(db.Integer, db.ForeignKey('donors.id')) referrees = db.relationship('Donor', backref=(db.backref('referrer', remote_side=[id]))) active = db.Column(db.Boolean(), default=True) created_at = db.Column(db.DateTime, default=db.func.now()) updated_at = db.Column(db.DateTime, default=db.func.now()) def __init__(self): """intitialization here""" def generate_sn(self): self.sn = "DN" + self.first_name[0] + self.middle_name[0] + str( random.randint(10000, 99999)) def update_active(self): self.active = True if (self.ndefbd - datetime.datetime.now()).days <= 0 else False def update_status(self): if self.referrees and self.donations: if len(self.referrees) < 2 and len(self.donations) < 2: self.status = "Bronze" elif len(self.referrees) < 6 and len(self.donations) < 3: self.status = "Silver" elif len(self.referrees) >= 6 and len(self.donations) >= 3: self.status = "Gold" else: self.status = "Bronze" db.session.add(self) db.session.commit() def update_dolbd(self, value): self.dolbd = value self.update_ndefbd() self.update_status() db.session.add(self) db.session.commit() def update_ndefbd(self, ndefbd_t=""): if ndefbd_t == "": self.ndefbd = self.dolbd + datetime.timedelta(days=90) self.update_active() else: self.ndefbd = ndefbd_t self.update_active() db.session.add(self) db.session.commit() def _asdict(self): return { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs } def _return_data(self): from project.server.models.Subscriber import Subscriber donor_data = self._asdict() donor_data['donations'] = [don._asdict() for don in self.donations] for j in range(len(self.donations)): donor_data['donations'][j]['hospital'] = self.donations[ j].hospital._asdict() match = Subscriber().query.filter( Subscriber.blood_group.in_( RECEIVE_MATCH[donor_data['blood_group']])).all() donor_data['match'] = [bg._asdict() for bg in match] donor_data['referrer'] = self.referrer._asdict( ) if self.referrer else None donor_data['deferrals'] = [ deferral._asdict() for deferral in self.deferrals ] donor_data['referrees'] = [ref._asdict() for ref in self.referrees] donor_data['done_at'] = self.done_at._asdict() return donor_data
class Metadata(db.Model): id = db.Column(db.Integer, primary_key=True) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) url_id = db.Column(db.Integer, db.ForeignKey('urls.id'), nullable=False) u = db.relationship('Urls', backref=db.backref('url', lazy=True))