Ejemplo n.º 1
0
    def update_badges(self, subjectroom, new_proficiency, old_proficiency):
        if new_proficiency == old_proficiency:
            return

        if old_proficiency.name is None:
            if new_proficiency >= ProficiencyClass.PAWN:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.PAWN)
            if new_proficiency >= ProficiencyClass.KNIGHT:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.KNIGHT)
            if new_proficiency == ProficiencyClass.KING:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.KING)
        elif old_proficiency == ProficiencyClass.PAWN:
            if new_proficiency >= ProficiencyClass.KNIGHT:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.KNIGHT)
            if new_proficiency == ProficiencyClass.KING:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.KING)
        elif old_proficiency == ProficiencyClass.KNIGHT:
            if new_proficiency == ProficiencyClass.KING:
                self.create_proficiency_increase_notification(
                    subjectroom, ProficiencyClass.KING)
        else:
            InvalidStateError("Invalid proficiency increase: %s to %s" %
                              (old_proficiency, new_proficiency))
Ejemplo n.º 2
0
    def build_for_subjectroom(cls, subjectroom, student):
        # first check if you can calculate an average

        subjectroom_graded_assignments = get_subjectroom_graded_assignments(
            subjectroom)
        if subjectroom_graded_assignments.count() == 0:
            return None  # element cannot exist with no data

        subjectroom_average = get_fraction_label(
            subjectroom_graded_assignments.aggregate(
                Avg('average'))['average__avg'])

        # need to evaluate the graded assignments query beforehand because as on 11/15 LIMIT is not supported for IN subquery
        graded_assignment_pks = list(
            subjectroom_graded_assignments.values_list('pk', flat=True))
        submissions = Submission.objects.filter(
            assignment__pk__in=graded_assignment_pks, student=student)
        if submissions.count() == 0:
            raise InvalidStateError(
                'No submissions found for student belonging to subjectroom with graded assignments'
            )

        student_average = get_fraction_label(
            submissions.aggregate(Avg('marks'))['marks__avg'])

        return cls(student_average, subjectroom_average,
                   subjectroom.subject.name)
Ejemplo n.º 3
0
def submission_id_post(request, submission_id):
    statsd.increment('core.hits.post.submission_id')

    submission = get_object_or_404(Submission, pk=submission_id)

    # submissions can only be submitted for active+uncorrected/practice+uncorrected assignments
    assignment_type = get_assignment_type(submission.assignment)

    if assignment_type == HWCentralAssignmentType.STUDENT:
        submission_type = get_student_assignment_submission_type(submission)
        if submission_type == HWCentralStudentAssignmentSubmissionType.CORRECTED:
            raise Http404
        elif submission_type == HWCentralStudentAssignmentSubmissionType.UNCORRECTED:
            return SubmissionIdPostStudent(request, submission).handle()
        else:
            raise InvalidHWCentralAssignmentTypeError(submission_type)
    elif assignment_type == HWCentralAssignmentType.INACTIVE:
        raise InvalidStateError("Submission %s for inactive assignment %s" %
                                (submission, submission.assignment))
    elif assignment_type == HWCentralAssignmentType.UNCORRECTED:
        return SubmissionIdPostUncorrected(request, submission).handle()
    elif assignment_type == HWCentralAssignmentType.CORRECTED:
        raise Http404
    else:
        raise InvalidHWCentralAssignmentTypeError(assignment_type)
Ejemplo n.º 4
0
    def build_for_focusroom(cls, focusroom, student):
        assert student.userinfo.school.schoolprofile.focus

        # first check if you can calculate an average
        focusroom_graded_assignments = get_focusroom_graded_assignments(
            focusroom)
        if focusroom_graded_assignments.count() == 0:
            return None  # element cannot exist with no data

        remedial_assignment_pks = [
        ]  # the list of assignments for remedials which included the current student
        for graded_assignment in focusroom_graded_assignments:
            if student in graded_assignment.content_object.students.all():
                remedial_assignment_pks.append(graded_assignment.pk)

        if len(remedial_assignment_pks) == 0:
            return None  # current student has never been in a remedial for this focusroom

        focusroom_average = get_fraction_label(
            focusroom_graded_assignments.aggregate(
                Avg('average'))['average__avg'])

        submissions = Submission.objects.filter(
            assignment__pk__in=remedial_assignment_pks, student=student)
        if submissions.count() == 0:
            raise InvalidStateError(
                'No submissions found for student in remedials belonging to focusroom with graded assignments'
            )

        student_average = get_fraction_label(
            submissions.aggregate(Avg('marks'))['marks__avg'])

        return cls(student_average, focusroom_average,
                   get_focusroom_label(focusroom.subjectRoom.subject.name))
