Exemplo n.º 1
0
class UserRequest(db.Model):
    """Define the UserRequest data-model"""
    __tablename__ = 'user_requests'
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(),
                        db.ForeignKey('users.id', ondelete='CASCADE'))
    authorizer_id = db.Column(db.Integer(),
                              db.ForeignKey('users.id', ondelete='CASCADE'))
    request_date = db.Column(db.DateTime())
    auth_date = db.Column(db.DateTime())
    start_date = db.Column(db.DateTime())
    end_date = db.Column(db.DateTime())
    request_type_id = db.Column(
        db.Integer(), db.ForeignKey('request_types.id', ondelete='CASCADE'))
    prv_note_to_auth = db.Column(db.UnicodeText(255), server_default='')
    prv_note_from_auth = db.Column(db.UnicodeText(255), server_default='')
    pub_note = db.Column(db.UnicodeText(255), server_default='')
    authorized = db.Column('is_authorized',
                           db.Boolean(),
                           nullable=False,
                           server_default='0')

    # Define relationships to User
    user = db.relationship('User', backref='requests', foreign_keys=[user_id])
    authorizer = db.relationship('User',
                                 backref='authorizations',
                                 foreign_keys=[authorizer_id])
    # Define relationship to RequestType
    request_type = db.relationship('RequestType', backref='user_requests')
    # Define relationship to Allowance
    allowance = db.relationship(
        'Allowance',
        primaryjoin=
        'and_(foreign(UserRequest.user_id) == remote(Allowance.user_id), foreign(UserRequest.request_type_id) == remote(Allowance.request_type_id))',
        backref='user_requests')
Exemplo n.º 2
0
class AssociationCourseGroup(db.Model):
    __tablename__ = 'Course_X_Group'
    course_id = db.Column(db.Integer, db.ForeignKey('EducationalСourse.id'), primary_key=True)
    group_id = db.Column(db.Integer, db.ForeignKey('EducationalGroup.id'), primary_key=True)
    extra_data = db.Column(db.String(50))
    is_active = db.Column(db.Integer, nullable=False, default = 0)
    created_on = db.Column(db.DateTime(), default=datetime.utcnow)
    updated_on = db.Column(db.DateTime(), default=datetime.utcnow,  onupdate=datetime.utcnow)
    child = db.relationship("EducationalGroup", back_populates="parents")
    parent = db.relationship("EducationalCourse", back_populates="children")

    def __init__(self, course_id:int, group_id:int, is_active = 1, extra_data = ''):
        self.course_id = course_id
        self.group_id = group_id
        self.is_active = is_active
        self.extra_data = extra_data
    """
    Many-to-Many association between courses and groups
    Firstly, check: Is association exist? 
    -> Exists:  Update optional parametrs
    -> Doesn't exist:  Create new association with all available parametrs
    """
    def associate_course_with_group(self):
        association = db.session.query(AssociationCourseGroup).filter(AssociationCourseGroup.course_id == self.course_id).filter(AssociationCourseGroup.group_id == self.group_id).first()
        if association != None:
            if (self.is_active != association.is_active):
                association.is_active = self.is_active
                db.session.commit()
            if (self.extra_data != association.extra_data):
                association.extra_data = self.extra_data
                db.session.commit()
        else:
            db.session.add(self)
            db.session.commit()
Exemplo n.º 3
0
class CourseHometask(db.Model):
    __tablename__ = 'course_hometask'
    id = db.Column(db.Integer, nullable = False, primary_key=True)
    course_id = db.Column(db.Integer(), db.ForeignKey('EducationalСourse.id'), nullable = False )
    name = db.Column(db.String(100), nullable = False)
    content = db.Column(db.String(10000), nullable = False)
    start_dttm = db.Column(db.DateTime(), nullable = False)
    end_dttm = db.Column(db.DateTime(), nullable = False)
    created_on = db.Column(db.DateTime(), default=datetime.utcnow)
    updated_on = db.Column(db.DateTime(), default=datetime.utcnow,  onupdate=datetime.utcnow)
    deleted = db.Column(db.Integer() )

    def __init__(self, course_id, name, content, start_dttm, end_dttm):
        self.course_id = course_id
        self.name = name
        self.content = content
        self.start_dttm = start_dttm
        self.end_dttm = end_dttm
        self.deleted = 0
    
    def set_content(self, content):
	    self.content = content

    def delete(self):
        self.deleted = 1
    
    def __repr__(self):
	    return "<CourseHometask Info {}:{}:{}>".format(self.id, self.course_id, self.name)
