Beispiel #1
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
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
class UserProject(db.Model):
    __tablename__ = 'user_project'
    project_id = db.Column(db.Integer,
                           db.ForeignKey('projects.id'),
                           primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id'),
                        primary_key=True)
    role_id = db.Column(db.Integer)
    user = db.relationship("User", backref="parent_assocs")
    project = db.relationship("Project", backref="assoc")
    is_active = db.Column(db.Boolean)

    __table_args__ = (db.UniqueConstraint('project_id',
                                          'user_id',
                                          name='uix_1'), )

    def __init__(self, project, user, role, is_active=True):
        self.project_id = project.id
        self.user_id = user.id
        self.role_id = role.id
        self.is_active = is_active
Beispiel #6
0
class SubcontractorCompanies(db.Model):
    __tablename__ = 'subcontractor_company'
    id = db.Column(db.Integer, primary_key=True)
    subcontractor_id = db.Column(db.Integer,
                                 db.ForeignKey('subcontractors.id'))
    company_id = db.Column(db.Integer, db.ForeignKey('companies.id'))
    company = db.relationship("Company", backref="assoc_subcontractor")
    subcontractor = db.relationship("Subcontractor", backref="assoc")
    org_id = db.Column(db.Integer, db.ForeignKey('organisations.id'))
    organisation = db.relationship('Organisation',
                                   backref='subcontractorcompanies')
    is_active = db.Column(db.Boolean)

    __table_args__ = (db.UniqueConstraint('subcontractor_id',
                                          'company_id',
                                          name='sc_cmp_1'), )

    def __init__(self, subcontractor, company, organisation, is_active=True):
        self.subcontractor_id = subcontractor.id
        self.company_id = company.id
        self.org_id = organisation.id
        self.is_active = is_active
Beispiel #7
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