Ejemplo n.º 1
0
class Racer(db.Model):

    __tablename__ = 'racers'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(255), unique=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
    name = db.Column(db.String(255), nullable=False)
    city = db.Column(db.String(255))
    state = db.Column(db.String(255))
    points = db.Column(db.Integer)
    cars = db.relationship('Car', secondary=CarRacer, back_populates='racers')
    sponsors = db.relationship('Sponsor',
                               secondary=RacerSponsor,
                               backref='racers')
    laps = db.relationship('BestLap', backref='racer')
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.utcnow(),
                             nullable=False)
    updated_date = db.Column(db.DateTime, nullable=True)

    #Picture

    def __init__(self, email, name, city, state, points):
        self.email = email
        self.name = name
        self.city = city
        self.state = state
        self.points = points
        self.created_date = datetime.datetime.now()

    def __repr__(self):
        return '<Racer {0}>'.format(self.name)
Ejemplo n.º 2
0
class Course(db.Model):

    __tablename__ = 'courses'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    description = db.Column(db.Text(), nullable=False)
    subject = db.Column(db.String(255), nullable=False)
    start_date = db.Column(db.DateTime, nullable=False)
    end_date = db.Column(db.DateTime, nullable=False)
    active = db.Column(db.Boolean, nullable=False, default=True)
    teacher_id = db.Column(db.Integer,
                           db.ForeignKey('teachers.id'),
                           nullable=False)
    teacher = db.relationship('Teacher', backref='courses')
    students = db.relationship('Student',
                               secondary=course_student_association_table,
                               backref='courses')

    def __init__(self, name, description, subject, start_date, end_date,
                 teacher_id):
        self.name = name
        self.description = description
        self.subject = subject
        self.start_date = start_date
        self.end_date = end_date
        self.teacher_id = teacher_id

    def __repr__(self):
        return '<Class {0}>'.format(self.name)
Ejemplo n.º 3
0
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}
Ejemplo n.º 4
0
class Itinerary(db.Model):

    __tablename__ = "itineraries"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    events = db.relationship("Event",
                             secondary=itinerary_events,
                             back_populates="itineraries")
    trip = db.relationship("Trip", back_populates="itineraries")
    trip_id = db.Column(db.Integer, db.ForeignKey("trips.id"))
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    user = db.relationship("User", foreign_keys=[user_id])
    app_user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    approved_user = db.relationship("User", foreign_keys=[app_user_id])
    req_user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    requesting_user = db.relationship("User", foreign_keys=[req_user_id])
    last_edited = db.Column(db.DateTime)

    def __init__(self, name, trip, user):
        self.name = name
        self.trip = trip
        self.user = user
        self.last_login = datetime.datetime.now()
        self.approved_user = None
        self.requesting_user = None

    def update_edited(self):
        self.last_edited = datetime.datetime.now()
Ejemplo n.º 5
0
class Section(db.Model):
    __tablename__ = 'section'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    owner_id = db.Column(db.Integer, nullable=False)
    parentSectionId = db.Column(db.Integer, nullable=True)
    assessment_id = db.Column(db.Integer,
                              db.ForeignKey('assessment.id'),
                              nullable=False)
    created_date = db.Column(db.DateTime, nullable=False)
    modified_date = db.Column(db.DateTime, nullable=True)
    status = db.Column(db.String(255), nullable=True)

    quesRelation = db.relationship('Question', backref='section', lazy=True)
    sectionsdpi = db.relationship('DpiAudit', backref='section', lazy=True)

    def __init__(self, name, owner_id, parentSectionId, assessment_id):
        self.name = name
        self.owner_id = owner_id
        self.parentSectionId = parentSectionId
        self.assessment_id = assessment_id
        self.created_date = datetime.datetime.now()

    def __repr__(self):
        return '<Section %r>' % (self.name)

    def to_dict(self):
        return {
            c.key: getattr(self, c.key)
            for c in inspect(self).mapper.column_attrs
        }
Ejemplo n.º 6
0
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
        }
