Exemplo n.º 1
0
class ElectionCandidatePollingStationVote(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    election_candidate_id = db.Column(db.Integer,
                                      db.ForeignKey('election_candidate.id'))
    polling_station_id = db.Column(db.Integer,
                                   db.ForeignKey('polling_station.id'))
    votes = db.Column(db.Integer)

    polling_station = db.relationship('PollingStation',
                                      backref=db.backref(
                                          "ecpollingstationvotes",
                                          cascade="all,delete-orphan"),
                                      lazy='joined')
    election_candidate = db.relationship('ElectionCandidate',
                                         backref=db.backref(
                                             "ecpollingstationvotes",
                                             cascade="all,delete-orphan",
                                             lazy='joined'))

    def __repr__(self):
        pass

    def __json__(self):
        return [self.polling_station_id, self.electioncandidate, self.votes]
Exemplo n.º 2
0
class User(db.Model):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.BigInteger, primary_key=True)
    username = db.Column(db.String)
    password = db.Column(db.String)
    nick = db.Column(db.String)
    status = db.Column(db.Integer)
Exemplo n.º 3
0
class Election(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_year = db.Column(db.Date)
    iteration_id = db.Column(db.Integer, db.ForeignKey('iteration.id'))
    election_type_id = db.Column(db.Integer, db.ForeignKey('election_type.id'))

    def __repr__(self):
        return "<Election %r >" % self.election_year.year
Exemplo n.º 4
0
class Base(db.Model):

    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True)
    date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
    date_modified = db.Column(db.DateTime,
                              default=db.func.current_timestamp(),
                              onupdate=db.func.current_timestamp())
Exemplo n.º 5
0
class Iteration(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String(12))

    elections = db.relationship('Election',
                                backref="iteration",
                                lazy='dynamic')

    def __repr__(self):
        return "<Iteration %r>" % self.description
Exemplo n.º 6
0
class Region(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    constituencies = db.relationship('Constituency',
                                     backref='region',
                                     lazy='dynamic')
    code = db.Column(db.String(4))

    def __repr__(self):
        return "<Region> %r  %r" % (self.name, self.code)
Exemplo n.º 7
0
class ElectionType(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(20), unique=True)
    elections = db.relationship('Election',
                                backref=db.backref('electiontype',
                                                   lazy="joined"),
                                lazy='dynamic')

    def __repr__(self):
        return " <ElectionType> %r" % self.type
Exemplo n.º 8
0
class PollingStation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40))
    constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id'))

    elections = db.relationship('ElectionPollingStation',
                                backref='pollinstation')

    def __repr__(self):
        return "<Constituency > %r" % self.name
Exemplo n.º 9
0
class Candidate(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(70))
    last_name = db.Column(db.String(140))
    avartar = db.Column(db.String(140))

    #elections a candidate has participated in
    elections = db.relationship('ElectionCandidate', backref='candidate')

    def __repr__(self):
        return "<Candidate>  %r %r" % (self.first_name, self.last_name)
Exemplo n.º 10
0
class ConstituencyRegister(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer, db.ForeignKey('election.id'))
    constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id'))
    number_of_registered_voters = db.Column(db.Integer)

    constituency = db.relationship('Constituency',
                                   backref=db.backref('election_registers',
                                                      lazy='joined'))
    election = db.relationship('Election',
                               backref=db.backref('constituencies_register',
                                                  lazy='joined'))
Exemplo n.º 11
0
class PollingStationRegister(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer, db.ForeignKey('election.id'))
    polling_station_id = db.Column(db.Integer,
                                   db.ForeignKey('polling_station.id'))
    number_of_registered_voters = db.Column(db.Integer)

    polling_station = db.relationship('PollingStation',
                                      backref=db.backref("elections_register"))
    election = db.relationship('Election',
                               backref=db.backref('polling_stations_register',
                                                  lazy='joined'))
Exemplo n.º 12
0
class Party(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(45))
    avartar = db.Column(db.String(70))
    code = db.Column(db.String(10))

    #election candidates
    election_candidates = db.relationship("ElectionCandidate",
                                          backref="party",
                                          lazy="dynamic")

    def __repr__(self):
        return "<Party>  %r (%r)" % (self.name, self.code)
Exemplo n.º 13
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True)
    password_hash = db.Column(db.String(128))
    role_id = db.Column(db.Integer, db.ForeignKey('role.id'))

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)

    def generate_auth_token(self, expiration=600):
        s = Serializer(current_app.config['SECRET_KEY'], expires=expiration)
        #s = Serializer(current_app.config['SECRET_KEY'],expires=expiration)

        return s.dumps({'id', self.id})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(current_app.config(['SECRET_KEY']))
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None

        except BadSignature:
            return None
        user = User.query.get(data['id'])
        return user

    #encrypted dictionary of user id with expiration time
    def generate_auth_token(self, expiration=600):
        s = Serializer(current_app.config['SECRET_KEY'], expires_in=600)
        return s.dumps({'id': self.id})

    #decode token and load user wit the id
    @staticmethod
    def verify_auth_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        #print current_app.config['SECRET_KEY']
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None
        except BadSignature:
            return None
        user = User.query.get(data['id'])
        return User
