How to use the devilry.apps.core.models.Assignment function in devilry

To help you get started, we’ve selected a few devilry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devilry / devilry-django / devilry / devilry_admin / views / period / createassignment.py View on Github external
def __get_selected_assignment_from_import_option(self, student_import_option):
        try:
            assignment_id = int(student_import_option.split('_')[0])
        except ValueError:
            raise ValidationError(_('Something went wrong'))
        try:
            assignment = Assignment.objects\
                .filter_is_active()\
                .filter(parentnode=self.period)\
                .get(id=assignment_id)
        except Assignment.DoesNotExist:
            raise Http404()
        return assignment
github devilry / devilry-django / src / devilry_examiner / devilry_examiner / views / allgroupsoverview.py View on Github external
context = super(CorrectedOverview, self).get_context_data(**kwargs)

        groups = context['allgroups']
        groups = groups.filter_by_status('corrected')
        paginator = Paginator(groups, 100, orphans=2)

        page = self.request.GET.get('page')

        context['groups'] = get_paginated_page(self._get_paginator(groups), page)

        return context



class WaitingForFeedbackOrAllRedirectView(SingleObjectMixin, View):
    model = Assignment
    context_object_name = 'assignment'
    pk_url_kwarg = 'assignmentid'

    def get(self, *args, **kwargs):
        assignment = self.get_object()
        has_waiting_for_feedback = AssignmentGroup.objects\
            .filter_examiner_has_access(self.request.user)\
            .filter(parentnode=assignment)\
            .filter_waiting_for_feedback().exists()
        if has_waiting_for_feedback:
            viewname = 'devilry_examiner_waiting_for_feedback'
        else:
            viewname = 'devilry_examiner_allgroupsoverview'
        return redirect(viewname, assignmentid=assignment.id)

    def get_queryset(self):
github devilry / devilry-django / devilry / devilry_examiner / views / bulkviewbase.py View on Github external
1. The form wrapping the publish button. This form has the view as POST url and the group
       IDs and any other options (first given in the options form), in hidden fields.
    2. The form wrapping the edit draft button. This form has the edit draft view as the
       POST url and the group IDs and any other options (first given in the options form),
       in hidden fields.

    As we can see, the common feature of the forms is that they forward the data first given
    in the options form. Handling this is easy:

    1. Make sure all primary forms inherit from the options form.
    2. Make sure to initialize all primary forms with ``request.POST`` as input.
       We handle this automatically.
    3. Only validate the submitted form.
       We handle this automatically.
    """
    model = Assignment
    pk_url_kwarg = 'assignmentid'
    context_object_name = 'assignment'

    #: We only allow POST requests
    http_method_names = ['post']

    #: The form used to parse initial options.
    optionsform_class = OptionsForm

    #: Dictionary mapping submit button name to primary form class.
    primaryform_classes = {}

    #: Reselect the originally selected groups when redirecting back to the overview?
    #: Setting this to ``False`` deletes selected_group_ids from the session in submitted_primaryform_valid().
    reselect_groups_on_success = True
github devilry / devilry-django / devilry / devilry_admin / views / assignment / gradingconfiguration.py View on Github external
'The grade to points table must have at least 2 rows. The first row must '
            'have 0 as points.'
        ),
        'max_points_too_small_for_point_to_grade_map': ugettext_lazy(
            'The grade to points table has points that is larger than the '
            'maximum number of points.'
        ),
        'max_points_larger_than_passing_grade_min_points': ugettext_lazy(
            'Must be larger than the minimum number of points required to pass.'
        )
    }

    grading_system_plugin_id = forms.ChoiceField(
        required=True,
        widget=forms.RadioSelect(),
        choices=Assignment.GRADING_SYSTEM_PLUGIN_ID_CHOICES,
        label=pgettext_lazy(
            'assignment config', 'Examiner chooses')
    )
    points_to_grade_mapper = forms.ChoiceField(
        required=True,
        widget=forms.RadioSelect(),
        choices=Assignment.POINTS_TO_GRADE_MAPPER_CHOICES,
        label=pgettext_lazy(
            'assignment config', 'Students see')
    )
    passing_grade_min_points = forms.IntegerField(
        required=True,
        min_value=0,
        label=pgettext_lazy(
            'assignment config',
            'Minimum number of points required to pass')
github devilry / devilry-django / devilry / apps / guiexamples / views.py View on Github external
@login_required
def assignment_avg_labels(request):
    qry = Assignment.where_is_admin_or_superadmin(request.user).order_by("publishing_time")
    labels = [dict(value=i+1, text=x[0]) \
            for i, x in enumerate(qry.values_list("short_name"))]
    json = JSONEncoder(ensure_ascii=False, indent=2).encode(labels)
    return HttpResponse(json, content_type="application/json")
github devilry / devilry-django / devilry / devilry_merge_v3database / utils / merger.py View on Github external
Get :obj:`devilry.apps.core.models.Assignment` by ``shortname`` from current default database.

        Args:
            short_name: Short name of the assignment to migrate.
            parentnode_short_name: Short name of the assignments period
            parentnode_parentnode_short_name: Short name of the assignments periods subject.

        Returns:
            :obj:`devilry.apps.core.models.Assignment`: Instance or ``None``.
        """
        try:
            return core_models.Assignment.objects\
                .get(parentnode__parentnode__short_name=parentnode_parentnode_shortname,
                     parentnode__short_name=parentnode_shortname,
                     short_name=shortname)
        except core_models.Assignment.DoesNotExist:
            return None
github devilry / devilry-django / devilry / devilry_admin / views / period / crinstance_period.py View on Github external
"""
        Check if an admin should be restricted access to due being a
        period-admin only and the period has one or more semi-anonymous
        assignments

        This method can be used to check whether access should be restricted for
        some elements, e.g. in a view or a template.

        Returns:
            (bool): ``True`` if access should be restriced, else ``False``.
        """
        devilryrole = self.get_devilryrole_for_requestuser(period=period)
        period = period or self.request.cradmin_role
        semi_anonymous_assignments_exist = Assignment.objects\
            .filter(parentnode=period)\
            .filter(anonymizationmode=Assignment.ANONYMIZATIONMODE_SEMI_ANONYMOUS)\
            .exists()
        if semi_anonymous_assignments_exist and devilryrole == PermissionGroup.GROUPTYPE_PERIODADMIN:
            return True
        return False