Пример #1
0
    def mutate(self, info, name, department):
        q = Department.get_query(info)
        subject_department = q.filter_by(id=department).one()
        new_subject = SubjectModel(name=name, department=subject_department)
        db_session.add(new_subject)
        db_session.commit()

        return CreateSubject(id=new_subject.id, name=new_subject.name, department=new_subject.department)
Пример #2
0
    def post(self):
        data = Subject.parser.parse_args()
        if SubjectModel.find_by_name(data["name"]):
            return {"messages": err_duplicate.format("subject")}, 400

        subject = SubjectModel(**data)
        try:
            subject.save_to_db()
        except:
            return {"messages": err_500}, 500
        return {"messages": noti_201}, 201
Пример #3
0
 def post(self):
     data = self.parser.parse_args()['subjects']
     body = data['body']
     date = data['date']
     name = data['name']
     user_id = get_jwt_identity()
     user: UserModel = UserModel.find_by_id(user_id)
     user.subjects_date = date
     for subject in body:
         subject_model = SubjectModel(name, subject, user_id)
         subject_model.save_to_db()
     if date is None:
         signuper = SubjectSignuper(body, user.get_cookies())
         signuper.execute()
     return {"message": "Successfully added subjects"}, 201