Beispiel #1
0
class User_question(db.Model):
    __tablename__ = 'user_question'
    question_id = db.Column(db.Integer,
                            db.ForeignKey('question.id'),
                            primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    record_url = db.Column(db.String(140))
    record_id = db.Column(db.String(140))
    record_title = db.Column(db.String(140))
    update_time = db.Column(db.DateTime, default=datetime.now)
    question = db.relationship("Question", back_populates="users")
    user = db.relationship("User", back_populates="questions")

    @staticmethod
    def add_user_question(user, question, record_url, record_id, record_title):
        user_has_question = User_question(user=user,
                                          question=question,
                                          record_url=record_url,
                                          record_id=record_id,
                                          record_title=record_title)
        db.session.add(user_has_question)
        db.session.commit()

    def add(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def update(self):
        db.session.commit()
Beispiel #2
0
class Voice(db.Model, Serializer):
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(128))
    sentence = db.Column(db.String(256))
    duration = db.Column(db.Interval)
    script_id = db.Column(db.Integer, db.ForeignKey('script.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return '<Voice {}>'.format(str(self.id) + ":" + self.filename)

    def serialize(self):
        return Serializer.serialize(self)
Beispiel #3
0
class Question(db.Model):
    __tablename__ = 'question'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    question_name = db.Column(db.String(64))
    description = db.Column(db.String(200))
    task_id = db.Column(db.Integer, db.ForeignKey('task.id'))
    task = db.relationship("Task", back_populates="questions")
    users = db.relationship("User_question", back_populates="question")

    def __repr__(self):
        return 'id={}, question_name={},description={}'.format(
            self.id, self.question_name, self.description)

    def add(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        user_quesions = db.session.query(User_question).filter(
            User_question.question_id == self.id)
        for user_quesion in user_quesions:
            # print(user_quesion.question_id)
            user_quesion.delete()
        db.session.delete(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def add_question2task(self, task):
        self.task_id = task.id
        db.session.commit()
Beispiel #4
0
class User_task(db.Model):
    __tablename__ = 'user_task'
    task_id = db.Column(db.Integer, db.ForeignKey('task.id'), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    comment = db.Column(db.String(140))
    record_url = db.Column(db.String(140))
    record_id = db.Column(db.String(140))
    record_title = db.Column(db.String(140))
    record_create_time = db.Column(db.DateTime)
    mark = db.Column(db.Float)
    task = db.relationship("Task", back_populates="users")
    user = db.relationship("User", back_populates="tasks")

    @staticmethod
    def add_user_task(user, task):
        user_has_task = User_task(user=user, task=task)
        db.session.add(user_has_task)
        db.session.commit()

    # @staticmethod
    # def get_user_task(user_id, task_id):
    #     user = db.session.query(User).filter(User.id == user_id).one()
    #     for task in user.tasks:
    #         if task.task_id == task_id:
    #             print(task.mark)
    #             return task

    def add(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        # this_task = db.session.query(Task).filter(Task.id == self.task_id).first()
        # questions = this_task.tasks
        # for question in questions:
        #     User_question.query.filter_by(question_id=question.id, user_id=self.user_id).first().delete()
        questions = self.task.questions
        for question in questions:
            user_question = User_question.query.filter_by(
                question_id=question.id, user_id=self.user_id).first()
            if user_question:
                user_question.delete()
        db.session.delete(self)
        db.session.commit()

    def update(self):
        db.session.commit()
Beispiel #5
0
class Task(db.Model):
    __tablename__ = 'task'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    task_name = db.Column(db.String(64))
    description = db.Column(db.String(300))
    create_time = db.Column(db.DateTime, default=datetime.now)
    due_time = db.Column(db.DateTime)
    pdf_url = db.Column(db.String(140))
    pdf_id = db.Column(db.String(140))
    unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'))
    unit = db.relationship("Unit", back_populates="tasks")
    questions = db.relationship("Question", back_populates="task")
    users = db.relationship("User_task", back_populates="task")

    def __repr__(self):
        return 'id={}, task_name={},description={}'.format(
            self.id, self.task_name, self.description)

    def add(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        if self.pdf_url is not None and self.pdf_url != 'deleted':
            pdf_id = self.pdf_id
            file = route.drive.CreateFile({'id': pdf_id})
            file.Delete()
        for question in self.questions:
            question.delete()
        user_tasks = db.session.query(User_task).filter(
            User_task.task_id == self.id)
        for user_task in user_tasks:
            user_task.delete()
        db.session.delete(self)
        db.session.commit()

    def delete_pdf(self):
        pdf_id = self.pdf_id
        file = route.drive.CreateFile({'id': pdf_id})
        file.Delete()
        self.pdf_id = None
        self.pdf_url = None
        self.update()

    def update(self):
        db.session.commit()

    def add_task2unit(self, unit):
        self.unit_id = unit.id
        db.session.commit()

    def get_task_users(self):
        users = []
        for user_task in self.users:
            user_id = user_task.user_id
            users.append(
                db.session.query(User).filter(User.id == user_id).one())
        return users
Beispiel #6
0
class User_unit(db.Model):
    __tablename__ = 'user_unit'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'), primary_key=True)
    user = db.relationship("User", back_populates="units")
    unit = db.relationship("Unit", back_populates="users")

    def add(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        tasks = self.unit.tasks
        for task in tasks:
            user_task = User_task.query.filter_by(
                task_id=task.id, user_id=self.user_id).first()
            if user_task:
                user_task.delete()

        db.session.delete(self)
        db.session.commit()

    def update(self):
        db.session.commit()