Exemplo n.º 4
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64), index=True, unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)
    active = db.Column(db.Boolean(), default=True)

    confirmed_at = db.Column(db.DateTime())
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(45))
    current_login_ip = db.Column(db.String(45))
    login_count = db.Column(db.Integer)

    roles = db.relationship('Role',
                            secondary="roles_users",
                            backref=db.backref('users', lazy='dynamic'))
    chats = db.relationship('Chat',
                            secondary="chat_users",
                            backref="chats",
                            lazy='dynamic')

    def __repr__(self):
        return '<User %r>' % (self.email)

    def get_id(self):
        try:
            return unicode(self.id)  # python 2
        except NameError:
            return str(self.id)  # python 3
Exemplo n.º 5
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    username = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    deleted = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(100))
    current_login_ip = db.Column(db.String(100))
    login_count = db.Column(db.Integer)

    # roles = db.relationship('Role', secondary='roles_users',
    #                         backref=db.backref('users', lazy='dynamic'))

    def gravatar(self, size=64, consider_settings=True):
        parameters = {'s': str(size), 'd': 'mm'}
        return "https://www.gravatar.com/avatar/" + \
            hashlib.md5(self.email.lower()).hexdigest() + \
            "?" + urllib.urlencode(parameters)

    def __str__(self):
        return self.email
Exemplo n.º 6
0
class Trip(db.Model):
    """Define schema for trip table
    """

    id = db.Column(db.Integer, primary_key=True, doc='id da viagem')

    start_date = db.Column(db.DateTime(timezone=True),
                           nullable=False,
                           index=True,
                           default=db.func.now(),
                           doc='Data início da viagem')

    end_date = db.Column(db.DateTime(timezone=True),
                         nullable=False,
                         index=True,
                         default=db.func.now(),
                         doc='Data fim da viagem')

    classification = db.Column(types.Enum(EnumBikeTripType,
                                          name='enum_bike_trip_type'),
                               nullable=True,
                               doc=u'Classificacão da viagem')

    score = db.Column(db.Integer(), nullable=True, doc='Nota da viagem')

    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False,
                        doc='ID do usuário que realizou a viagem')

    user = db.relationship('User', doc='Instancia de User')
Exemplo n.º 7
0
class FlicketPost(Base):
    __tablename__ = 'flicket_post'

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

    ticket_id = db.Column(db.Integer, db.ForeignKey(FlicketTicket.id))
    ticket = db.relationship(FlicketTicket, back_populates='posts')

    content = db.Column(db.String(field_size['content_max_length']))

    user_id = db.Column(db.Integer, db.ForeignKey(FlicketUser.id))
    user = db.relationship(FlicketUser, foreign_keys='FlicketPost.user_id')

    date_added = db.Column(db.DateTime())
    date_modified = db.Column(db.DateTime())

    modified_id = db.Column(db.Integer, db.ForeignKey(FlicketUser.id))
    modified = db.relationship(FlicketUser,
                               foreign_keys='FlicketPost.modified_id')

    # finds all the images associated with the post
    uploads = db.relationship(
        'FlicketUploads',
        primaryjoin="and_(FlicketPost.id == FlicketUploads.posts_id)")

    # finds all the actions associated with the post
    actions = db.relationship(
        'FlicketAction',
        primaryjoin="and_(FlicketPost.id == FlicketAction.post_id)")
Exemplo n.º 8
0
class User(UserMixin, db.Model):
    def __init__(self, id, first_name='', uuid='', practice_uuid='',
            practice_name='', practice_id='', practice_admin='', invoice_layout = '', namaf_profession = '', practice_role='', practice_folder_id='', active=True):
        self.uuid = uuid
        self.first_name = first_name
        self.practice_uuid = practice_uuid
        self.practice_name = practice_name
        self.practice_id = practice_id
        self.practice_admin = practice_admin
        self.invoice_layout = invoice_layout
        self.namaf_profession = namaf_profession
        self.practice_role = practice_role
        self.id = id
        self.practice_folder_id = practice_folder_id
        self.active = active

    __tablename__ = 'users'
    id = db.Column(db.Integer(), primary_key=True)
    uuid_bin =  db.Column(UUIDType(binary=False))
    uuid_text = db.Column(db.String(36), nullable=False)
    title = db.Column(db.String(255), nullable=True)
    first_name = db.Column(db.String(255), nullable=False)
    second_name = db.Column(db.String(255), nullable=False)
    email = db.Column(db.String(100), unique=True)
    current_practice_uuid = db.Column(db.String(36), nullable=True)
    current_practice_role = db.Column(db.DateTime, nullable=False)
    created_on = db.Column(db.DateTime(),default=datetime.utcnow)
    last_active = db.Column(db.DateTime(),default=datetime.utcnow,onupdate=datetime.utcnow)
