Ejemplo n.º 1
0
    def get_common_objects(self) -> None:
        super().get_common_objects()

        students = self.instance.students.all()
        group = self.request.GET.get("group")
        if group == "internal":
            students = [s for s in students if not s.is_external]
        elif group == "external":
            students = [s for s in students if s.is_external]

        point_limits = self.design.point_limits
        pad_points = self.design.pad_points
        student_grades = []
        for profile in students:
            points = CachedPoints(self.instance, profile.user, self.content,
                                  self.is_course_staff)
            student_grades.append((
                profile,
                calculate_grade(points.total(), point_limits, pad_points),
            ))
        self.student_grades = student_grades
        self.group = group
        self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
        self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
        self.note('student_grades', 'group', 'internal_user_label',
                  'external_user_label')
Ejemplo n.º 2
0
    def obj_get(self, request=None, **kwargs):
        results = {}
        course_instance = CourseInstance.objects.get(pk=kwargs["pk"])
        user_profile = UserProfile.objects.get(pk=kwargs["user"])
        points = CachedPoints(course_instance, user_profile.user,
                              CachedContent(course_instance))
        results["user"] = user_profile.id
        results["course_instance"] = kwargs["pk"]

        summary = []
        for entry in points.modules():
            exs = []
            for entry in points.flat_module(entry):
                exs.append({
                    'exercise_id':
                    entry['id'],
                    'submission_count':
                    entry['submission_count'],
                    'completed_percentage':
                    self._percentage(entry['points'], entry['max_points']),
                })
            summary.append({
                'exercise_round_id':
                entry['id'],
                'completed_percentage':
                self._percentage(entry['points'], entry['max_points']),
                'closing_time':
                entry['closing_time'],
                'exercise_summaries':
                exs,
            })

        results["summary"] = summary
        return results
Ejemplo n.º 3
0
    def has_object_permission(self, request: HttpRequest, view: Any,
                              module: CourseModule) -> bool:
        if isinstance(request.user, GraderUser):
            return False

        if not isinstance(module, CourseModule):
            return True

        if module.status == CourseModule.STATUS.HIDDEN:
            return False

        if not module.is_after_open():
            # FIXME: use format from django settings
            self.error_msg(
                _('MODULE_PERMISSION_ERROR_NOT_OPEN_YET -- {date}'),
                format={'date': module.opening_time},
                delim=' ',
            )
            return False

        if module.requirements.count() > 0:
            points = CachedPoints(module.course_instance, request.user,
                                  view.content, view.is_course_staff)
            return module.are_requirements_passed(points)
        return True
Ejemplo n.º 4
0
 def test_pass(self):
     content = CachedContent(self.instance)
     points = CachedPoints(self.instance, self.student, content)
     t = Threshold.objects.create(course_instance=self.instance,
                                  name="test")
     t.passed_categories.add(self.category)
     self.assertTrue(t.is_passed(points))
     t.passed_exercises.add(self.exercise)
     self.assertTrue(t.is_passed(points))
     t.passed_exercises.add(self.exercise2)
     self.assertFalse(t.is_passed(points))
     t.passed_exercises.clear()
     t.passed_modules.add(self.module)
     self.assertFalse(t.is_passed(points))
     self.submission3.set_points(2, 2)
     self.submission3.set_ready()
     self.submission3.save()
     points = CachedPoints(self.instance, self.student, content)
     self.assertTrue(t.is_passed(points))
Ejemplo n.º 5
0
    def retrieve(self, request, course_id, version, user_id=None):
        profile = self.get_object()
        points = CachedPoints(self.instance, profile.user, self.content)
        ids = points.submission_ids(
            category_id=self._int_or_none(request.GET.get('category_id')),
            module_id=self._int_or_none(request.GET.get('module_id')),
            exercise_id=self._int_or_none(request.GET.get('exercise_id')),
            best=request.GET.get('best') != 'no',
        )
        submissions = Submission.objects.filter(id__in=ids)

        # Pick out a field.
        field = request.GET.get('field')
        if field:
            vals = [self._submitted_field(s, field) for s in submissions.all()]
            return Response([v for v in vals if v != ""])

        serializer = self.get_serializer(submissions, many=True)
        return Response(serializer.data)