Ejemplo n.º 7
0
class OrderRepairAssociation(db.Model, CRUDMixin):
    __tablename__ = 'order_repair_association'
    order_id = db.Column(db.Integer,
                         db.ForeignKey('order.id'),
                         primary_key=True)
    repair_id = db.Column(db.Integer,
                          db.ForeignKey('repair.id'),
                          primary_key=True)

    order = db.relationship("Order", back_populates="_repairs")
    repair = db.relationship("Repair", back_populates="orders")
Ejemplo n.º 8
0
class Customer(db.Model, CRUDMixin, SessionStoreMixin):
    __tablename__ = "customer"
    SESSION_KW = __tablename__

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    tricoma_id = db.Column(db.String, nullable=True, index=True)
    first_name = db.Column(db.String(255),
                           nullable=True,
                           unique=False,
                           index=True)
    last_name = db.Column(db.String(255),
                          nullable=True,
                          unique=False,
                          index=True)
    tricoma_username = db.Column(db.String(255),
                                 nullable=True,
                                 unique=False,
                                 index=False)
    street = db.Column(db.String(255), nullable=True, unique=False, index=True)
    zip_code = db.Column(db.String(10),
                         nullable=True,
                         unique=False,
                         index=True)
    city = db.Column(db.String(255), nullable=True, unique=False, index=True)
    tel = db.Column(db.String(64), nullable=True, unique=False, index=True)
    email = db.Column(db.String(255), nullable=False, unique=False, index=True)
    registered_on = db.Column(db.DateTime,
                              nullable=False,
                              default=datetime.datetime.now)

    # Relations
    orders = db.relationship("Order", back_populates="customer")
    enquiries = db.relationship("MiscInquiry", back_populates="customer")

    def __repr__(self):
        return self.first_name + " " + self.last_name

    @classmethod
    def deserialize(cls, obj):
        try:
            customer_id = obj['customer_id']
            instance = cls.query.get(customer_id)
            return instance
        except KeyError as error:
            raise ValueError(
                f"{obj} is an invalid CustomerRepairDTO") from error

    @classmethod
    def query_by_mail(cls, email: str) -> typing.Optional:
        return cls.query.filter(cls.email == email).first()

    def serialize(self) -> dict:
        return dict(customer_id=self.id)
Ejemplo n.º 9
0
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    question_type = db.Column(db.String(255))
    question_label = db.Column(db.String(255))
    action_status = db.Column(db.String(255))
    comments = db.Column(db.String(255))
    riskWeightageStatus = db.Column(db.String(255))
    assignedTo = db.Column(db.String(255))
    owner = db.Column(db.String(255))
    actions = db.relationship('Action', backref='question', lazy=True)
    answer_id = db.Column(db.Integer, db.ForeignKey('answer.id'))
    # define relationship
    answer = db.relationship('Answer', backref='question')
Ejemplo n.º 10
0
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
        }
Ejemplo n.º 11
0
class Appointment(BaseModel, Base):
    """"""
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    date = db.Column(db.DateTime, nullable=False)
    notes = db.Column(db.Text, nullable=False)
    treatments = db.relationship('Treatment',
                                 secondary='user_symptom_treatment')
Ejemplo n.º 12
0
class Projects(db.Model):

    __tablename__ = 'projects'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    proj_id = db.Column(db.String(10), nullable=False)
    proj_name = db.Column(db.String(255), nullable=False)
    proj_desc = db.Column(db.String(9999), nullable=False)
    proj_status = db.Column(db.String(25), nullable=False)
    created_by = db.Column(db.Integer, nullable=False)
    modified_by = db.Column(db.Integer, nullable=True)
    created_date = db.Column(db.DateTime, nullable=False)
    modified_date = db.Column(db.DateTime, nullable=True)
    actions = db.relationship('Assessment', backref='projects', lazy=True)

    def __init__(self, proj_id, proj_name, proj_desc, proj_status, created_by):
        self.proj_id = proj_id
        self.proj_name = proj_name
        self.proj_desc = proj_desc
        self.proj_status = proj_status
        self.created_by = created_by
        self.created_date = datetime.datetime.now()

    def __repr__(self):
        return '<Projects %r>' % (self.proj_name)

    def to_dict(self):
        return {
            c.key: getattr(self, c.key)
            for c in inspect(self).mapper.column_attrs
        }
