Exemple #1
0
class Pacient(db.Model):
    __tablename__ = 'Pacient'

    id = db.Column(db.Integer, primary_key=True)
    blood_type = db.Column(db.String(5))
    weight = db.Column(db.Float())
    deseases = db.Column(db.String(50))

    def __init__(self, blood_type, weight, deseases):
        self.blood_type = blood_type
        self.weight = weight
        self.deseases = deseases

    def __repr__(self):
        """Return representation of pacient object"""
        return "<Pacient {}>".format(self)

    def to_dict(self):
        """Convert pacient object into dictionary"""
        return dict([
            ("blood_type", self.blood_type),
            ("weight", self.weight),
            ("deseases", self.deseases),
        ])

    def save(self):
        """Saves object into database"""
        try:
            db.session.add(self)
            db.session.commit()
            logger.debug("Saved {}.".format(repr(self)))
        except Exception, e:
            logger.error("Error on saving {} (ROLLBACK): {}".format(
                self.__class__.__name__, e))
            db.session.remove()
Exemple #2
0
class Doctor(db.Model):
    __tablename__ = 'Doctor'

    id = db.Column(db.Integer, primary_key=True)
    speciality = db.Column(db.String(50))

    def __init__(self, speciality):
        self.speciality = speciality

    def __repr__(self):
        """Return representation of doctor object"""
        return "<Doctor {}>".format(self)

    def to_dict(self):
        """Convert doctor object into dictionary"""
        return dict([
            ("speciality", self.speciality),
        ])

    def save(self):
        """Saves object into database"""
        try:
            db.session.add(self)
            db.session.commit()
            logger.debug("Saved {}.".format(repr(self)))
        except Exception, e:
            logger.error("Error on saving {} (ROLLBACK): {}".format(
                self.__class__.__name__, e))
            db.session.remove()
Exemple #3
0
class Candidate(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer,
                            db.ForeignKey('election.id'),
                            nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    votes = db.Column(db.Integer, nullable=False, default=0)

    def __repr__(self):
        return f"Candidate:('{self.election_id}', '{self.user_id}','{self.votes}')"
Exemple #4
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), nullable=False, unique=True)
    password = db.Column(db.String(60), nullable=False)
    voters = db.relationship('Voter', backref='user', lazy=True)
    organizers = db.relationship('Election', backref='organizer', lazy=True)
    candidates = db.relationship('Candidate', backref='candidate', lazy=True)

    def __repr__(self):
        return f"User:('{self.email}')"
Exemple #5
0
class Appointment(db.Model):
    __tablename__ = 'Appointment'

    pacient_id = db.Column(
        db.ForeignKey("central_server.models.pacient.Pacient"),
        primary_key=True)
    doctor_id = db.Column(
        db.ForeignKey("central_server.models.doctor.Doctor"),
        primary_key=True)
    date = db.Column(db.Date(), primary_key=True)
    time = db.Column(db.String(7))
    office = db.Column(db.String(50))

    def __init__(self, pacient_id, doctor_id, date, time, office):
        self.pacient_id = pacient_id
        self.doctor_id = doctor_id
        self.date = date
        self.time = time
        self.office = office

    def __repr__(self):
        """Return representation of appointment object"""
        return "<Appointment {}>".format(self)

    def to_dict(self):
        """Convert appointment object into dictionary"""
        return dict([
            ("pacient_id", self.pacient_id),
            ("doctor_id", self.doctor_id),
            ("date", self.date),
            ("time", self.time),
            ("office", self.office),
        ])

    def save(self):
        """Saves object into database"""
        try:
            db.session.add(self)
            db.session.commit()
            logger.debug("Saved {}.".format(repr(self)))
        except Exception, e:
            logger.error("Error on saving {} (ROLLBACK): {}".format(
                self.__class__.__name__, e))
            db.session.remove()
Exemple #6
0
class Election(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    organizer_id = db.Column(db.Integer,
                             db.ForeignKey('user.id'),
                             nullable=False)
    started = db.Column(db.Boolean, nullable=False, default=False)
    ended = db.Column(db.Boolean, nullable=False, default=False)
    public_key = db.Column(db.String(1024), nullable=False)
    private_key_p = db.Column(db.String(1024), nullable=False)
    private_key_q = db.Column(db.String(1024), nullable=False)
    voters = db.relationship('Voter', backref='election', lazy=True)
    candidates = db.relationship('Candidate', backref='election', lazy=True)

    def __repr__(self):
        return f"Election:('{self.title}', '{self.organizer_id}', '{self.started}', '{self.ended}' '{self.public_key}')"
Exemple #7
0
class User(UserMixin, db.Model):
    __tablename__ = 'User'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), unique=True)
    password = db.Column(db.String(128))
    email = db.Column(db.String(128), unique=True)
    first_name = db.Column(db.String(128))
    last_name = db.Column(db.String(128))
    birth_date = db.Column(db.Date())

    def __init__(self,
                 username,
                 password,
                 email,
                 first_name=None,
                 last_name=None,
                 birth_date=None):
        self.username = username
        self.password = password
        self.email = email
        self.first_name = first_name
        self.last_name = last_name
        self.birth_date = birth_date

    @property
    def is_admin(self):
        """Wrapper to check if user is admin"""
        return self.username in ['admin', 'abc']

    def __repr__(self):
        """Return representation of user object"""
        return "<User {}>".format(self.username)

    def to_dict(self):
        """Convert user object into dictionary"""
        return dict([("username", self.username), ("password", self.password),
                     ("is_admin", self.is_admin), ("email", self.email),
                     ("first_name", self.first_name),
                     ("last_name", self.last_name),
                     ("birth_date", self.birth_date)])

    def save(self):
        """Saves object into database"""
        try:
            db.session.add(self)
            db.session.commit()
            logger.debug("Saved {}.".format(repr(self)))
        except Exception, e:
            logger.error("Error on saving {} (ROLLBACK): {}".format(
                self.__class__.__name__, e))
            db.session.remove()
Exemple #8
0
class Voter(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    election_id = db.Column(db.Integer,
                            db.ForeignKey('election.id'),
                            nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    voted = db.Column(db.Boolean, nullable=False)
    authentication_token = db.Column(db.String(128), nullable=False)
    verified = db.Column(db.Integer, nullable=False, default=False)
    vote_exists = db.Column(db.Integer, nullable=False, default=False)

    def __repr__(self):
        return f"Voter:('{self.election_id}', '{self.user_id}', '{self.voted}', '{self.authentication_token}')"
Exemple #9
0
class VotingMachine(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    port = db.Column(db.Integer, nullable=False)
    status = db.Column(db.Boolean, nullable=False)
    last_checked = db.Column(db.DateTime, nullable=False)