Пример #1
0
def create_grader(grader_dict, sub):
    grade = Grader(
        score=grader_dict['score'],
        feedback=grader_dict['feedback'],
        status_code=grader_dict['status'],
        grader_id=grader_dict['grader_id'],
        grader_type=grader_dict['grader_type'],
        confidence=grader_dict['confidence'],
        submission=sub,
    )

    grade.save()

    return grade
Пример #2
0
def create_grader(grader_dict, sub):
    log.debug("Creating grader with feedback: {0} and type {1}".format(grader_dict['feedback'], grader_dict['grader_type']))
    grade = Grader(
        score=grader_dict['score'],
        feedback=grader_dict['feedback'],
        status_code=grader_dict['status'],
        grader_id=grader_dict['grader_id'],
        grader_type=grader_dict['grader_type'],
        confidence=grader_dict['confidence'],
        submission=sub,
    )

    grade.save()

    return grade
Пример #3
0
def create_grader(grader_dict, sub):
    log.debug("Creating grader with feedback: {0} and type {1}".format(
        grader_dict['feedback'], grader_dict['grader_type']))
    grade = Grader(
        score=grader_dict['score'],
        feedback=grader_dict['feedback'],
        status_code=grader_dict['status'],
        grader_id=grader_dict['grader_id'],
        grader_type=grader_dict['grader_type'],
        confidence=grader_dict['confidence'],
        submission=sub,
    )

    grade.save()

    return grade
Пример #4
0
def formPostGraderAddV0(request):

    status = 'Success'
    if request.is_ajax() and request.method == 'POST':

        jqxinputLesson = request.POST.get('jqxinputGraderNewLesson', None)
        #jqxinputTeacherArray = request.POST.getlist('jqxinputGraderNewTeacherArray[]', '')       # Received: [u'[7,6,1]'] AS STRING
        jqxinputTeacherArray = json.loads(request.POST['jqxinputGraderNewTeacherArray'])
        #print 'POST Received:', jqxinputLesson, jqxinputTeacherArray
        
        # CHECK Fail Conditions  | Pass to DB |  MUST CHECK FOR FAIL CONDITIONS
        lessonIsNull = True  if jqxinputLesson == ''  else False 
        teacherArrayIsNull = True  if jqxinputTeacherArray == ''  else False 
        
        if lessonIsNull or teacherArrayIsNull:
            status = 'Error'
            #responseData.append ( {'status': 'error', } )
        else:
            lesson = Lesson.objects.get( id = jqxinputLesson )        # pk = # get Lesson Data 
            print "Found in DB (LESSON):", lesson.name
            for jqxinputTeacher in jqxinputTeacherArray:
                teacher = Teacher.objects.get(id = jqxinputTeacher )  # get Teacher Data 
                #teacher = Teacher.objects.filter( id = jqxinputTeacher )
                print "Found in DB (TEACHER):", teacher.surname
                graderExists = False  if Grader.objects.filter(TeacherID = teacher, LessonID = lesson).count() == 0  else True 
                if not (graderExists):
                    print 'No GraderExists:', teacher,  lesson
                    # INSERT to DB > MUST CHECK FOR FAIL CONDITIONS
                    Grader(LessonID = lesson, TeacherID = teacher, ).save()
                    print 'INSERT Grader:', teacher,  lesson
                else: 
                    status = 'Errors'
        #<!-- User Inputs -->
        #dictData = {'jqxinputLesson':jqxinputLesson, 'jqxinputTeacherArray': jqxinputTeacherArray, }
        dictData = {'status': status, }
        jsonData = json.dumps(dictData)
        #print 'jsonData:', jsonData
        return HttpResponse(jsonData, content_type='application/json')
    else:
        raise Http404    