Exemplo n.º 9
0
class Job(db.Model):
    """A Job is the basic work unit of Flamenco

    The creation of a job can happen in different ways:
    * within Flamenco (using the job creation form)
    * via a query from an external software (e.g. Attract)
    * withing Blender itself

    Possible statuses for a job are:
    * Waiting (tasks for this job are ready to be dispatched)
    * Active
    * Canceled
    * Failed
    * Paused (will be added later)
    * Completed
    * Waiting
    """
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
    project = db.relationship('Project',
                              backref=db.backref('jobs', lazy='dynamic'))
    name = db.Column(db.String(120))
    status = db.Column(db.String(64))
    priority = db.Column(db.Integer())
    settings = db.Column(db.Text())
    creation_date = db.Column(db.DateTime(), default=datetime.datetime.now)
    date_edit = db.Column(db.DateTime())
    type = db.Column(db.String(64))
    tasks_status = db.Column(db.String(256))
    notes = db.Column(db.Text())
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    user = db.relationship('User', backref=db.backref('job', lazy='dynamic'))

    def __repr__(self):
        return '<Job %r>' % self.name
Exemplo n.º 10
0
class FlicketPost(PaginatedAPIMixin, Base):
    __tablename__ = "flicket_post"

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

    ticket_id = db.Column(db.Integer, db.ForeignKey(FlicketTicket.id))
    ticket = db.relationship(FlicketTicket, back_populates="posts")

    content = db.Column(db.String(field_size["content_max_length"]))

    user_id = db.Column(db.Integer, db.ForeignKey(FlicketUser.id))
    user = db.relationship(FlicketUser, foreign_keys="FlicketPost.user_id")

    date_added = db.Column(db.DateTime())
    date_modified = db.Column(db.DateTime())

    modified_id = db.Column(db.Integer, db.ForeignKey(FlicketUser.id))
    modified = db.relationship(FlicketUser, foreign_keys="FlicketPost.modified_id")

    days = db.Column(db.Numeric(10, 2), server_default="0")

    # finds all the images associated with the post
    uploads = db.relationship(
        "FlicketUploads", primaryjoin="and_(FlicketPost.id == FlicketUploads.posts_id)"
    )

    # finds all the actions associated with the post
    actions = db.relationship(
        "FlicketAction", primaryjoin="FlicketPost.id == FlicketAction.post_id"
    )

    def to_dict(self):
        """

        :return: dict()
        """

        data = {
            "id": self.id,
            "content": self.content,
            "data_added": self.date_added,
            "date_modified": self.date_modified,
            "ticket_id": self.ticket_id,
            "user_id": self.user_id,
            "links": {
                "self": app.config["base_url"] + url_for("bp_api.get_post", id=self.id),
                "created_by": app.config["base_url"]
                + url_for("bp_api.get_user", id=self.user_id),
                "posts": app.config["base_url"]
                + url_for("bp_api.get_posts", ticket_id=self.ticket_id),
            },
        }

        return data

    def __repr__(self):
        return "<FlicketPost: id={}, ticket_id={}, content={}>".format(
            self.id, self.ticket_id, self.content
        )