Ejemplo n.º 5
0
    def __init__(self, assignment, categorization):
        if categorization == AssignmentInfo.CAT_PRACTICE:
            self.context = "Practice Assignment"
        elif categorization == AssignmentInfo.CAT_DUE:
            self.context = "Due: " + get_datetime_label(assignment.due)

        else:
            InvalidStateError('Invalid assignment categorization %s' %
                              categorization)
Ejemplo n.º 6
0
def get_student_assignment_submission_type(submission):
    assert is_student_assignment(submission.assignment)

    if (submission.marks is not None) and (submission.assignment.average
                                           is not None):
        return HWCentralStudentAssignmentSubmissionType.CORRECTED
    elif (submission.marks is None) and (submission.assignment.average is
                                         None):
        return HWCentralStudentAssignmentSubmissionType.UNCORRECTED
    else:
        raise InvalidStateError(
            "Student Assignment Submission %s has only one of marks and assignment average non null"
            % submission)
Ejemplo n.º 7
0
def check_homework_assignment(assignment):
    """
    checks that the given assignment is homework for a subjectroom or remedial
    """
    from core.models import SubjectRoom
    from focus.models import Remedial

    if assignment.content_type == ContentType.objects.get_for_model(User):
        raise InvalidStateError(
            "Practice/Open assignment is not a homework assignment.")
    elif (assignment.content_type !=
          ContentType.objects.get_for_model(Remedial)) and (
              assignment.content_type !=
              ContentType.objects.get_for_model(SubjectRoom)):
        raise InvalidContentTypeError(assignment.content_type)
Ejemplo n.º 8
0
def submission_id_get(request, submission_id):
    statsd.increment('core.hits.get.submission_id')

    submission = get_object_or_404(Submission, pk=submission_id)

    assignment_type = get_assignment_type(submission.assignment)

    if assignment_type == HWCentralAssignmentType.STUDENT:
        return SubmissionIdGetStudent(request, submission).handle()
    elif assignment_type == HWCentralAssignmentType.INACTIVE:
        raise InvalidStateError("Submission %s for inactive assignment %s" %
                                (submission, submission.assignment))
    elif assignment_type == HWCentralAssignmentType.UNCORRECTED:
        return SubmissionIdGetUncorrected(request, submission).handle()
    elif assignment_type == HWCentralAssignmentType.CORRECTED:
        return SubmissionIdGetCorrected(request, submission).handle()
    else:
        raise InvalidHWCentralAssignmentTypeError(assignment_type)
