Ejemplo n.º 1
0
class BallotOption(Base):
    __tablename__ = 'ballot_option'
    uuid = C(UUIDType, server_default=func.gen_random_uuid(), primary_key=True)
    voting_uuid = C(UUIDType, FK('ballot_voting.uuid'), nullable=False)
    title = C(String)
    text = C(Text, nullable=False)

    voting = rel('BallotVoting', back_populates='options')
    votes = rel('Vote', back_populates='option')
Ejemplo n.º 2
0
class Vote(Base):
    __tablename__ = 'vote'
    uuid = C(UUIDType, server_default=func.gen_random_uuid(), primary_key=True)
    yes_no = C(Boolean)
    points = C(Integer, nullable=False)
    option_uuid = C(UUIDType, FK('ballot_option.uuid'), nullable=False)
    created_at = C(DateTime, nullable=False, server_default=func.now())
    confirmed = C(Boolean, nullable=False, server_default='false')

    token = rel(VoteToken, back_populates='vote')
    option = rel(BallotOption, back_populates='votes')
Ejemplo n.º 3
0
class OAuthToken(Base):
    __tablename__ = 'oauth_token'
    id = C(Integer, FK('users.id'), primary_key=True)
    user = rel("User", backref=bref("oauth_token", uselist=False))
    token = C(JSON)
    provider = C(Text)
    created_at = C(DateTime, nullable=False, server_default=func.now())
Ejemplo n.º 4
0
class VoteToken(Base):
    __tablename__ = 'vote_token'
    token = C(UUIDType,
              server_default=func.gen_random_uuid(),
              primary_key=True)
    auid = C(UUIDType, nullable=False)
    vote_uuid = C(UUIDType, FK('vote.uuid'), nullable=False)

    vote = rel('Vote', back_populates='token')
Ejemplo n.º 5
0
class BallotVoting(Base):
    __tablename__ = 'ballot_voting'
    uuid = C(UUIDType, server_default=func.gen_random_uuid(), primary_key=True)
    department = C(String, nullable=False)
    title = C(String)
    created_at = C(DateTime, nullable=False, server_default=func.now())
    starts_at = C(DateTime, nullable=False)
    ends_at = C(DateTime, nullable=False)

    options = rel(BallotOption, back_populates='voting')

    def votes_to_confirm(self, auid):
        return (object_session(self).query(
            VoteToken.token, Vote, BallotOption).filter(
                VoteToken.auid == auid, Vote.confirmed == False,
                VoteToken.vote_uuid == Vote.uuid,
                BallotOption.uuid == Vote.option_uuid,
                BallotOption.voting == self).order_by(Vote.yes_no.desc(),
                                                      Vote.points.desc()))