Ejemplo n.º 13
0
class User(db.Model):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)
    projects = db.relationship('Project', backref='users', lazy=True)

    def __init__(self, email, password, admin=False):
        self.email = email
        self.password = bcrypt.generate_password_hash(
            password,
            current_app.config.get('BCRYPT_LOG_ROUNDS')).decode('utf-8')
        self.admin = admin

    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 '<User {0}>'.format(self.email)
Ejemplo n.º 14
0
class User(db.Model):
    """ User Model for storing user related details """
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(1000), nullable=False)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    registered_on = db.Column(db.DateTime, nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)
    entries = db.relationship('Entry', backref='user', lazy='dynamic')

    def __init__(self, name, email, password, admin=False):
        self.name = name
        self.email = email
        self.password = bcrypt.generate_password_hash(
            password, app.config.get('BCRYPT_LOG_ROUNDS')).decode()
        self.registered_on = datetime.datetime.now()
        self.admin = admin

    def encode_auth_token(self, user_id):
        """
        Generates the Auth Token
        :return: string
        """
        try:
            days, hours, seconds = app.config.get('TOKEN_EXPIRATION')
            payload = {
                'exp':
                datetime.datetime.utcnow() +
                datetime.timedelta(days=days, hours=hours, seconds=seconds),
                'iat':
                datetime.datetime.utcnow(),
                'sub':
                user_id
            }
            return jwt.encode(payload,
                              app.config.get('SECRET_KEY'),
                              algorithm='HS256')
        except Exception as e:
            return e

    @staticmethod
    def decode_auth_token(auth_token):
        """
        Validates the auth token
        :param auth_token:
        :return: integer|string
        """
        try:
            payload = jwt.decode(auth_token, app.config.get('SECRET_KEY'))
            is_blacklisted_token = BlacklistToken.check_blacklist(auth_token)
            if is_blacklisted_token:
                return 'Token blacklisted. Please log in again.'
            else:
                return payload['sub']
        except jwt.ExpiredSignatureError:
            return 'Signature expired. Please log in again.'
        except jwt.InvalidTokenError:
            return 'Invalid token. Please log in again.'
Ejemplo n.º 15
0
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    registered_on = db.Column(db.DateTime, nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)
    bucketlists = db.relationship('Bucketlist',
                                  order_by='Bucketlist.id',
                                  cascade="all, delete-orphan")

    def __init__(self, email, password, admin=False):
        self.email = email
        self.password = bcrypt.generate_password_hash(
            password, app.config.get('BCRYPT_LOG_ROUNDS'))
        self.registered_on = datetime.datetime.now()
        self.admin = admin

    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 '<User {0}>'.format(self.email)
Ejemplo n.º 16
0
class Order(db.Model):

    __tablename__ = "orders"

    class STATUS(Enum):
        PENDING = 'pending'
        COMPLETED = 'completed'
        CANCELLED = 'cancelled'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    number = db.Column(db.String(255), nullable=False, unique=True)
    status = db.Column(db.Enum(STATUS), nullable=False, default=STATUS.PENDING)
    date_created_gmt = db.Column(db.DateTime,
                                 nullable=False,
                                 default=datetime.utcnow)
    modification_date_gmt = db.Column(db.DateTime,
                                      nullable=False,
                                      default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    order_items = db.relationship("OrderItem")

    def get_id(self):
        return self.id

    def total(self):
        return sum(oi.total() for oi in self.order_items)

    def get_status(self):
        return self.status

    def __repr__(self):
        return "<Order {0}>".format(self.number)
Ejemplo n.º 17
0
class Hospital(db.Model):

    __tablename__ = "hospitals"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100))
    city = db.Column(db.String(100))
    region = db.Column(db.String(100))
    address = db.Column(db.String(100))
    phone1 = db.Column(db.String(100))
    phone2 = db.Column(db.String(100))
    unit_blood_pile = db.Column(db.Integer)
    transfusions = db.relationship('Transfusion',
                                   backref='hospital',
                                   lazy=True)
    donations = db.relationship('Donation', backref='hospital', lazy=True)
    donors = db.relationship('Donor', backref='done_at', lazy=True)
    subscribers = db.relationship('Subscriber', backref='done_at', lazy=True)
    created_at = db.Column(db.DateTime, default=db.func.now())
    updated_at = db.Column(db.DateTime, default=db.func.now())

    def _asdict(self):
        return {
            c.key: getattr(self, c.key)
            for c in db.inspect(self).mapper.column_attrs
        }

    def _return_data(self):
        hosp_arr = self._asdict()
        hosp_arr['transfusions'] = [
            tran._asdict() for tran in self.transfusions
        ]
        hosp_arr['donations'] = [don._asdict() for don in self.donations]
        hosp_arr['donors'] = [don._asdict() for don in self.donors]
        hosp_arr['subscribers'] = [sub._asdict() for sub in self.subscribers]
        for j in range(len(self.transfusions)):
            hosp_arr['transfusions'][j]['subscriber'] = self.transfusions[
                j].subscriber._asdict()
            hosp_arr['transfusions'][j]['hospital'] = self.transfusions[
                j].hospital._asdict()
        for j in range(len(self.donations)):
            hosp_arr['donations'][j]['donor'] = self.donations[
                j].donor._asdict()
            hosp_arr['donations'][j]['hospital'] = self.donations[
                j].hospital._asdict()

        return hosp_arr
