Example #1
0
def add_exam():
    if current_identity.is_superuser:
        data = request.get_json()
        exam = Exam(data['subject_id'], data['exam_period_id'], data['date'])
        exam.save()
        return custom_response({'message': 'Successfully created'}, 201)
    else:
        return custom_response({'error': 'Unauthorized'}, 403)
Example #2
0
def createNewExam(examName, groupName):
    groupObject = Group.objects.get(group_name=groupName)
    try:
        examObject = Exam.objects.get(group=groupObject, exam_name=examName)
        return False
    except Exam.DoesNotExist:
        examObject = Exam(group=groupObject, exam_name=examName)
        examObject.save()
        return True
Example #3
0
def post_metadata(request, ef_id):
    ef = get_object_or_404(ExamFile, id=ef_id)
    try:
        e = Exam.objects.get(file=ef)
    except Exam.DoesNotExist:
        e = Exam()
        e.file = ef
    e.professor, c = Professor.objects.get_or_create(name=request.POST['professor'])
    e.subject, c = Subject.objects.get_or_create(name=request.POST['subject'])
    e.degree, c = Degree.objects.get_or_create(name=request.POST['degree'])
    try:
        e.year = int(request.POST['year'])
    except ValueError:
        r = HttpResponse("invalid year")
        r.status_code = 405
        return r
    e.hws = True if request.POST['hws'] == "true" else False 
    e.solution = True if request.POST['solution'] == "true" else False 
    e.note = request.POST['note'] 
    e.save()
    return HttpResponse("OK")
Example #4
0
    def post(self, request):
        """
        Create exam record in database
        :param request: Key value pair data
        :return: status & respective message
        """

        data = request.data

        if "college_ids" in data:
            college_ids = data["college_ids"]
            data.pop("college_ids")

        # Assuming field_id is mandatory as of now
        try:
            exam = Exam(**data)
            exam.save()
            LOGGER.info("exam created successfully")
        except Exception, error:
            LOGGER.error("Error:%s", str(error))
            return Response({"status": "FAILED", "message": str(error)})