Пример #1
0
    def as_dict(self):
        d = self.as_shallow(turnovers=True)
        d.update({
            'representative': self.representative.as_shallow() if self.representative else None
            })
        return d

    def __repr__(self):
        return "<FinancialData(%s,%r)>" % (self.start_date, self.representative)


Representative.financial_datas = db.relationship(FinancialData,
            lazy='dynamic',
            backref=db.backref('representative',
                uselist=False,
                ))


class FinancialTurnover(db.Model, RevisionedMixIn, ApiEntityMixIn):
    __tablename__ = 'financial_turnover'

    financial_data_id = db.Column(db.String(36), db.ForeignKey('financial_data.id'))
    entity_id = db.Column(db.String(36), db.ForeignKey('entity.id'))

    min = db.Column(db.Integer)
    max = db.Column(db.Integer)
    status = db.Column(db.Unicode)

    def update_values(self, data):
        self.financial_data = data.get('financial_data')
Пример #2
0
    def as_dict(self):
        d = self.as_shallow()
        d.update({
            'entity': self.entity.as_shallow(),
            'memberships': [m.as_dict(organisation=False) for m in self.memberships]
            })
        return d

    def __repr__(self):
        return "<Organisation(%s,%r)>" % (self.id, self.entity)


Entity.organisation = db.relationship(Organisation,
        uselist=False,
        backref=db.backref('entity'))


class OrganisationMembership(db.Model, RevisionedMixIn, ApiEntityMixIn):
    __tablename__ = 'organisation_membership'

    organisation_id = db.Column(db.String(36), db.ForeignKey('organisation.id'))
    representative_id = db.Column(db.String(36), db.ForeignKey('representative.id'))
    status = db.Column(db.Unicode)

    def update_values(self, data):
        self.organisation = data.get('organisation')
        self.representative = data.get('representative')
        self.status = data.get('status')

    @classmethod
Пример #3
0
    def as_dict(self):
        d = self.as_shallow()
        d.update(
            {
                "entity": self.entity.as_shallow(),
                "memberships": [m.as_dict(organisation=False) for m in self.memberships],
            }
        )
        return d

    def __repr__(self):
        return "<Organisation(%s,%r)>" % (self.id, self.entity)


Entity.organisation = db.relationship(Organisation, uselist=False, backref=db.backref("entity"))


class OrganisationMembership(db.Model, RevisionedMixIn, ApiEntityMixIn):
    __tablename__ = "organisation_membership"

    organisation_id = db.Column(db.String(36), db.ForeignKey("organisation.id"))
    representative_id = db.Column(db.String(36), db.ForeignKey("representative.id"))

    def update_values(self, data):
        self.organisation = data.get("organisation")
        self.representative = data.get("representative")

    @classmethod
    def by_rpo(cls, representative, organisation):
        q = db.session.query(cls)
Пример #4
0
        d = self.as_shallow()
        d.update({
            'entity': self.entity.as_shallow() if self.entity else None,
            'contact_country': self.contact_country.as_shallow() if self.contact_country else None,
            'main_category': self.main_category.as_shallow() if self.main_category else None,
            'sub_category': self.sub_category.as_shallow() if self.sub_category else None,
            'head': self.head.as_shallow() if self.head else None,
            'legal': self.legal.as_shallow() if self.legal else None,
            'financial_data': [fd.as_shallow(turnovers=True) for fd in self.financial_datas],
            'organisation_memberships': [om.as_dict(representative=False) for om in self.organisation_memberships],
            'accreditations': [a.as_dict(representative=False) for a in self.accreditations],
            'tags': [t.tag for t in self.tags]
            })
        return d

    def cascade_delete(self):
        for a in self.accreditations:
            a.delete()
        for om in self.organisation_memberships:
            om.delete()
        for fd in self.financial_datas:
            fd.delete()

    def __repr__(self):
        return "<Representative(%s,%r)>" % (self.id, self.entity)

Entity.representative = db.relationship(Representative,
        uselist=False, backref=db.backref('entity'))


Пример #5
0
        d = self.as_shallow()
        d.update({
            'entity': self.entity.as_shallow() if self.entity else None,
            'accreditations': [a.as_dict(person=False) for a in self.accreditations],
            'representatives_head': [r.as_shallow() for r in self.representatives_head],
            'representatives_legal': [r.as_shallow() for r in self.representatives_legal]
            })
        return d

    def __repr__(self):
        return "<Person(%s,%r)>" % (self.id, self.entity)


Entity.person = db.relationship(Person,
        uselist=False,
        backref=db.backref('entity'))


Person.representatives_head = db.relationship('Representative',
            primaryjoin=Representative.head_id==Person.id,
            lazy='dynamic',
            backref=db.backref('head',
                uselist=False,
                primaryjoin=Representative.head_id==Person.id,
                ))


Person.representatives_legal = db.relationship('Representative', 
            primaryjoin=Representative.legal_id==Person.id,
            lazy='dynamic',
            backref=db.backref('legal',
Пример #6
0
                "contact_country": self.contact_country.as_shallow() if self.contact_country else None,
                "head_office": self.head_office.as_shallow() if self.head_office else None,
                "be_office": self.be_office.as_shallow() if self.be_office else None,
                "main_category": self.main_category.as_shallow() if self.main_category else None,
                "sub_category": self.sub_category.as_shallow() if self.sub_category else None,
                "head": self.head.as_shallow() if self.head else None,
                "legal": self.legal.as_shallow() if self.legal else None,
                "financial_data": [fd.as_shallow(turnovers=True) for fd in self.financial_datas],
                "organisation_memberships": [om.as_dict(representative=False) for om in self.organisation_memberships],
                "action_fields": [af.action for af in self.action_fields],
                "interests": [i.interest for i in self.interests],
                "accreditations": [a.as_dict(representative=False) for a in self.accreditations],
                "tags": [t.tag for t in self.tags],
            }
        )
        return d

    def cascade_delete(self):
        for a in self.accreditations:
            a.delete()
        for om in self.organisation_memberships:
            om.delete()
        for fd in self.financial_datas:
            fd.delete()

    def __repr__(self):
        return "<Representative(%s,%r)>" % (self.id, self.entity)


Entity.representative = db.relationship(Representative, uselist=False, backref=db.backref("entity"))