Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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)
Пример #10
0
class IncidentStatus(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    status = db.Column(db.String(20))
Пример #11
0
class IncidentType(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(64))
Пример #12
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")