Пример #5
0
def jsonGraderCrud(request):
    
    dictData = []
    if request.is_ajax() and request.method == 'GET':
        id = request.GET.get('id', None)
        LessonID = request.GET.get('LessonID', None)
        action = request.GET.get('action', None)
        print action, LessonID

        if (action=="filter"):     # on LessonID
            dictData = GraderJoinTables(LessonID)
        else: 
            dictData = GraderJoinTables()
        #print dictData
        jsonData = json_repr(list(dictData))
        #jsonData = json.dumps(list(dictData))
        #jsonData = json.dumps(list(dictData), default=date_handler)  # handle datetime JSON ser.
        #print jsonData
        return HttpResponse(jsonData, content_type='application/json')

    if request.is_ajax() and request.method == 'POST':
        action = request.POST.get('action', None)        
        print action

        #ADD
        if (action=="add"):        # on LessonID
            #status = 'Success'
            jqxinputLesson = request.POST.get('jqxinputGraderNewLesson', None)
            jqxinputTeacherArray = json.loads(request.POST['jqxinputGraderNewTeacherArray'])
            #print 'POST Received:', jqxinputLesson, jqxinputTeacherArray        
            # CHECK Fail Conditions  | Pass to DB |  MUST CHECK FOR FAIL CONDITIONS
            lessonIsNull = True  if jqxinputLesson == ''  else False 
            teacherArrayIsNull = True  if jqxinputTeacherArray == ''  else False 
            
            if lessonIsNull or teacherArrayIsNull:
                msg = 'Ανύπαρκτα στοιχεία Μαθήματος ή Καθηγητών!'
                helperMessageLog(request, msg, tag='info')                
                #messages.error(request, msg, fail_silently=True)
                #status = 'Error'
            else:
                lesson = Lesson.objects.get( id = jqxinputLesson )        # pk = # get Lesson Data 
                #print "Found in DB (LESSON):", lesson.name
                (i, j)  = (0, 0)
                for jqxinputTeacher in jqxinputTeacherArray:
                    teacher = Teacher.objects.get(id = jqxinputTeacher )  # get Teacher Data 
                    #print "Found in DB (TEACHER):", teacher.surname
                    graderExists = False  if Grader.objects.filter(TeacherID = teacher, LessonID = lesson).count() == 0  else True 
                    if not (graderExists):
                        try:
                            Grader(LessonID = lesson, TeacherID = teacher, ).save()
                            i +=1
                        except DatabaseError:
                            transaction.rollback()   
                            msg = "Αδυναμία εισαγωγής εγγραφής!"
                            helperMessageLog(request, msg, tag='error')
                    else: 
                        j +=1

                # Handle display of 2 messages 
                if i >0 :                
                    msg = 'Επιτυχής εισαγωγή (%d) εγγραφών!' %(i)
                    helperMessageLog(request, msg, tag='info')                
                if j >0 :                 
                    msg = 'Υπήρξαν (%d) σχετικές εγγραφές!' %(j) #%(teacher.name,  lesson.name)
                    helperMessageLog(request, msg, tag='warning')                

            #dictData = {'jqxinputLesson':jqxinputLesson, 'jqxinputTeacherArray': jqxinputTeacherArray, }
            jsonData = json.dumps("ΟΚ")
            return HttpResponse(jsonData, content_type='application/json')                    

        #UPDATE
        elif (action=="update"):
            id = request.POST.get('id', None)
            isCoordinator = request.POST.get('isCoordinator', None).title()
            isgraderC = request.POST.get('isgraderC', None).title()
            status = request.POST.get('status', None)

            try:    
                record = Grader.objects.filter(id=id)
                record.update (isCoordinator = helperStr2Bool(isCoordinator), 
                    isgraderC = helperStr2Bool(isgraderC), status = status, )
                #'Αδυναμία εισαγωγής | τροποποίησης | διαγραφής | εγγραφής.'
                msg = "Επιτυχής τροποποίηση  εγγραφής!"                 
                helperMessageLog(request, msg, tag='info')
            except DatabaseError:
                transaction.rollback()   
                msg = "Αδυναμία τροποποίησης εγγραφής!"
                helperMessageLog(request, msg, tag='error')
                
            dictData = record.values()
            jsonData = json.dumps(list(dictData))
            return HttpResponse(jsonData, content_type='application/json')
        
        #DELETE 
        elif (action=="delete"):
            id = request.POST.get('id', None)
            try:
                record = Grader.objects.filter(id=id).delete()
                msg = 'Επιτυχής διαγραφής εγγραφής!' #%(record.name)
                helperMessageLog(request, msg, tag='info')
                
            except DatabaseError:
                transaction.rollback()   
                msg = 'Αδυναμία διαγραφής εγγραφής!' 
                helperMessageLog(request, msg, tag='info')
                
            jsonData = json.dumps(msg)  #jsonData = json.dumps(status)
            return HttpResponse(jsonData, content_type='application/json')

    # DEFAULT 
    else: 
        dictData = GraderJoinTables()
        jsonData = json_repr(list(dictData))
        #jsonData = json.dumps(list(dictData), default=date_handler)  # handle datetime JSON ser.
        #jsonData = json.dumps(list(dictData))
        #print jsonData
        return HttpResponse(jsonData, content_type='application/json')