class Voter(db.Model): ''' Contains details of a voter ''' __tablename__ = 'Voter' voterId = db.Column(db.Integer, db.ForeignKey('ElectoralRoll.voterId'), nullable=False, primary_key=True) electionId = db.Column(db.Integer, db.ForeignKey('Elections.electionId'), nullable=False, primary_key=True) otp = db.Column(db.Integer, nullable=True) def __repr__(self): return 'Voter: < ' + self.voterId + ':' + self.electionId + ':' + self.otp + '>' def __init__(self, id, electionId, otp): self.voterId = id self.electionId = electionId self.otp = otp def as_dict(self): return { c.name: getattr(self, c.name) for c in self.__tablename__.columns }
class QuestionAttempt(db.Model): """Maps quiz attempt to quiz questions, mark if correct""" __tablename__ = 'question_attempts' id = db.Column(db.Integer, primary_key=True) question_id = db.Column(db.Integer, db.ForeignKey('questions.id', ondelete='cascade')) quiz_attempt_id = db.Column( db.Integer, db.ForeignKey('quiz_attempts.id', ondelete='cascade')) answer_given = db.Column(db.Text) correct = db.Column(db.Boolean)
class QuizAttempt(db.Model): """Quiz attempts by a user""" __tablename__ = 'quiz_attempts' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='cascade')) quiz_id = db.Column(db.Integer, db.ForeignKey('quizzes.id', ondelete='cascade')) timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) num_correct = db.Column(db.Integer) questions = db.relationship("QuestionAttempt", backref='quiz_attempt')
class Candidate(db.Model): ''' Info about candidates ''' __tablename__ = "Candidate" voterId = db.Column(db.Integer, db.ForeignKey('ElectoralRoll.voterId'), nullable=False) electionId = db.Column(db.Integer, db.ForeignKey('Elections.electionId'), nullable=False) name = db.Column(db.String(100), nullable=False) manifesto = db.Column(db.Text, nullable=True) uId = db.Column(db.Integer, primary_key=True, autoincrement=True) def __repr__(self): return 'Candidate: < ' + str(self.electionId) + ':' + str( self.uId) + ':' + str( self.voterId) + ':' + self.name + ':' + self.manifesto + '>' def __init__(self, electionId, voterId, name, manifesto): self.voterId = voterId self.name = name self.manifesto = manifesto self.electionId = electionId def as_dict(self): return { c.name: getattr(self, c.name) for c in self.__tablename__.columns } def get_uId(self): return self.uId def get_voterId(self): return self.voterId def get_name(self): return self.name def get_manifesto(self): return self.manifesto
class QuizQuestion(db.Model): """Map quiz questions to a quiz""" __tablename__ = 'quiz_questions' id = db.Column( db.Integer, primary_key=True ) question_id = db.Column( db.Integer, db.ForeignKey('questions.id', ondelete='cascade') ) quiz_id = db.Column( db.Integer, db.ForeignKey('quizzes.id', ondelete='cascade') )
class Coordinator(db.Model): __tablename__ = 'Coordinator' userId = db.Column(db.String(10), db.ForeignKey('User.pecfestId'), primary_key=True) password = db.Column(db.String(10), nullable=False) level = db.Column(db.String(10), nullable=False) def __str__(self): return "[" + self.userId + "] " + self.level
class EventRegistration(db.Model): __tablename__ = 'Registration' id = db.Column(db.Integer, primary_key=True) eventId = db.Column(db.Integer, db.ForeignKey('Event.eventId'), nullable=False) memberId = db.Column(db.String(10), db.ForeignKey('User.pecfestId'), nullable=False) leaderId = db.Column(db.String(10), db.ForeignKey('User.pecfestId'), nullable=False) def as_dict(self): return { c.name: getattr(self, c.name) for c in self.__tablename__.columns }
class Notifications(db.Model): __tablename__ = 'Notifications' notificationId = db.Column(db.String(10), primary_key=True) notificationTitle = db.Column(db.String(100), nullable=False) notificationDetails = db.Column(db.String(4096), nullable=True) eventId = db.Column(db.Integer, db.ForeignKey('Event.eventId'), nullable=False) notificationType = db.Column(db.String(10), nullable=False) notif_rel = relationship('Event')
class Vote(db.Model): ''' Contains info about the Vote count ''' __tablename__ = "Vote" electionId = db.Column ( db.Integer, db.ForeignKey('Elections.electionId'),nullable=False, primary_key=True) uId = db.Column ( db.Integer,db.ForeignKey('Candidate.uId'), nullable=False , primary_key=True) count = db.Column (db.Integer, nullable=False) def __repr__(self): return 'Vote: < ' + self.electionId + ':' + self.uId + ':' + self.count + '>' def __init__(self, uId, electionId, count): self.uId = uId self.electionId = electionId self.count = 0 def as_dict(self): return { c.name : getattr(self, c.name) for c in self.__tablename__.columns}