示例#1
0
    def post(self, dist_id):
        #args = parser.parse_args()
        user_id = get_jwt_identity()['id']
        grade_distribution = GradeDistribution().where(
            [['id', '=', dist_id], ['user_id', '=', user_id]]).first()

        if grade_distribution.exists() is True:
            grade_distribution.delete()
            return response(
                {'message': 'Grade Distribution has deleted successfully'},
                202)

        return response({'errors': ['Grade distribution could not found']},
                        404)
示例#2
0
    def post(self):
        args = parser.parse_args()
        user_id = get_jwt_identity()['id']
        file = args['image']

        if file:
            grade_distribution = GradeDistribution()
            filename = grade_distribution.generateImageName()
            grade_distribution.create({
                'lecturer_id': args['lecturer_id'],
                'user_id': user_id,
                'term_id': args['term_id'],
                'course_id': args['course_id'],
                'course_code': args['course_code'],
                'english': args['english'],
                'image': filename
            })

            imgdata = base64.b64decode(file.split(';base64,', 1)[1])

            with open(server.config['UPLOAD_FOLDER'] + '/' + filename,
                      'wb') as f:
                f.write(imgdata)

            file_size = os.stat(
                os.path.join(server.config['UPLOAD_FOLDER'], filename)).st_size

            if file_size > 5000000:
                os.remove(
                    os.path.join(server.config['UPLOAD_FOLDER'], filename))
                return response(
                    {'errors': ['File size must be lower than 5 MB']}, 400)

            if grade_distribution.validate() is True:
                grade_distribution.save()

                return response(
                    {'grade_distribution': grade_distribution.data()})

            return response({'errors': grade_distribution.getErrors()}, 400)

        return response({
            'errors': ['File could not found!'],
            'file': file
        }, 400)
示例#3
0
    def post(self, user_id):
        user_id = get_jwt_identity()['id']
        user = User().where('id', user_id).first()
        if user.exists() is True:
            Comment().where('user_id', user_id).get().delete()
            GradeDistribution().where('user_id', user_id).get().delete()
            Lecturer().where('user_id', user_id).get().delete()
            Note().where('user_id', user_id).get().delete()
            user.delete()
            return response({'message': 'User deleted with success'}, 200)

        return response({'errors': ['User could not found!']}, 401)
示例#4
0
 def post(self, user_id):
     user = User().where('id', '=', user_id).first()
     print(user_id, file=sys.stderr)
     if user.exists():
         Comment().where('user_id', user_id).get().delete()
         Event().where('user_id', user_id).get().delete()
         GradeDistribution().where('user_id', user_id).get().delete()
         lecturers = Lecturer().where('user_id', user_id).get()
         for lecturer in lecturers.data():
             Comment().where([['type', '=', 'lecturers'], ['type_id', '=', lecturer['id']]]).get().delete()
             GradeDistribution().where('lecturer_id', '=', lecturer['id']).get().delete()
         lecturers.delete()
         notes = Note().where('user_id', user_id).get()
         for note in notes.data():
             Comment().where([['type', '=', 'notes'], ['type_id', '=', note['id']]]).get().delete()
         notes.delete()
         user.delete()
         return response({
             'message': 'User deleted successfully'
         }, 202)
     return response({
         'message': 'User does not exist'
     }, 404)
示例#5
0
    def post(self, term_id):
        term = Term().where('id', '=', term_id).first()
        notes = Note().where('term_id', term_id).get()
        for note in notes:
            note.delete()
        grade_dists = GradeDistribution().where('term_id', term_id).get()
        for grade_dist in grade_dists:
            grade_dist.delete()

        if term.exists():
            term.delete()
            return response({
                'message': 'Term deleted successfully'
            }, 202)
        return response({
            'message': 'Term does not exist'
        }, 404)
示例#6
0
    def post(self, course_id):
        course = Course().where('id', '=', course_id).first()
        notes = Note().where('course_id', course_id).get()
        for note in notes:
            note.delete()
        grade_dists = GradeDistribution().where('course_id', course_id).get()
        for grade_dist in grade_dists:
            grade_dist.delete()

        if course.exists():
            course.delete()
            return response({
                'message': 'Course deleted successfully'
            }, 202)
        return response({
            'message': 'Course does not exist'
        }, 404)
示例#7
0
    def post(self, lecturer_id):
        lecturer = Lecturer().where('id', lecturer_id).first()

        if lecturer.exists() is True:
            Comment().where([['type', '=', 'lecturers'], ['type_id', '=', lecturer_id]]).get().delete()
            GradeDistribution().where('lecturer_id', '=', lecturer_id).get().delete()

            lecturer.delete()
            return response({
                'message': 'Lecturer deleted'
            })

        return response({
            'errors': [
                'Lecturer could not found'
            ]
        }, 401)
示例#8
0
    def get(self, slug):
        lecturer = Lecturer().where('slug', slug).first()

        if lecturer.exists() is True:
            comments = Comment().where([['type_id', '=', lecturer.ATTRIBUTES['id']], ['type', '=', 'lecturers']])\
                .get().data()
            grade_distributions = GradeDistribution().where(
                'lecturer_id', lecturer.ATTRIBUTES['id']).get().data()

            return response({
                'lecturer':
                lecturer.plus('comments',
                              comments).plus('grade_distributions',
                                             grade_distributions).data()
            })

        return response({'errors': ['Lecturer could not found!']})
示例#9
0
    def post(self, lecturer_id):
        user_id = get_jwt_identity()['id']
        lecturer = Lecturer().where([['id', '=', lecturer_id],
                                     ['user_id', '=', user_id]]).first()

        comments = Comment().where([['type_id', '=', lecturer_id],
                                    ['type', '=', 'lecturers']]).get()
        for comment in comments:
            comment.delete()

        dists = GradeDistribution().where('lecturer_id',
                                          lecturer_id).get().delete()

        if lecturer.exists() is True:
            lecturer.delete()
            return response({'message': 'Lecturer deleted'})

        return response({'errors': ['Lecturer could not found']}, 401)