Exemplo n.º 14
0
class Constituency(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40))
    region_id = db.Column(db.Integer, db.ForeignKey('region.id'))

    #simple one to many relationship1
    polling_stations = db.relationship('PollingStation',
                                       backref='constituency',
                                       lazy='dynamic')

    #many to many relationship type1
    elections = db.relationship('ElectionConstituency', backref='constituency')

    def __repr__(self):
        return "<Constituence > %r" % self.name
Exemplo n.º 15
0
class ElectionCandidate(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer, db.ForeignKey('election.id'))
    candidate_id = db.Column(db.Integer, db.ForeignKey('candidate.id'))
    party_id = db.Column(db.Integer, db.ForeignKey('party.id'))

    #what the f**k is this? = elections and candidates for a particular election
    election = db.relationship('Election', backref="electioncandidates")

    def __repr__(self):
        return "<Election  %r party: %r Election: %r>" % (
            self.candidate, self.party, self.election)

    def __json__(self):

        return [self.candidate, self.election, self.party]
Exemplo n.º 16
0
class ElectionConstituency(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer, db.ForeignKey('election.id'))
    constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id'))
    number_of_registered_voters = db.Column(db.Integer)

    #many to many type1
    election = db.relationship('Election',
                               backref="constituency_electionconstituencies")

    def __repr__(self):
        return "<Election  %r : %r Constituency:  Total Registered Voters %r>" % (
            self.election, self.constituency, self.number_of_registered_voters)

    def __json__(self):

        return [self.candidate, self.election, self.party]
Exemplo n.º 17
0
class ElectionPollingStation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer, db.ForeignKey('election.id'))
    polling_station_id = db.Column(db.Integer,
                                   db.ForeignKey('polling_station.id'))
    number_of_registered_voters = db.Column(db.Integer)

    #what the f**k is this? = elections and candidates for a particular election
    election = db.relationship(
        'Election', backref="pollingstation_electionpollingstations")

    def __repr__(self):
        return "<ElectionPollingStation> Election:%r : %r Polling Station:  Total Registered Voters: %r>" % (
            self.election, self.polling_station, self.total_registered_voters)

    def __json__(self):

        return [
            self.election, self.pooling_station,
            self.number_of_registered_voters
        ]
Exemplo n.º 18
0
class Incident(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String(240))
    election_polling_station_id = db.Column(
        db.Integer, db.ForeignKey('election_polling_station.id'))
    election_constituency_id = db.Column(
        db.Integer, db.ForeignKey('election_constituency.id'))
    status_type_id = db.Column(db.Integer, db.ForeignKey('incident_status.id'))

    election_polling_station = db.relationship('ElectionPollingStation',
                                               backref=db.backref(
                                                   'incidents', lazy="joined"))

    election_constituency = db.relationship('ElectionConstituency',
                                            backref=db.backref('incidents', ))

    status = db.relationship('IncidentStatus', backref="incidents")

    def __repr__(self):
        return "<Incident>  %r constituency: %r status: %r, " % (
            self.description, self.election_constituency, self.status)
Exemplo n.º 19
0
class RailwayLine(db.Model):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.BigInteger, primary_key=True)
    line_name = db.Column(db.String)
    city = db.Column(db.String)
    city_code = db.Column(db.String)
    train_type = db.Column(db.Integer)
    mileage = db.Column(db.Float)
    gmt_modified = db.Column(db.DateTime)
    gmt_created = db.Column(db.DateTime)

    def __repr__(self):
        return 'RailwayLine: (%d %s %s %s %s %d %f %s %s)' % (
            self.id, self.line_name, self.city, self.city_code,
            self.train_type, self.mileage, self.gmt_created, self.gmt_modified)
Exemplo n.º 20
0
class ElectionCandidateConstituencyVote(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_candidate_id = db.Column(db.Integer,
                                      db.ForeignKey('election_candidate.id'))
    constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id'))
    votes = db.Column(db.Integer)

    constituency = db.relationship('Constituency',
                                   backref=db.backref(
                                       "ecconstituencyvotes",
                                       cascade="all,delete-orphan"))

    election_candidate = db.relationship('ElectionCandidate',
                                         backref=db.backref(
                                             "ecconstituencyvotes",
                                             cascade="all,delete-orphan"))

    def __repr__(self):
        return "Election: %r ,Candidate %r , Constituency %r votes %r" % (
            self.election_candidate.election,
            self.election_candidate.candidate, self.constituency, self.votes)

    def __json__(self):
        return [self.constituency, self.electioncandidate, self.votes]
Exemplo n.º 21
0
class Role(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    rolename = db.Column(db.String(64))

    users = db.relationship('User', backref="role")
Exemplo n.º 22
0
class IncidentStatus(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    status = db.Column(db.String(20))
Exemplo n.º 23
0
class IncidentType(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(64))