def source_erase(request): try: check_capability(request, 'edit') source = source_get_by_id(request.matchdict['source_id']) if source.get_type() != '_subject' or not source.problem_id: check_capability(request, 'admin') db_session.delete(source) db_session.commit() return {"result": "ok"} except Exception as e: return {"result": "error", "content": e.__str__()}
def source_verify_cancel(request): try: check_capability(request, 'edit') source = source_get_by_id(request.matchdict['source_id']) if source.verified: raise Exception("Source mustn't be canceled") db_session.delete(source) db_session.commit() return {'result': 'ok'} except Exception as e: return {'result': 'error', 'content': e.__str__()}
def course_verify_cancel(request): try: check_capability_course(request, 'admin') course = course_get_by_id(request.matchdict['course_id']) if course.verified: raise Exception("Source mustn't be canceled") db_session.delete(course) db_session.commit() course_make_dump(request) return {'result': 'ok'} except Exception as e: return {'result': 'error', 'content': e.__str__()}
def course_erase(request): return course_erase_all(request) try: raise Exception("DEPRECATED") course = course_get_by_id(request.matchdict['course_id']) if course_check_owner(course.course_id, int(RequestGetUserId(request))) \ or course_tree_check_owner(course.id, RequestGetUserId(request)): check_capability_course(request, 'teacher') else: check_capability_course(request, 'admin') db_session.delete(course) db_session.commit() course_make_dump(request) return {'result': 'ok'} except Exception as e: return {'result': 'error', 'content': e.__str__()}
def erase_tree(course): for child in course.children: erase_tree(child) db_session.delete(course)
def erase_tree(source): if not source: return for child in source.children: erase_tree(child) db_session.delete(source)