class User(db.Model, RoleFreeUserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255))
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean(), default=False)
    confirmed_at = db.Column(db.DateTime())
    user_type = db.Column(db.Enum(TypeOfUser, name="type_of_user_types"), nullable=False)
    capabilities = db.Column(MutableList.as_mutable(ARRAY(db.String)), default=[])
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(16))
    current_login_ip = db.Column(db.String(16))
    login_count = db.Column(db.Integer)
    failed_login_count = db.Column(db.Integer, default=0)

    # relationships
    measures = db.relationship(
        "Measure",
        lazy="subquery",
        secondary="user_measure",
        primaryjoin="User.id == user_measure.columns.user_id",
        secondaryjoin="Measure.id == user_measure.columns.measure_id",
        back_populates="shared_with",
    )

    __table_args__ = (UniqueConstraint(email, name="uq_users_email"),)

    def user_name(self):
        return self.email.split("@")[0]

    def is_departmental_user(self):
        return self.user_type == TypeOfUser.DEPT_USER

    def is_rdu_user(self):
        return self.user_type == TypeOfUser.RDU_USER

    def is_admin_user(self):
        return self.user_type == TypeOfUser.ADMIN_USER

    def can(self, capability):
        return capability in self.capabilities

    def can_access_measure(self, measure):
        if self.user_type != TypeOfUser.DEPT_USER:
            return True
        else:
            return self in measure.shared_with

    # DEPRECATED: use `can_access_measure` method instead.
    def can_access(self, measure_slug):
        if self.user_type != TypeOfUser.DEPT_USER:
            return True
        else:
            if any(measure.slug == measure_slug for measure in self.measures):
                return True
            else:
                return False
Exemplo n.º 12
0
class Tasks(db.Model):
    task_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=True)
    details = db.Column(db.String(100), nullable=True)
    start_date = db.Column(db.DateTime('%Y-%m-%d %H:%M'), nullable=True)
    due_date = db.Column(db.DateTime('%Y-%m-%d %H:%M'), nullable=True)
    end_date = db.Column(db.DateTime('%Y-%m-%d %H:%M'), nullable=True)
    state = db.Column(db.String(10))
Exemplo n.º 13
0
class Caught_by(db.Model):
    Officer_id = db.Column(db.String(8),
                           db.ForeignKey("police_officers.Officer_id"),
                           primary_key=True)
    Criminal_id = db.Column(db.Integer(),
                            db.ForeignKey("criminal.Criminal_id"),
                            primary_key=True)
    Start_date = db.Column(db.DateTime(), default=datetime.utcnow())
    End_date = db.Column(db.DateTime())
Exemplo n.º 14
0
class Invoice(db.Model):
    id:int
    practice_uuid:str
    patient_id:str
    medical_aid:str
    date_created:datetime
    date_invoice:datetime
    invoice_id:str
    invoice_file_url:str
    tariff:str
    po_number:int
    hospital_name:str
    admission_date:datetime
    discharge_date:datetime
    procedure:str
    procedure_date:str
    diagnosis:str
    diagnosis_date:datetime
    implants:str
    intra_op:str
    post_op:str
    submitted_on:datetime
    invoice_layout:int
    status:str
    credit_cent:int
    remind_me:datetime
    last_edited:datetime
    last_edited_by:str

    __tablename__ = 'invoices'
    id = db.Column(db.Integer(), primary_key=True)
    practice_uuid = db.Column(db.String(36), nullable=False)
    patient_id = db.Column(db.String(255), nullable=False)
    medical_aid = db.Column(db.String(255), nullable=False)
    date_created = db.Column(db.DateTime(),default=datetime.utcnow)
    date_invoice = db.Column(db.Date(),nullable=False)
    invoice_id = db.Column(db.String(255),nullable=False)
    invoice_file_url = db.Column(db.String(255),nullable=False)
    tariff = db.Column(db.String(255),nullable=False)
    po_number = db.Column(db.Integer(), nullable=True)
    hospital_name = db.Column(db.String(255), nullable=True)
    admission_date = db.Column(db.Date(), nullable=True)
    discharge_date = db.Column(db.Date(), nullable=True)
    procedure = db.Column(db.Text(), nullable=True)
    procedure_date = db.Column(db.Date(), nullable=True)
    diagnosis = db.Column(db.Text(), nullable=True)
    diagnosis_date = db.Column(db.Date(), nullable=True)
    implants = db.Column(db.Text(), nullable=True)
    intra_op = db.Column(db.String(255), nullable=True)
    post_op = db.Column(db.String(255), nullable=True)
    submitted_on = db.Column(db.Date(),nullable=True)
    invoice_layout = db.Column(db.Integer(), nullable=True)
    status = db.Column(db.String(255), default="not-submitted")
    credit_cent = db.Column(db.Integer(), default=0)
    remind_me = db.Column(db.DateTime, nullable=True)
    last_edited = db.Column(db.DateTime(),default=datetime.utcnow,onupdate=datetime.utcnow)
    last_edited_by = db.Column(db.String(255), nullable=True)
