コード例 #1
0
def delete_course(id):
    course = Course()
    course.id = id
    if course.course_has_student():
        flash(
            'Course Has a Student Enrolled in it. Please Update the student\'s course to delete the specified course.',
            category='danger')
        return redirect(url_for('students'))
    else:
        course.delete(id)
        flash('Successfully Deleted Course!', category='success')
        return redirect(url_for('courses'))
コード例 #2
0
ファイル: courses.py プロジェクト: availablenick/getren
def course(id):
    course = Course.get_by_id(id)
    if course is None:
        return {}, 404
    if request.method == 'GET':
        course_dict = course.as_dict()
        response = jsonify(course_dict)
        response.status_code = 200
        return response
    if is_valid_admin(request):
        if request.method == 'PUT':
            json_args = request.form['json_args']
            result = json.loads(json_args)
            while type(result) == str:
                result = json.loads(result)
            course = Course.update_data(id, result)
            if course:
                course_dict = course.as_dict()
                response = jsonify(course_dict)
                response.status_code = 200
                return response
            else:
                return error_response('Curso não atualizado', 500)

        elif request.method == 'DELETE':
            if Course.delete(id):
                return {}, 200
            else:
                return error_response(
                    'Curso não deletado. Tente novamente em alguns minutos.',
                    500)
    else:
        return error_response('Permissão negada', 401)
コード例 #3
0
 def test_09_delete_fail(self):
     course = Course.add({"name": "Curso de teste"})
     Course.delete(2)
     deleted_course = Course.get_by_id(1)
     assert deleted_course is not None
コード例 #4
0
 def test_08_delete(self):
     course = Course.add({"name": "Curso de teste"})
     is_deleted = Course.delete(1)
     deleted_course = Course.get_by_id(1)
     assert is_deleted == True and deleted_course is None