Ejemplo n.º 9
0
def trim_qb_dump(outfile, start_aql_id):
    trim_chapter = 0
    trim_questiontag = 0
    trim_question = 0
    trim_questionsubpart = 0
    trim_assignmentquestionslist = 0

    if start_aql_id > 1:
        # get the trim limits for all models by looking at the dump file for the previous aql id (if it exists)
        prev_aql_id = start_aql_id - 1
        for file in os.listdir(DUMPFILE_DIR):
            if (file == str(prev_aql_id) +
                    '.json') or ('to' + str(prev_aql_id) + '.json' in file):
                with open(os.path.join(DUMPFILE_DIR, file), 'r') as f:
                    prev_dump = json.load(f)
                    break
        else:
            raise InvalidStateError("Previous aql %s dump file not found" %
                                    prev_aql_id)

        # find max values for each model. These will be the trim values
        for elem in prev_dump:
            elem_model = elem["model"]
            elem_pk = elem["pk"]

            if elem_model == "core.chapter":
                if elem_pk > trim_chapter:
                    trim_chapter = elem_pk

            elif elem_model == "core.questiontag":
                if elem_pk > trim_questiontag:
                    trim_questiontag = elem_pk

            elif elem_model == "core.question":
                if elem_pk > trim_question:
                    trim_question = elem_pk

            elif elem_model == "core.questionsubpart":
                if elem_pk > trim_questionsubpart:
                    trim_questionsubpart = elem_pk

            elif elem_model == "core.assignmentquestionslist":
                if elem_pk > trim_assignmentquestionslist:
                    trim_assignmentquestionslist = elem_pk

            else:
                raise InvalidStateError("Unexpected model %s in qb dump" %
                                        elem_model)

        if trim_chapter == 0:
            print 'No chapter trim found in dump file: %s' % file
            print 'Please enter chapter trim pk for dump file: %s' % outfile
            trim_chapter = int(raw_input())

        if trim_questiontag == 0:
            print 'No chapter trim found in dump file: %s' % file
            print 'Please enter chapter trim pk for dump file: %s' % outfile
            trim_questiontag = int(raw_input())

    with open(outfile, 'r') as f:
        qb_dump = json.load(f)
    trimmed_qb_dump = []

    for elem in qb_dump:
        elem_model = elem["model"]
        elem_pk = elem["pk"]
        if elem_model == "core.chapter":
            if elem_pk > trim_chapter:
                trimmed_qb_dump.append(elem)

        elif elem_model == "core.questiontag":
            if elem_pk > trim_questiontag:
                trimmed_qb_dump.append(elem)

        elif elem_model == "core.question":
            if elem_pk > trim_question:
                trimmed_qb_dump.append(elem)

        elif elem_model == "core.questionsubpart":
            if elem_pk > trim_questionsubpart:
                trimmed_qb_dump.append(elem)

        elif elem_model == "core.assignmentquestionslist":
            if elem_pk > trim_assignmentquestionslist:
                trimmed_qb_dump.append(elem)

        else:
            raise InvalidStateError("Unexpected model %s in qb dump" %
                                    elem_model)

    with open(outfile, 'w') as f:
        json.dump(trimmed_qb_dump, f, indent=4)
Ejemplo n.º 10
0
    def teacher_endpoint(self):
        classteacher = False
        subjectteacher = False
        if self.user.classes_managed_set.exists():
            classteacher = True
        if self.user.subjects_managed_set.exists():
            subjectteacher = True

        if classteacher and (not subjectteacher):
            #For ClassTeacher type teacher user
            form = ClassAnnouncementForm(self.user, self.request.POST)
            if form.is_valid():
                classroom = form.cleaned_data['classroom']
                message = form.cleaned_data['message']
                new_announcement = Announcement.objects.create(
                    content_object=classroom,
                    message=message,
                    announcer=self.user)
                return self.redirect_with_toast(new_announcement)
            else:
                return render(
                    self.request, self.template,
                    AuthenticatedVM(self.user,
                                    AnnouncementBody(form)).as_context())

        elif (not classteacher) and subjectteacher:
            #For Subject Teacher type teacher user
            form = SubjectAnnouncementForm(self.user, self.request.POST)
            if form.is_valid():
                subjectroom = form.cleaned_data['subjectroom']
                message = form.cleaned_data['message']
                new_announcement = Announcement.objects.create(
                    content_object=subjectroom,
                    message=message,
                    announcer=self.user)
                return self.redirect_with_toast(new_announcement)
            else:
                return render(
                    self.request, self.template,
                    AuthenticatedVM(self.user,
                                    AnnouncementBody(form)).as_context())

        elif classteacher and subjectteacher:
            #For a Class and Subject Teacher type teacher user
            form = ClassSubjectAnnouncementForm(self.user, self.request.POST)
            if form.is_valid():
                target = form.cleaned_data['target']
                if target.startswith(
                        ClassSubjectAnnouncementForm.SUBJECTROOM_ID_PREFIX):
                    content_object = SubjectRoom.objects.get(
                        pk=long(target[len(ClassSubjectAnnouncementForm.
                                           SUBJECTROOM_ID_PREFIX):]))
                elif target.startswith(
                        ClassSubjectAnnouncementForm.CLASSROOM_ID_PREFIX):
                    content_object = ClassRoom.objects.get(
                        pk=long(target[len(ClassSubjectAnnouncementForm.
                                           CLASSROOM_ID_PREFIX):]))
                else:
                    raise InvalidStateError(
                        "Invalid announcement form target: %s" % target)
                message = form.cleaned_data['message']
                new_announcement = Announcement.objects.create(
                    content_object=content_object,
                    message=message,
                    announcer=self.user)
                return self.redirect_with_toast(new_announcement)
            else:
                return render(
                    self.request, self.template,
                    AuthenticatedVM(self.user,
                                    AnnouncementBody(form)).as_context())

        else:
            raise Http404