politikorama/app/model/stance.py

45 lines
1.4 KiB
Python

# encoding: utf-8
from app import admin, db
from app.model.model import Model, View
from app.model.matter import MatterModel
from app.model.representative import RepresentativeModel
class StanceModel(db.Model, Model):
__tablename__ = "stance"
id = db.Column(db.Integer, primary_key=True)
representative_id = db.Column(db.Integer, db.ForeignKey("representative.id"))
representative = db.relationship(
"RepresentativeModel", backref=db.backref("stances", lazy="dynamic")
)
matter_id = db.Column(db.Integer, db.ForeignKey("matter.id"), nullable=True)
matter = db.relationship(
"MatterModel", backref=db.backref("stances", lazy="dynamic")
)
date = db.Column(db.Date)
subject = db.Column(db.String(2000))
extract = db.Column(db.Text)
source_url = db.Column(db.String(2000))
active = db.Column(db.Boolean, default=False)
def __repr__(self):
return self.representative.name + " : " + self.extract[:50]
@property
def extract_html(self):
return "<p>" + self.extract.replace("\n", "</p><p>") + "</p>"
@property
def extract_chapo(self):
return " ".join((self.extract + " ")[:60].split(" ")[:-1])
class AdminView(View):
column_default_sort = ("date", False)
column_exclude_list = ["extract"]
column_filters = ["representative.name", "subject", "date"]
admin.add_view(AdminView(StanceModel, db.session, name="Stance", category="CRUD"))