Exemplo n.º 15
0
class Vote(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_created = db.Column(db.DateTime(timezone=True), default=db.func.current_timestamp())
    date_modified = db.Column(db.DateTime(timezone=True), default=db.func.current_timestamp(),
    onupdate=db.func.current_timestamp())
    poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'), nullable=False)
    vote_option_id = db.Column(db.Integer, db.ForeignKey('vote_option.id'), nullable=False)

    @staticmethod
    def add_account_vote(account_id, poll_id):
        r = User_voted.query.filter_by(account_id=account_id, poll_id=poll_id).count()
        if(r > 0):
            return False
        
        r = User_voted()
        r.account_id = account_id
        r.poll_id = poll_id
        db.session.add(r)
        db.session.commit()
        return True

    @staticmethod
    def admin_top_polls_most_votes(limit=10):
        stmt  = text("""
        SELECT
            t.vote_cnt,
            poll.id,
            poll.name,
            poll.date_open,
            poll.date_close,
            account.id,
            account.firstname,
            account.lastname
        FROM
            (
                SELECT
                    count(*) as vote_cnt,
                    poll_id
                FROM
                    vote
                GROUP BY
                    poll_id
                ORDER BY
                    count(*) desc
                LIMIT :limit
            ) as t
        LEFT JOIN poll ON (t.poll_id = poll.id)
        LEFT JOIN account ON (account.id = poll.owner_id)
        """).params(limit=limit)
        return db.engine.execute(stmt)

    @staticmethod
    def order66():
        res = db.engine.execute("DELETE FROM vote")
        res = db.engine.execute("DELETE FROM user_voted")
Exemplo n.º 16
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(100), nullable = False)
    surname = db.Column(db.String(100), nullable = False)
    second_name = db.Column(db.String(100), nullable = False)
    username = db.Column(db.String(50), unique=True)
    email = db.Column(db.String(100),  unique=True)
    password_hash = db.Column(db.String(100))
    registration_password_hash = db.Column(db.String(100))
    created_on = db.Column(db.DateTime(), default=datetime.utcnow)
    updated_on = db.Column(db.DateTime(), default=datetime.utcnow,  onupdate=datetime.utcnow)

    def __init__(self, name, surname, second_name):
        self.name = name
        self.surname = surname
        self.second_name = second_name
    
    @staticmethod
    def create_user(name, surname, second_name):
        user = User(name, surname, second_name)
        db_add_objects(user)
        print('Сначала создали юзера = ', user)
        user_info = UserInfo(user.id)
        user_social_pages = UserSocialPages(user.id)
        db_add_objects(user_info, user_social_pages)
        print('Затем создали: ',user,' ',user_info,' ',user_social_pages)
        return user




    def __repr__(self):
	    return "<{}:{}>".format(self.id, self.name + ' ' + self.surname)
    
    def set_username(self, username):
	    self.username = username

    def set_email(self, email):
	    self.email = email

    def set_password(self, password):
	    self.password_hash = generate_password_hash(password)

    def check_password(self, password):
	    return check_password_hash(self.password_hash, password)
    
    def set_registration_password(self, password_length = 10):
        lettersAndDigits = string.ascii_letters + string.digits
        registration_password = ''
        for i in range(password_length):
            registration_password = registration_password + random.choice(lettersAndDigits)
        self.registration_password_hash = generate_password_hash(registration_password)
        return registration_password
Exemplo n.º 17
0
class Ticket(db.Model):
    id = db.Column(db.Integer(), primary_key=True, nullable=False)
    creation_datetime = db.Column(db.DateTime(), nullable=False, default=datetime.datetime.now)
    closed_datetime = db.Column(db.DateTime(), nullable=True)
    title = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text(), nullable=True)
    status_id = db.Column(db.Integer(), db.ForeignKey("status.id"), nullable=False)
    priority_id = db.Column(db.Integer(),db.ForeignKey("priority.id"), nullable=False)
    created_by = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)

    status = relationship("Status")
    priority = relationship("Priority")
    ticket_note = relationship("Ticket_Notes")
Exemplo n.º 18
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(32))
    current_login_ip = db.Column(db.String(32))
    login_count = db.Column(db.Integer)

    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
Exemplo n.º 19
0
class Customer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    full_name = db.Column(db.String())
    email = db.Column(db.String())
    telephone = db.Column(db.String())
    date_registered = db.Column(db.DateTime())
    bookings = db.relationship("Booking", backref="customer")
