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]
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
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'))
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'))
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]
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]
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
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)
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 ]
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
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
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]