Ejemplo n.º 18
0
class Genre(db.Model):
    __tablename__ = 'genre'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False, unique=True)
    artists = db.relationship('Artist', backref="genre")

    def __init__(self, name):
        self.name = name
Ejemplo n.º 19
0
class Relationship(db.Model):

    __tablename__ = "relationships"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    followed_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    follower = db.relationship(User, primaryjoin=follower_id == User.id)
    followed = db.relationship(User, primaryjoin=followed_id == User.id)
    created_on = db.Column(db.DateTime, nullable=False)
    updated_on = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.datetime.now,
                           onupdate=datetime.datetime.now)

    def __init__(self, follower_id, followed_id):
        self.follower_id = follower_id
        self.followed_id = followed_id
        self.created_on = datetime.datetime.now()
Ejemplo n.º 20
0
class CartItem(db.Model):
    __tablename__ = 'cart_items'

    # Constants
    ADD = 'add'
    SUBTRACT = 'subtract'
    REMOVE = 'remove'
    ACTIONS = (ADD, SUBTRACT, REMOVE)

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    quantity = db.Column(db.Integer, default=1)
    price = db.Column(db.Numeric(asdecimal=True, precision=10, scale=2), nullable=False)

    cart_id = db.Column(db.Integer, db.ForeignKey('carts.id'), nullable=True)
    cart = db.relationship('Cart', backref=backref("cart_items", lazy='joined', cascade="all, delete-orphan"),
                           lazy=True)
    product_id = db.Column(db.Integer, db.ForeignKey('products.id'), nullable=True)
    product = db.relationship('Product', backref="cartitem", uselist=False, lazy='joined')
Ejemplo n.º 21
0
class Question(db.Model):
    __tablename__ = 'question'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    question_type = db.Column(db.String(255), nullable=False)
    question_label = db.Column(db.String(255), nullable=False)
    section_id = db.Column(db.Integer,
                           db.ForeignKey('section.id'),
                           nullable=True)
    action_status = db.Column(db.String(255), nullable=True)
    owner_id = db.Column(db.Integer, nullable=False)
    isAnswered = db.Column(db.Boolean, nullable=False)
    comments = db.Column(db.String(255), nullable=True)
    risk_weightage_status = db.Column(db.String(255), nullable=True)
    created_date = db.Column(db.DateTime, nullable=False)
    modified_date = db.Column(db.DateTime, nullable=True)

    answer = db.relationship('Answer', uselist=False, backref="question")
    actionss = db.relationship('ActionNote', backref='question', lazy=True)
    DpiAuditQ = db.relationship('DpiAudit', backref='question', lazy=True)
    attachment = db.relationship('Attachments', backref='question', lazy=True)

    def __init__(self, question_type, question_label, section_id,
                 action_status, owner_id, isAnswered, comments,
                 risk_weightage_status):
        self.question_type = question_type
        self.question_label = question_label
        self.section_id = section_id
        self.action_status = action_status
        self.owner_id = owner_id
        self.isAnswered = isAnswered
        self.comments = comments
        self.risk_weightage_status = risk_weightage_status
        self.created_date = datetime.datetime.now()

    def __repr__(self):
        return '<Question %r>' % (self.question_type)

    def to_dict(self):
        return {
            c.key: getattr(self, c.key)
            for c in inspect(self).mapper.column_attrs
        }