Exemplo n.º 20
0
class Patient(db.Model):
    practice_uuid:str
    patient_id:str
    patient_name:str
    medical_aid:str
    main_member:str
    patient_birth_date:datetime
    medical_number:str
    case_number:str
    patient_note:str
    created_on:datetime
    #updated_on:datetime
    __tablename__ = 'patients'
    id = db.Column(db.Integer(), primary_key=True)
    practice_uuid = db.Column(db.String(36), nullable=False)
    patient_name = db.Column(db.String(255), nullable=False)
    medical_aid = db.Column(db.String(255), nullable=False)
    main_member = db.Column(db.String(255), nullable=True)
    patient_birth_date = db.Column(db.Date(), nullable=True)
    medical_number = db.Column(db.String(255), nullable=True)
    case_number = db.Column(db.String(255), nullable=True)
    patient_note = db.Column(db.Text, nullable=True)
    created_on = db.Column(db.DateTime(),default=datetime.utcnow)
    #updated_on = db.Column(db.DateTime(),default=datetime.utcnow,onupdate=datetime.utcnow)

    @hybrid_property
    def patient_id(self):
        if self.medical_number is not None:
            return self.medical_number
        else:
            return self.case_number
    @patient_id.expression
    def patient_id(cls):
        return case([(cls.case_number != None,
            cls.case_number),], else_ = cls.medical_number)
Exemplo n.º 21
0
class Task(db.Model):
    """Tasks are created after a Shot is added

    Tasks can be reassigned individually to a different worker, but can be
    deleted and recreated all together. A task is made of "orders" or
    instructions, for example:
    * Check out SVN revision 1954
    * Clean the /tmp folder
    * Render frames 1 to 5 of scene_1.blend
    * Send email with results to [email protected]
    """
    id = db.Column(db.Integer, primary_key=True)
    job_id = db.Column(db.Integer, db.ForeignKey('job.id'))
    job = db.relationship('Job',
        backref=db.backref('tasks', lazy='dynamic'))
    manager_id = db.Column(db.Integer())
    name = db.Column(db.String(64))
    status = db.Column(db.String(64))
    priority = db.Column(db.Integer())
    type = db.Column(db.String(64))
    settings = db.Column(db.Text())
    log = db.Column(db.Text())
    activity = db.Column(db.String(128))
    child_id = db.Column(db.Integer())
    parser = db.Column(db.String(64))
    time_cost = db.Column(db.Integer())
    last_activity = db.Column(db.DateTime())
    # Currently the hostname, later will be a serialized dictionary, storing
    # id and hostname of a worker
    worker = db.Column(db.String(128))


    def __repr__(self):
        return '<Task %r>' % self.id
Exemplo n.º 22
0
class Question(db.Model):
    """deployment model"""
    __tablename__ = 'questions'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    question = db.Column(db.String())
    function_name = db.Column(db.String())
    session = db.Column(db.Integer())
    args = db.Column(db.PickleType())
    answer = db.Column(db.PickleType())
    timeout = db.Column(db.Float())
    created_date = db.Column(db.DateTime(), default=datetime.datetime.utcnow)

    def __init__(self, name, question, function_name, args, answer, timeout,
                 session):
        self.name = name
        self.question = question
        self.function_name = function_name
        self.answer = answer
        self.session = session
        self.args = args
        self.timeout = timeout

    def __repr__(self):
        return '<question {0}, {1}>'.format(self.name, self.id)
Exemplo n.º 23
0
class User(db.Model):
    id = db.Column(UUID(as_uuid=True),
                   primary_key=True,
                   default=uuid.uuid4,
                   unique=True,
                   nullable=False)
    username = db.Column(db.String(64),
                         index=True,
                         unique=True,
                         nullable=False)
    email = db.Column(db.String(120), index=True, unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean(), default=True, nullable=False)
    created = db.Column(db.DateTime(), default=datetime.now(), nullable=False)

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

    def __repr__(self):
        return '<User {}>'.format(self.id)

    def to_json(self):
        return {
            'id': self.id,
            'username': self.username,
            'email': self.email,
            'active': self.active,
            'created': self.created
        }
