class Voter(db.Model): __tablename__ = "voter" __table_args__ = (UniqueConstraint("ballot_id", "person_id"),) id = db.Column(db.Integer, primary_key=True) ballot_id = db.Column(db.Integer, db.ForeignKey('ballot.id')) name = db.Column(db.Unicode(100)) email = db.Column(db.Unicode(100)) person_id = db.Column(db.Integer) voted_at = db.Column(db.DateTime) remote_addr = db.Column(db.String(50)) user_agent = db.Column(db.String(500))
class Abstainer(db.Model): __tablename__ = "abstainer" __table_args__ = (UniqueConstraint("ballot_id", "person_id"),) id = db.Column(db.Integer, primary_key=True) ballot_id = db.Column(db.Integer, db.ForeignKey('ballot.id')) created_at = db.Column(db.DateTime) name = db.Column(db.Unicode(100)) email = db.Column(db.Unicode(100)) person_id = db.Column(db.Integer) hash_salt = db.Column(db.Unicode(100)) hash_digest = db.Column(db.Unicode(100)) confirmation_sent = db.Column(db.Boolean, nullable=False, default=False)
class BallotOption(db.Model): __tablename__ = "ballot_option" id = db.Column(db.Integer, primary_key=True) ballot_id = db.Column(db.Integer, db.ForeignKey('ballot.id')) title = db.Column(db.Unicode(500)) user_id = db.Column(db.Integer, nullable=True) votes = db.relationship('Vote', backref='ballot_option', lazy='dynamic', order_by="Vote.hash_digest")
class Connection(db.Model): __tablename__ = "connection" id = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(30), unique=True) logged_in = db.Column(db.DateTime) last_click = db.Column(db.DateTime, index=True) remote_addr = db.Column(db.String(50)) user_id = db.Column(db.Integer) name = db.Column(db.Unicode(100)) profile = db.Column(db.UnicodeText) valid = db.Column(db.Boolean, nullable=False, default=True) jwt = db.Column(db.Text)
class Vote(db.Model): __tablename__ = "vote" id = db.Column(db.Integer, primary_key=True) ballot_option_id = db.Column(db.Integer, db.ForeignKey('ballot_option.id')) value = db.Column(db.Integer) hash_digest = db.Column(db.Unicode(100))
class Ballot(db.Model): __tablename__ = "ballot" TYPES = [ ("ELECTION", u'Volba'), ("VOTING", u'Hlasování') ] id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(100), nullable=False, info={'label': u'Název'}) description = db.Column(db.UnicodeText, nullable=True, info={'label': u'Popis'}) begin_at = db.Column(db.DateTime, nullable=False, info={'label': u'Začátek'}) finish_at = db.Column(db.DateTime, nullable=False, info={'label': u'Konec'}) approved = db.Column(db.Boolean, nullable=False, default=False, info={'label': u'Schváleno'}) cancelled = db.Column(db.Boolean, nullable=False, default=False, info={'label': u'Zrušeno'}) type = db.Column(ChoiceType(TYPES, impl=db.String(20)), nullable=False, info={'label': u'Druh'}) unit = db.Column( ChoiceType(UNITS, impl=db.String(20)), nullable=False, info={'label': u'Jednotka', 'form_field_class': SelectField}) supporters_too = db.Column(db.Boolean, nullable=False, default=False, info={'label': u'Také příznivci'}) max_votes = db.Column(db.Integer, default=1, nullable=False, info={'label': u'Max. hlasů'}) options = db.relationship('BallotOption', backref='ballot', lazy='select', order_by="BallotOption.title") voters = db.relationship('Voter', backref='ballot', lazy='dynamic') abstainers = db.relationship('Abstainer', backref='ballot', lazy='dynamic', order_by="Abstainer.hash_digest") protocols = db.relationship('BallotProtocol', backref='ballot', lazy='dynamic', order_by="desc(BallotProtocol.created_at)") candidate_self_signup = db.Column( db.Boolean, nullable=False, default=True, info={'label': u'Kandidáti se přihlašují sami'}) candidate_signup_from = db.Column( db.DateTime, nullable=True, info={'label': u'Přihlašování kandidátů od'}) candidate_signup_until = db.Column( db.DateTime, nullable=False, info={'label': u'Přihlašování kandidátů do'}) quorum = db.Column(db.Integer, nullable=True, info={'label': u'Kvórum'}) @property def in_time_progress(self): now = datetime.datetime.now() return self.begin_at < now < self.finish_at @property def in_time_finished(self): now = datetime.datetime.now() return self.finish_at < now @property def in_progress(self): return self.approved and not self.cancelled and self.in_time_progress @property def is_finished(self): return self.approved and not self.cancelled and self.in_time_finished @property def in_time_candidate_signup(self): now = datetime.datetime.now() return self.candidate_self_signup and \ (self.candidate_signup_from is None or self.candidate_signup_from <= now) and \ self.candidate_signup_until > now @property def is_election(self): return self.type == "ELECTION" @property def is_yes_no(self): return len(self.options) <= self.max_votes @property def method(self): if self.is_yes_no: return u"PRO NÁVRH / PROTI NÁVRHU" return u"podle pořadí počtu získaných hlasů" @property def approved_protocol(self): return self.protocols.filter_by(approved=True).first() @property def count_voted(self): return self.voters.filter(Voter.voted_at < datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)).count() @property def mail_greeting(self): return UNITS_GREETING.get(self.unit.code, "") @property def mail_name(self): return self.name[0].lower()+self.name[1:] @property def type_short(self): return self.type.value[0]