Ejemplo n.º 22
0
class Action(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    section_id = db.Column(db.Integer)
    owner_id = db.Column(db.Integer)
    question_id = db.Column(db.Integer,
                            db.ForeignKey('question.id'),
                            nullable=False)
    additional_info = db.relationship('AdditionalInformation',
                                      backref='action',
                                      lazy=True)
Ejemplo n.º 23
0
class User_Symptom(BaseModel, Base):
    """"""
    __tablename__ = 'user_symptom'
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    symptom_id = db.Column(db.Integer, db.ForeignKey('symptom.id'))
    start_date = db.Column(db.DateTime, nullable=False)
    end_date = db.Column(db.DateTime, nullable=False)
    notes = db.Column(db.Text, nullable=True)
    treatments = db.relationship('Treatment',
                                 secondary='user_symptom_treatment')
Ejemplo n.º 24
0
class Shop(BaseModel):
    """ Shops """
    __tablename__ = 'shop'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), unique=True)

    # Relations
    orders = db.relationship("Order", back_populates="shop")

    def __repr__(self):
        return self.name
Ejemplo n.º 25
0
class OrderItem(db.Model):
    __tablename__ = "order_items"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    product_id = db.Column(db.Integer, db.ForeignKey('products.id'))
    quantity = db.Column(db.Integer, nullable=False)
    order_id = db.Column(db.Integer, db.ForeignKey('orders.id'))

    product = db.relationship("Product")

    def total(self):
        return self.product.price * self.quantity
Ejemplo n.º 26
0
class User(BaseModel, Base):

    __tablename__ = 'users'

    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    street_address = db.Column(db.String(64), nullable=True)
    city = db.Column(db.String(64), nullable=True)
    state = db.Column(db.String(2), nullable=True)
    zip_code = db.Column(db.Integer, nullable=True)
    registered_on = db.Column(db.DateTime, nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)

    symptoms = db.relationship('Symptom', secondary='user_symptom')
    appointments = db.relationship('Appointment',
                                   backref='users',
                                   lazy='dynamic')

    def __init__(self, email, password, admin=False):
        self.email = email
        self.password = bcrypt.generate_password_hash(
            password, app.config.get('BCRYPT_LOG_ROUNDS')).decode('utf-8')
        self.registered_on = datetime.datetime.now()
        self.admin = admin

    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 '<User {0}>'.format(self.email)
Ejemplo n.º 27
0
class MiscInquiry(BaseModel):
    __tablename__ = "misc_enquiry"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    description = db.Column(db.Text, nullable=False)

    # Relation
    customer_id = db.Column(db.Integer,
                            db.ForeignKey('customer.id'),
                            nullable=False)
    customer = db.relationship("Customer", back_populates="enquiries")

    def __repr__(self) -> str:
        return self.customer.name
Ejemplo n.º 28
0
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}
Ejemplo n.º 29
0
class Event(db.Model):

    __tablename__ = 'events'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)
    tracks = db.relationship('Track', secondary=TrackEvent, backref='events')
    laps = db.relationship('BestLap', backref='event')
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.utcnow(),
                             nullable=False)
    updated_date = db.Column(db.DateTime, nullable=True)

    def __init__(self, name, start_date, end_date):
        self.name = name
        self.start_date = start_date
        self.end_date = end_date
        self.created_date = datetime.datetime.now()

    def __repr__(self):
        return '<Event {0}>'.format(self.name)
Ejemplo n.º 30
0
class Trip(db.Model):

    __tablename__ = "trips"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    location = db.Column(db.String(255), nullable=False)
    # we should add date constraitns: start_date < end_date
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)
    users = db.relationship("User",
                            secondary=users_trips,
                            back_populates="trips")
    itineraries = db.relationship("Itinerary", back_populates="trip")

    def __init__(self, name, location, start_date, end_date, user):
        self.name = name
        self.location = location
        self.start_date = start_date
        self.end_date = end_date
        self.users.append(user)

    def __repr__(self):
        return '<Trip {0}'.format(self.name)