class Stimme(db.Model, ModelCore): __tablename__ = 'stimme' entscheidung = db.Column(db.Unicode()) person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=True) abstimmung_id = db.Column(db.Integer, db.ForeignKey('abstimmung.id'), nullable=True) def to_ref(self): return { 'id': self.id, 'abstimmung': self.abstimmung.thema, 'person': self.person.to_ref(), } def to_dict(self): data = self.to_ref() data.update({ 'abstimmung': self.abstimmung.to_ref(), 'person': self.person.to_ref(), 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Beitrag(db.Model, ModelCore): __tablename__ = 'beitrag' seite = db.Column(db.Unicode()) art = db.Column(db.Unicode()) person_id = db.Column(db.Integer, db.ForeignKey('person.id')) rolle_id = db.Column(db.Integer, db.ForeignKey('rolle.id')) position_id = db.Column(db.Integer, db.ForeignKey('position.id')) def to_ref(self): return { 'id': self.id, 'seite': self.seite, 'art': self.art, 'position': self.position.id, 'rolle': self.rolle.id if self.rolle else None, 'person': self.person.id if self.person else None } def to_dict(self): data = self.to_ref() data.update({ 'person': self.person.to_ref() if self.person else None, 'rolle': self.rolle.to_ref() if self.rolle else None, 'position': self.position.to_ref(), 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Zuweisung(db.Model, ModelCore): __tablename__ = 'zuweisung' text = db.Column(db.Unicode()) federfuehrung = db.Column(db.Boolean()) gremium_id = db.Column(db.Integer, db.ForeignKey('gremium.id')) position_id = db.Column(db.Integer, db.ForeignKey('position.id')) def to_ref(self): return { 'id': self.id, 'text': self.text, 'federfuehrung': self.federfuehrung, 'gremium': self.gremium.key if self.gremium else None, 'position': self.position.id if self.position else None } def to_dict(self): data = self.to_ref() data.update({ 'gremium': self.gremium.to_ref(), 'position': self.position.to_ref(), 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Position(db.Model, ModelCore): __tablename__ = 'position' key = db.Column(db.Unicode()) zuordnung = db.Column(db.Unicode()) urheber = db.Column(db.Unicode()) fundstelle = db.Column(db.Unicode()) fundstelle_url = db.Column(db.Unicode()) date = db.Column(db.DateTime()) quelle = db.Column(db.Unicode()) typ = db.Column(db.Unicode()) ablauf_id = db.Column(db.Integer, db.ForeignKey('ablauf.id')) dokument_id = db.Column(db.Integer, db.ForeignKey('dokument.id')) debatte_id = db.Column(db.Integer, db.ForeignKey('debatte.id'), nullable=True) zuweisungen = db.relationship('Zuweisung', backref='position', lazy='dynamic') beschluesse = db.relationship('Beschluss', backref='position', lazy='dynamic') beitraege = db.relationship('Beitrag', lazy='dynamic', backref='position') def to_ref(self): return { 'id': self.id, 'key': self.key, 'urheber': self.urheber, 'fundstelle': self.fundstelle, 'wahlperiode': self.ablauf.wahlperiode, 'ablauf': self.ablauf.key } def to_dict(self): data = self.to_ref() del data['wahlperiode'] data.update({ 'zuordnung': self.zuordnung, 'fundstelle_url': self.fundstelle_url, 'date': self.date, 'quelle': self.quelle, 'typ': self.typ, 'ablauf': self.ablauf.to_ref(), 'debatte': self.debatte.to_ref() if self.debatte else None, 'dokument': self.dokument.to_ref() if self.dokument else None, 'zuweisungen': [z.to_ref() for z in self.zuweisungen], 'beschluesse': [b.to_ref() for b in self.beschluesse], 'beitraege': [b.to_dict() for b in self.beitraege], 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Gremium(db.Model, ModelCore): __tablename__ = 'gremium' vorsitz_id = db.Column(db.Integer, db.ForeignKey('person.id')) stellv_vorsitz_id = db.Column(db.Integer, db.ForeignKey('person.id')) source_url = db.Column(db.Unicode) rss_url = db.Column(db.Unicode) name = db.Column(db.Unicode) url = db.Column(db.Unicode) key = db.Column(db.Unicode) typ = db.Column(db.Unicode) aufgabe = db.Column(db.Unicode) image_url = db.Column(db.Unicode) image_copyright = db.Column(db.Unicode) zuweisungen = db.relationship('Zuweisung', backref='gremium', lazy='dynamic') def to_dict(self): return { 'id': self.id, 'vorsitz': self.vorsitz.to_ref() if \ self.vorsitz else None, 'stellv_vorsitz': self.stellv_vorsitz.to_ref() if \ self.stellv_vorsitz else None, 'source_url': self.source_url, 'rss_url': self.rss_url, 'name': self.name, 'url': self.url, 'key': self.key, 'typ': self.typ, 'aufgabe': self.aufgabe, 'image_url': self.image_url, 'image_copyright': self.image_copyright, 'created_at': self.created_at, 'updated_at': self.updated_at, 'obleute': [m.to_ref() for m in self.obleute], 'mitglieder': [m.to_ref() for m in self.mitglieder], 'stellvertreter': [m.to_ref() for m in self.stellvertreter], } def to_ref(self): return { 'id': self.id, 'source_url': self.source_url, 'name': self.name, 'key': self.key }
class Beschluss(db.Model, ModelCore): __tablename__ = 'beschluss' dokument_text = db.Column(db.Unicode()) tenor = db.Column(db.Unicode()) seite = db.Column(db.Unicode()) position_id = db.Column(db.Integer, db.ForeignKey('position.id')) def to_ref(self): return { 'id': self.id, 'dokument_text': self.dokument_text, 'tenor': self.tenor, 'seite': self.seite, 'position': self.position.id } def to_dict(self): data = self.to_ref() data.update({ 'dokument': self.dokument.to_ref(), 'position': self.position.to_ref(), 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Referenz(db.Model, ModelCore): __tablename__ = 'referenz' seiten = db.Column(db.Unicode()) text = db.Column(db.Unicode()) dokument_id = db.Column(db.Integer, db.ForeignKey('dokument.id')) ablaeufe = db.relationship('Ablauf', secondary=referenzen, backref=db.backref('referenzen', lazy='dynamic')) def to_ref(self): return { 'id': self.id, 'seiten': self.seiten, 'text': self.text, 'dokument': self.dokument.id } def to_dict(self): data = self.to_ref() data.update({ 'dokument': self.dokument.to_ref(), 'ablaeufe': [a.to_ref() for a in self.ablaeufe], 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Rede(db.Model, ModelCore): __tablename__ = 'rede' webtv_id = db.Column(db.Integer()) sitzung_id = db.Column(db.Integer, db.ForeignKey('sitzung.id')) debatte_id = db.Column(db.Integer, db.ForeignKey('debatte.id')) redner_id = db.Column(db.Integer, db.ForeignKey('person.id')) zitate = db.relationship('Zitat', backref='rede', lazy='dynamic', order_by='Zitat.sequenz.asc()') @property def titel(self): return "%s: %s" % (self.debatte.titel, self.redner.name) @property def text(self): zitat = self.zitate.first() return zitat.text def to_ref(self): return { 'id': self.id, 'webtv_id': self.webtv_id, 'redner': self.redner.fingerprint if self.redner else None, } def to_dict(self): data = self.to_ref() data.update({ 'sitzung': self.sitzung.to_ref() if self.sitzung else None, 'debatte': self.debatte.to_ref() if self.debatte else None, 'created_at': self.created_at, 'updated_at': self.updated_at }) return data def to_index(self): data = super(Rede, self).to_index() data['sitzung'] = self.sitzung.to_dict() data['debatte'] = self.debatte.to_dict() data['zitate'] = [z.to_dict() for z in self.zitate] return data
class Postleitzahl(db.Model): __tablename__ = 'postleitzahl' plz = db.Column(db.Unicode, primary_key=True) wahlkreis_id = db.Column(db.Integer, db.ForeignKey('wahlkreis.id')) created_at = db.Column(db.DateTime, default=datetime.utcnow) updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class Zitat(db.Model, ModelCore): __tablename__ = 'zitat' sequenz = db.Column(db.Integer()) sprecher = db.Column(db.Unicode()) text = db.Column(db.Unicode()) typ = db.Column(db.Unicode()) source_url = db.Column(db.Unicode()) person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=True) sitzung_id = db.Column(db.Integer, db.ForeignKey('sitzung.id')) debatte_id = db.Column(db.Integer, db.ForeignKey('debatte.id')) rede_id = db.Column(db.Integer, db.ForeignKey('rede.id')) def to_ref(self): return { 'id': self.id, 'sequenz': self.sequenz, 'sprecher': self.sprecher, 'typ': self.typ, } def to_dict(self): data = self.to_ref() data.update({ 'text': self.text, 'source_url': self.source_url, 'sitzung': self.sitzung.to_ref() if self.sitzung else None, 'person': self.person.to_ref() if self.person else None, 'debatte': self.debatte.to_ref() if self.debatte else None, 'rede': self.rede.to_ref() if self.rede else None, 'created_at': self.created_at, 'updated_at': self.updated_at }) return data def to_index(self): data = super(Zitat, self).to_index() data['debatte'] = self.debatte.to_dict() data['sitzung'] = self.sitzung.to_dict() data['rede'] = self.rede.to_dict() return data
class Rolle(db.Model, ModelCore): __tablename__ = 'rolle' person_id = db.Column(db.Integer, db.ForeignKey('person.id')) mdb_id = db.Column(db.Unicode) status = db.Column(db.Unicode) funktion = db.Column(db.Unicode) fraktion = db.Column(db.Unicode) gewaehlt = db.Column(db.Unicode) ressort = db.Column(db.Unicode) land = db.Column(db.Unicode) austritt = db.Column(db.DateTime) wahlkreis_id = db.Column(db.Integer, db.ForeignKey('wahlkreis.id')) beitraege = db.relationship('Beitrag', backref='rolle', lazy='dynamic') def to_ref(self): return { 'id': self.id, 'mdb_id': self.mdb_id, 'status': self.status, 'funktion': self.funktion, 'fraktion': self.fraktion, 'ressort': self.ressort, 'land': self.land, 'wahlkreis': self.wahlkreis.to_ref() if self.wahlkreis else None, } def to_dict(self): data = self.to_ref() data.update({ 'person': self.person.to_ref(), 'gewaehlt': self.gewaehlt, 'austritt': self.austritt, 'created_at': self.created_at, 'updated_at': self.updated_at }) return data
class Debatte(db.Model, ModelCore): __tablename__ = 'debatte' tops = db.Column(db.Unicode()) nummer = db.Column(db.Integer()) titel = db.Column(db.Unicode()) text = db.Column(db.Unicode()) sitzung_id = db.Column(db.Integer, db.ForeignKey('sitzung.id')) zitate = db.relationship('Zitat', backref='debatte', lazy='dynamic', order_by='Zitat.sequenz.asc()') reden = db.relationship('Rede', backref='debatte', lazy='dynamic', order_by='Rede.webtv_id.asc()') positionen = db.relationship('Position', backref='debatte', lazy='dynamic') def to_ref(self): return {'id': self.id, 'nummer': self.nummer, 'titel': self.titel} def to_dict(self): data = self.to_ref() data.update({ 'sitzung': self.sitzung.to_ref() if self.sitzung else None, 'text': self.text, 'positionen': [p.to_ref() for p in self.positionen], 'created_at': self.created_at, 'updated_at': self.updated_at }) return data def to_index(self): data = super(Debatte, self).to_index() data['sitzung'] = self.sitzung.to_dict() return data
from datetime import datetime from offenesparlament.core import db from offenesparlament.model.util import ModelCore beschluesse_dokumente = db.Table( 'beschluesse_dokumente', db.Column('dokument_id', db.Integer, db.ForeignKey('beschluss.id')), db.Column('beschluss_id', db.Integer, db.ForeignKey('dokument.id'))) class Dokument(db.Model, ModelCore): __tablename__ = 'dokument' nummer = db.Column(db.Unicode()) hrsg = db.Column(db.Unicode()) typ = db.Column(db.Unicode()) link = db.Column(db.Unicode()) referenzen = db.relationship('Referenz', backref='dokument', lazy='dynamic') positionen = db.relationship('Position', backref='dokument', lazy='dynamic') beschluesse = db.relationship('Beschluss', secondary=beschluesse_dokumente, backref=db.backref('dokumente', lazy='dynamic'))
from offenesparlament.core import db from offenesparlament.model.util import ModelCore referenzen = db.Table( 'referenzen', db.Column('referenz_id', db.Integer, db.ForeignKey('referenz.id')), db.Column('ablauf_id', db.Integer, db.ForeignKey('ablauf.id'))) class Referenz(db.Model, ModelCore): __tablename__ = 'referenz' seiten = db.Column(db.Unicode()) text = db.Column(db.Unicode()) dokument_id = db.Column(db.Integer, db.ForeignKey('dokument.id')) ablaeufe = db.relationship('Ablauf', secondary=referenzen, backref=db.backref('referenzen', lazy='dynamic')) def to_ref(self): return { 'id': self.id, 'seiten': self.seiten, 'text': self.text, 'dokument': self.dokument.id } def to_dict(self): data = self.to_ref()
from offenesparlament.core import db schlagworte = db.Table('schlagworte', db.Column('schlagwort_id', db.Integer, db.ForeignKey('schlagwort.id')), db.Column('ablauf_id', db.Integer, db.ForeignKey('ablauf.id')) ) class Schlagwort(db.Model): __tablename__ = 'schlagwort' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode())
import re from datetime import datetime from collections import OrderedDict from offenesparlament.core import db from offenesparlament.model.util import ModelCore obleute = db.Table('obleute', db.Column('gremium_id', db.Integer, db.ForeignKey('gremium.id')), db.Column('person_id', db.Integer, db.ForeignKey('person.id')) ) mitglieder = db.Table('mitglieder', db.Column('gremium_id', db.Integer, db.ForeignKey('gremium.id')), db.Column('person_id', db.Integer, db.ForeignKey('person.id')) ) stellvertreter = db.Table('stellvertreter', db.Column('gremium_id', db.Integer, db.ForeignKey('gremium.id')), db.Column('person_id', db.Integer, db.ForeignKey('person.id')) ) class Person(db.Model, ModelCore): __tablename__ = 'person' slug = db.Column(db.Unicode) fingerprint = db.Column(db.Unicode) source_url = db.Column(db.Unicode) mdb_id = db.Column(db.Integer)