Exemplo n.º 24
0
class Day(db.Model):
    __tablename__ = 'days'

    id = db.Column(db.Integer(), primary_key=True)
    date = db.Column(db.DateTime(),
                     default=datetime.datetime.utcnow,
                     nullable=False)
    habit_id = db.Column(db.Integer(), db.ForeignKey('habits.id'))
    user_id = db.Column(db.Integer(), db.ForeignKey('users.id'))
    habit_complete = db.Column(db.Boolean())

    #Parent
    habit = relationship("Habit", back_populates="days")

    #Child
    daydescs = relationship("DayDesc",
                            back_populates='day',
                            cascade="all, delete, delete-orphan")

    def __init__(self, date, habit_id, user_id, habit_complete):
        self.date = date
        self.habit_id = habit_id
        self.user_id = user_id
        self.habit_complete = habit_complete

    def __repr__(self):
        return f'{self.date}:{self.habit_id}:{self.habit_complete}'
Exemplo n.º 25
0
class Crime_evidence(db.Model):
    Case_No = db.Column(db.Integer(),
                        db.ForeignKey("crime.Case_No"),
                        primary_key=True)
    Description = db.Column(db.String(128))
    Collection_date = db.Column(db.DateTime(), default=datetime.utcnow())
    location = db.Column(db.String(128))
Exemplo n.º 26
0
class User(Base):

    __tablename__ = "account"

    username = db.Column(db.String(255), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False)

    role_id = db.Column(db.Integer, db.ForeignKey('role.id'), nullable=False)

    date_created = db.Column(db.DateTime(),
                             default=db.func.current_timestamp())

    def __init__(self, name, username, password):
        self.name = name
        self.username = username
        self.password = password

    def get_id(self):
        return self.id

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True
Exemplo n.º 27
0
class UserLedger(db.Model):
    """
    SQLAlchemy object :: `user_ledgers` table.

    Fields
    ------
    id : int
        The primary key and user identifier.
    user_id : int
        The user identifier.
    amount : float
        Transaction value.
    timestamp : datetime
        Timestamp of transaction.
    """

    __tablename__ = "user_ledgers"

    id = db.Column(db.Integer, primary_key=True)
    amount = db.Column(db.Float, nullable=False)
    timestamp = db.Column(db.DateTime(timezone=True), default=func.now())

    # relationships
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)

    def __repr__(self):
        return f"<UserLedger `{self.id}`>"
Exemplo n.º 28
0
class Investment(db.Model):
    """
    SQLAlchemy object :: "investments" table.

    Fields
    ------
    id : int
        The primary key and investment identifier.
    fund_id : str
        The fund identifier.
    line_id : str
        The line identifier.
    amount : float
        Transaction value.
    timestamp : datetime
        Timestamp of transaction.
    """

    __tablename__ = "investments"

    id = db.Column(db.Integer, primary_key=True)
    amount = db.Column(db.Float, nullable=False)
    timestamp = db.Column(db.DateTime(timezone=True), default=func.now())

    # relationships
    fund_id = db.Column(db.Integer, db.ForeignKey("funds.id"), nullable=False)
    line_id = db.Column(db.String(64),
                        db.ForeignKey("lines.id"),
                        nullable=False)

    def __repr__(self):
        return f"<Investment `{self.id}`>"
Exemplo n.º 29
0
class Post(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text())
    timestamp = db.Column(db.DateTime(), index=True, default=datetime.utcnow)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    comments = db.relationship('Comment', backref='post', lazy='dynamic')
Exemplo n.º 30
0
class Fight(db.Model):
    __tablename__ = 'fight'
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.String(128), index=True, unique=False)
    red_fighter_id = db.Column(db.Integer, index=True, unique=False)
    blue_fighter_id = db.Column(db.Integer, index=True, unique=False)
    finish_round = db.Column(db.Integer, index=True, unique=False)
    finish_time = db.Column(db.String(128), index=True, unique=False)
    allowed_round = db.Column(db.Integer, index=True, unique=False)
    time_created = db.Column(db.DateTime(timezone=True),
                             server_default=func.now(),
                             onupdate=func.current_timestamp())

    def __init__(self, date, red_fighter_id, blue_fighter_id, finish_round,
                 finish_time, allowed_round):
        self.date = date
        self.red_fighter_id = red_fighter_id
        self.blue_fighter_id = blue_fighter_id
        self.finish_round = finish_round
        self.finish_time = finish_time
        self.allowed_round = allowed_round

    def __repr__(self):
        line = ('<Fight(date=%r, red_fighter_id=%r, blue_fighter_id=%r,'
                'finish_round=%r, finish_time=%r, allowed_round=%r)>')
        return line % (self.date, self.red_fighter_id, self.blue_fighter_id,
                       self.finish_round, self.finish_time, self.allowed_round)