Ejemplo n.º 6
0
    def get(self, request: HttpRequest, *args: Any,
            **kwargs: Any) -> HttpResponse:
        # Query submitters who have not been assessed yet.
        submitter = None
        submitters = (UserProfile.objects.filter(
            submissions__exercise=self.exercise).annotate(count_assessed=Count(
                'submissions__id',
                filter=(Q(submissions__grader__isnull=False)),
            ), ).filter(count_assessed=0).order_by('id'))

        previous_user_id = request.GET.get('prev')
        if previous_user_id:
            # Find specifically the submitter AFTER the previously inspected one.
            submitters_after = submitters.filter(id__gt=previous_user_id)
            submitter = submitters_after.first()

        if not submitter:
            submitter = submitters.first()

        if not submitter:
            # There are no more unassessed submitters.
            messages.success(request, _('ALL_SUBMITTERS_HAVE_BEEN_ASSESSED'))
            return self.redirect(self.exercise.get_submission_list_url())

        # Find the submitter's best submission using the cache.
        cache = CachedPoints(self.instance, submitter.user, self.content, True)
        ids = cache.submission_ids(exercise_id=self.exercise.id,
                                   best=True,
                                   fallback_to_last=True)
        if not ids:
            raise Http404()
        url = reverse(
            'submission-inspect',
            kwargs={
                'submission_id': ids[0],
                **kwargs
            },
        )
        return self.redirect(url)
Ejemplo n.º 7
0
    def get(self, request: HttpRequest, *args: Any,
            **kwargs: Any) -> HttpResponse:
        user = get_object_or_404(
            User,
            id=self.kwargs[self.user_kw],
        )

        # Find the submitter's best submission using the cache.
        cache = CachedPoints(self.instance, user, self.content, True)
        ids = cache.submission_ids(exercise_id=self.exercise.id,
                                   best=True,
                                   fallback_to_last=True)
        if not ids:
            raise Http404()
        del kwargs['user_id']
        url = reverse(
            'submission-inspect',
            kwargs={
                'submission_id': ids[0],
                **kwargs
            },
        )
        return self.redirect(url)
Ejemplo n.º 8
0
    def retrieve(self, request, course_id, version, user_id=None):
        profile = self.get_object()
        students_results = self.student_information(profile, course_id,
                                                    request)

        students_results["tags"] = [
            t.id for t in profile.taggings.tags_for_instance(self.instance)
        ]

        points = CachedPoints(self.instance, profile.user, self.content)
        students_results = self.students_rounds(profile, points,
                                                students_results, request,
                                                course_id)

        return Response(students_results)
Ejemplo n.º 9
0
    def has_object_permission(self, request, view, module):

        if module.status == CourseModule.STATUS.HIDDEN:
            return False

        if not module.is_after_open():
            # FIXME: use format from django settings
            self.error_msg(
                _("The module will open for submissions at {date}."),
                format={'date': module.opening_time},
                delim=' ',
            )
            return False

        if module.requirements.count() > 0:
            points = CachedPoints(module.course_instance, request.user, view.content)
            return module.are_requirements_passed(points)
        return True
Ejemplo n.º 10
0
    def has_object_permission(self, request, view, module):
        if not isinstance(module, CourseModule):
            return True

        if module.status == CourseModule.STATUS.HIDDEN:
            self.error_msg(request, _("The module is not currently visible."))
            return False

        if not module.is_after_open():
            self.error_msg(
                request,
                _("The module will open for submissions at {date}").format(
                    date=module.opening_time))
            return False

        if module.requirements.count() > 0:
            points = CachedPoints(module.course_instance, request.user,
                                  view.content)
            return module.are_requirements_passed(points)
        return True
Ejemplo n.º 11
0
    def post(self, request, *args, **kwargs):
        design = self.design
        profile = self.get_profile_object()
        if (profile != self.profile and not self.is_course_staff):
            raise PermissionDenied()

        points = CachedPoints(self.instance, profile.user, self.content)
        grade = assign_grade(points, design)
        if grade < 0:
            raise PermissionDenied()

        diploma = StudentDiploma.objects.filter(design=design, profile=profile).first()
        if not diploma:
            diploma = StudentDiploma(design=design, profile=profile)
            diploma.generate_hashkey()

        diploma.name = profile.user.get_full_name()
        diploma.grade = grade
        diploma.save()

        return self.redirect(diploma.get_absolute_url())