Пример #1
0
class Section(db.Model):
	__tablename__ ="sections"
	id = db.Column(db.Integer, primary_key=True)
	code = db.Column(db.String(80), unique=True)
	name = db.Column(db.String(80))
	project_id = db.Column(db.Integer, db.ForeignKey('projects.id'))
	project= db.relationship('Project', backref='section')
	parent_id = db.Column(db.Integer, db.ForeignKey('sections.id'))
	parent = db.relationship(lambda: Section, remote_side=id, backref='subs')
	
	active = db.Column(db.Boolean)
	__table_args__ = (
		db.UniqueConstraint('code', 'project_id', name='uix_sec1'),
	)
	def __init__(self, code, name, project, parent, active=True):
		self.code = code
		self.name = name
		self.active = active
		self.project_id = project.id
		self.parent = parent
		if parent:
			self.parent_id= parent.id
		
	def json(self):
		return ({"name": self.name , "id": str(self.id) ,
                "parent_id": str(self.parent_id), 
                "level": 0,
                "childs":[ ]})
		
	def __repr__(self):
		return self.name
Пример #2
0
class Project(db.Model):
    __tablename__ = "projects"
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(80), unique=True)
    name = db.Column(db.String(80))
    owner = db.Column(db.Integer, db.ForeignKey('users.id'))
    description = db.Column(db.Text)
    start = db.Column(db.DateTime)
    finish = db.Column(db.DateTime)
    cycle_id = db.Column(db.Integer, db.ForeignKey('reportingcycles.id'))
    cycle = db.relationship('ReportingCycle', backref='project')
    org_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
    organisation = db.relationship('Organisation', backref='project')
    status = db.Column(db.Boolean, default=True)
    users = db.relationship("UserProject")

    __table_args__ = (db.UniqueConstraint('code', 'org_id', name='uix_prj1'), )

    def __init__(self, code, name, description, owner, start, finish, cycle,
                 organisation, status):
        self.code = code
        self.name = name
        self.owner = owner
        self.description = description
        self.start = start
        self.finish = finish
        self.status = status
        self.org_id = organisation.id
        self.cycle_id = cycle.id

    def __repr__(self):
        return self.name
Пример #3
0
class Company(db.Model):
    __tablename__ = "companies"
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(80), unique=True)
    name = db.Column(db.String(80))
    description = db.Column(db.Text)
    address = db.Column(db.Text)
    contact_number = db.Column(db.Text)
    contact_person = db.Column(db.Text)
    org_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
    organisation = db.relationship('Organisation', backref='company')
    status = db.Column(db.Boolean, default=True)

    __table_args__ = (db.UniqueConstraint('code', 'org_id', name='uix_prj1'), )

    def __init__(self,
                 code,
                 name,
                 description,
                 address,
                 contact_number,
                 contact_person,
                 organisation,
                 status=True):
        self.code = code
        self.name = name
        self.description = description
        self.address = address
        self.constact_person = contact_person
        self.contact_number = contact_number
        self.org_id = organisation.id

    def __repr__(self):
        return self.name
Пример #4
0
class Message(db.Model):
    __tablename__ = "messages"
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(100))
    sender_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    sender = db.relationship('User', foreign_keys=[sender_id])
    recipient_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    recipient = db.relationship('User', foreign_keys=[recipient_id])
    body = db.Column(db.String(255))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    read = db.Column(db.Boolean)
    is_active = db.Column(db.Boolean)

    def __repr__(self):
        return '<Message {}>'.format(self.body)
Пример #5
0
class User(db.Model):
    __tablename__='users'
    id = db.Column(db.Integer, primary_key =True)
    firstname = db.Column(db.String(80))
    lastname = db.Column(db.String(80))
    email = db.Column(db.String(35), unique =True)
    username = db.Column(db.String(80), unique= True)
    password = db.Column(db.String(80))
    organisation_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
    organisation= db.relationship('Organisation', backref='users')
    confirmed = db.Column(db.Boolean, nullable=False, default=False)
    confirmed_on = db.Column(db.DateTime, nullable=True)
    is_admin = db.Column(db.Boolean, default=False)
    is_active = db.Column(db.Boolean, default=True)


    def __init__(self, firstname, lastname, email, username, password, organisation, is_admin=False, is_active=True, confirmed=False, confirmed_on= None):
        self.firstname = firstname
        self.email = email
        self.lastname = lastname
        self.password = password
        self.is_admin = is_admin
        self.username = username
        if organisation:
            self.organisation_id = organisation.id
        self.is_active= is_active
        self.confirmed = confirmed
        self.confirmed_on = confirmed_on

    def get_reset_password_token(self, expires_in=600):
        return jwt.encode(
            {'reset_password': self.id, 'exp': time() + expires_in},
            app.config['SECRET_KEY'], algorithm='HS256').decode('utf-8')

    @staticmethod
    def verify_reset_password_token(token):
        try:
            id = jwt.decode(token, app.config['SECRET_KEY'],
                            algorithms=['HS256'])['reset_password']
        except:
            return
        return User.query.get(id)

    def __repr__(self):
        return self.username
