Ejemplo n.º 1
0
class Cake(BaseModel):
    """
    Cake class that defines how cake object are kept in the database.
    """
    __tablename__ = 'exampletest'
    ex1 = db.Column(db.String(40), unique=False)
    ex2 = db.Column(db.String(40), unique=False)
    ex3 = db.Column(db.String(50), unique=False)
    ex4 = db.Column(db.Date)
    ex5 = db.Column(db.Time)

    def __init__(self, ex1, ex2, ex3, ex4, ex5):
        self.ex1 = ex1
        self.ex2 = ex2
        self.ex3 = ex3
        self.ex4 = ex4
        self.ex5 = ex5

    def as_dict(self):
        Cake_dict = {}
        for C in self.__table__.columns:
            Cake_dict[C.ex3] = getattr(self, C.ex3)
        return Cake_dict

    def __repr__(self):
        return "<Cake %s>" % self.ex3
Ejemplo n.º 2
0
class Score(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    student_id = db.Column(db.Integer, db.ForeignKey(Student.id))
    assignment_id = db.Column(db.Integer, db.ForeignKey(Assignment.id))
    organization_id = db.Column(db.Integer, db.ForeignKey(Organization.id))
    task_id = db.Column(db.Integer, db.ForeignKey(Task.id))
    review_type = db.Column(db.Integer, unique=False)
    score = db.Column(db.Float, unique=False)
    max_score = db.Column(db.Float, unique=False)

    def __init__(self, student_id, assignment_id, organization_id, task_id,
                 review_type, score, max_score):
        self.student_id = student_id
        self.assignment_id = assignment_id
        self.organization_id = organization_id
        self.task_id = task_id
        self.review_type = review_type
        self.score = score
        self.max_score = max_score

    def as_dict(self):
        score_dict = {}
        for c in self.__table__.columns:
            score_dict[c.name] = getattr(self, c.name)
        return score_dict

    def __repr__(self):
        return '<Score %r>' % self.id
Ejemplo n.º 3
0
class AssignmentType(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), unique=False)

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

    def as_dict(self):
        assign_t_dict = {}
        for c in self.__table__.columns:
            assign_t_dict[c.name] = getattr(self, self.name)
        return assign_t_dict

    def __repr__(self):
        return '<AssignmentType %r>' % self.name
Ejemplo n.º 4
0
class Task(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=False)
    assignment_id = db.Column(db.Integer, db.ForeignKey(Assignment.id))

    def __init__(self, name, assignment_id):
        self.name = name
        self.assignment_id = assignment_id

    def as_dict(self):
        task_dict = {}
        for c in self.__table__.columns:
            task_dict[c.name] = getattr(self, c.name)
        return task_dict

    def __repr__(self):
        return '<Task %r>' % self.id
Ejemplo n.º 5
0
class Assignment(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True)
    type = db.Column(db.Integer, db.ForeignKey(AssignmentType.id))

    def __init__(self, name, type):
        self.name = name
        self.type = type

    def as_dict(self):
        assign_dict = {}
        for c in self.__table__.columns:
            assign_dict[c.name] = getattr(self, c.name)
        return assign_dict

    def __repr__(self):
        return '<Assignment %r>' % self.name
Ejemplo n.º 6
0
class Organization(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    address = db.Column(db.String(255), unique=False)

    def __init__(self, name, address):
        self.name = name
        self.address = address

    def as_dict(self):
        org_dict = {}
        for c in self.__table__.columns:
            org_dict[c.name] = getattr(self, c.name)
        return org_dict

    def __repr__(self):
        return '<Organization %r>' % self.name
Ejemplo n.º 7
0
class Cake(BaseModel):
    """
    Cake class that defines how cake object are kept in the database.
    """
    id = db.Column(db.Integer, primary_key=True)
    cakename = db.Column(db.String(80), unique=True)
    bakername = db.Column(db.String(120), unique=False)
    price = db.Column(db.Float)

    def __init__(self, cakename, bakername, price):
        self.cakename = cakename
        self.bakername = bakername
        self.price = price

    def as_dict(self):
        #return {c.name: getattr(self, c.name) for c in self.__table__.columns} # Python 2.6 does not support this.
        cake_dict = {}
        for c in self.__table__.columns:
            cake_dict[c.name] = getattr(self, c.name)
        return cake_dict

    def __repr__(self):
        return '<Cake %r>' % self.cakename
Ejemplo n.º 8
0
class Student(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    fname = db.Column(db.String(100), unique=False)
    lname = db.Column(db.String(100), unique=False)
    organization_id = db.Column(db.Integer, primary_key=True)
    assignment_id = db.Column(db.Integer, primary_key=True)
    reputation = db.Column(db.Float, unique=False)

    def __init__(self, fname, lname, org_id, assign_id, reputation):
        self.fname = fname
        self.lname = lname
        self.organization_id = org_id
        self.assign_id = assign_id
        self.reputation = reputation

    def as_dict(self):
        org_dict = {}
        for c in self.__table__.columns:
            org_dict[c.name] = getattr(self, c.name)
        return org_dict

    def __repr__(self):
        return '<Student ID : %r Name : %r>' % (self.id,
                                                self.fname + ' ' + self.lname)