Пример #6
0
class Task(db.Model):
    __tablename__ = "tasks"
    id = db.Column(db.Integer, primary_key=True)
    task_code = db.Column(db.String(80))
    task_name = db.Column(db.String(255))
    early_end_date = db.Column(db.DateTime)
    early_start_date = db.Column(db.DateTime)
    remain_drtn_hr_cnt = db.Column(db.Integer)
    target_drtn_hr_cnt = db.Column(db.Integer)

    def __init__(self, task_code, task_name, early_end_date, early_start_date,
                 remain_drtn_hr_cnt, target_drtn_hr_cnt):
        self.task_code = task_code
        self.task_name = task_name
        self.early_end_date = early_end_date
        self.early_start_date = early_start_date
        self.remain_drtn_hr_cnt = remain_drtn_hr_cnt
        self.target_drtn_hr_cnt = target_drtn_hr_cnt
Пример #7
0
class Organisation(db.Model):
	__tablename__ ="organisations"
	id = db.Column(db.Integer, primary_key=True)
	code = db.Column(db.String(80))
	name = db.Column(db.String(80))
	description = db.Column(db.Text)
	is_active = db.Column(db.Boolean)
	__table_args__ = (
		db.UniqueConstraint('code', 'name', name='uix_org1'),
	)
	def __init__(self, code, name, description, is_active=True):
		self.code = code
		self.name = name
		self.description = description
		self.is_active = is_active
		
	def __repr__(self):
		return self.name
Пример #8
0
class RSRCType(db.Model):
	__tablename__ ="rsrc_types"
	id = db.Column(db.Integer, primary_key=True)
	code = db.Column(db.String(80), unique=True)
	name = db.Column(db.String(80))
	description = db.Column(db.Text)
	organisation_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
	organisation = db.relationship('Organisation', backref='rsrctypes')
	is_active = db.Column(db.Boolean, default=True)

	def __init__(self, code, name, description, organisation, is_active=True):
		self.code = code
		self.name = name
		self.description = description
		if organisation:
			self.organisation_id = organisation.id
		self.is_active = is_active

	def __repr__(self):
		return self.name
Пример #9
0
class Permission(db.Model):
    __tablename__ = "permissions"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    is_active = db.Column(db.Boolean)

    def __init__(self, name, is_active=True):
        self.name = name
        self.is_active = is_active

    def __repr__(self):
        return self.name
Пример #10
0
class UserLog(db.Model):
    __tablename__='users_log'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer)
    date = db.Column(db.DateTime)
    success = db.Column(db.Boolean)
    ipaddr = db.Column(db.String(40))

    def __init__(self, user_id, success, ipaddr, date=None):
        self.user_id = user_id
        self.date = datetime.now()
        self.success = success
        self.ipaddr = ipaddr

    def new_messages(self):
        last_read_time = self.last_message_read_time or datetime(1900, 1, 1)
        return Message.query.filter_by(recipient=self, read=False).count()

    def __repr__(self):
        return 'user:'******' logged on: ' + str(self.date)
Пример #11
0
class Role(db.Model):
    __tablename__='roles'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key =True)
    name = db.Column(db.String(80))
    organisation_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
    organisation = db.relationship('Organisation', backref='roles')
    manager_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    manager = db.relationship(lambda: Role, remote_side=id,backref='subs')
    is_active = db.Column(db.Boolean, default=True)
    __table_args__ = (
		db.UniqueConstraint('name', 'organisation_id', name='uix_rol1'),
	)
    def __init__(self, name, organisation, manager, is_active=True):
        self.name = name
        if organisation is not None:
            self.organisation_id = organisation.id
        if manager is not None:
            self.manager_id = manager.id
        self.is_active = is_active

    def __repr__(self):
        return self.name