Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_assignment_group_from_id(self, assignment_group_id):
try:
assignment_group = AssignmentGroup.objects.get(id=assignment_group_id)
except AssignmentGroup.DoesNotExist():
raise modelimporter.ModelImporterException(
'AssignmentGroup with id {} does not exist.'.format(assignment_group_id))
return assignment_group
def get_model_class(self):
return AssignmentGroup
def __get_upcoming_assignments_as_groups(self):
"""
Get upcoming assignments the next seven days from now.
Returns:
QuerySet: ``AssignmentGroup`` query set.
"""
now = timezone.now()
days_from_now = timezone.now() + timezone.timedelta(days=7)
queryset = coremodels.AssignmentGroup.objects\
.filter_student_has_access(user=self.request.user)\
.filter_is_active()\
.distinct()\
.select_related(
'parentnode',
'cached_data__last_published_feedbackset',
'cached_data__last_feedbackset',
'cached_data__first_feedbackset') \
.filter(
cached_data__last_feedbackset__deadline_datetime__gte=now,
cached_data__last_feedbackset__deadline_datetime__lte=days_from_now) \
.order_by('cached_data__last_feedbackset__deadline_datetime')\
.prefetch_assignment_with_points_to_grade_map(
assignmentqueryset=Assignment.objects.select_related('parentnode__parentnode'))
return queryset
def _get_group(self, group_id):
try:
return AssignmentGroup.objects.get(parentnode=self.assignment_id,
id=group_id)
except AssignmentGroup.DoesNotExist:
raise NotFoundError(('Group with assignment_id={assignment_id} and '
'id={group_id} not found').format(assignment_id=self.assignment_id,
group_id=group_id))
class AssignmentGroupModelSerializer(serializer_base.BaseAssignmentGroupSerializer):
#: Candidates in assignment group
candidates = CandidateSerializer(many=True, required=False)
#: Examiners in assignment group
examiners = ExaminerSerializer(many=True, required=False)
class Meta:
read_only_fields = ('candidates',
'examiners',
'is_waiting_for_feedback',
'is_waiting_for_deliveries',
'is_corrected',)
model = AssignmentGroup
fields = [
'id',
'name',
'assignment_id',
'assignment_short_name',
'subject_short_name',
'period_short_name',
'short_displayname',
'long_displayname',
'is_waiting_for_feedback',
'is_waiting_for_deliveries',
'is_corrected',
'candidates',
'examiners',
]
"""
The form we use for validation and selected items extractions
when the user submits their selection.
It is just a plain Django form (can also be a ModelForm). You
just have to make sure that the name of the form field (``selected_items``)
matches the value returned by ``get_inputfield_name()`` in the
``SelectableProductItemValue`` class.
"""
invalid_students_selected_message = pgettext_lazy(
'admin group multiselect submit',
'Something went wrong. This may happen if changes was made to the selected '
'students while you where working on them. Please try again.')
selected_items = forms.ModelMultipleChoiceField(
queryset=AssignmentGroup.objects.none(),
error_messages={
'invalid_choice': invalid_students_selected_message,
}
)
def __init__(self, *args, **kwargs):
selectable_groups_queryset = kwargs.pop('selectable_groups_queryset')
super(SelectedGroupsForm, self).__init__(*args, **kwargs)
self.fields['selected_items'].queryset = selectable_groups_queryset
class BaseMultiselectView(GroupViewMixin, multiselect2view.ListbuilderFilterView):
template_name = 'devilry_admin/assignment/students/groupview_base/base-multiselect-view.django.html'
def get_value_renderer_class(self):
devilryrole = self.request.cradmin_instance.get_devilryrole_for_requestuser()
def get_queryset(self, assignment, relatedexaminer):
queryset = coremodels.AssignmentGroup.objects \
.filter(parentnode_id=assignment.id) \
.filter_user_is_examiner(user=relatedexaminer.user)
return queryset
@classmethod
def published_where_is_candidate(cls, user_obj, old=True, active=True):
""" Returns a QuerySet matching all :ref:`published
` assignment groups where the given user
is student.
:param user_obj: A django.contrib.auth.models.User_ object.
:rtype: QuerySet
"""
return AssignmentGroup.objects.filter(
cls.q_is_candidate(user_obj) &
cls.q_published(old=old, active=active))
def _query_groups_by_id(self, groupids):
qry = AssignmentGroup.objects.filter(id__in=groupids)
qry = qry.select_related('feedback')
qry = qry.prefetch_related(
'deadlines',
'tags',
'examiners', 'examiners__user',
'examiners__user__devilryuserprofile',
'candidates', 'candidates__student',
'candidates__student__devilryuserprofile')
return qry.all()
class Deadline(models.Model):
"""
.. attribute:: assignment_group
The assignment group where the deadline is registered.
.. attribute:: deadline
The deadline a DateTimeField.
.. attribute:: text
A optional deadline text.
"""
assignment_group = models.ForeignKey(AssignmentGroup,
related_name='deadlines')
deadline = models.DateTimeField()
text = models.TextField(blank=True, null=True)
class Meta:
verbose_name = _('Deadline')
verbose_name_plural = _('Deadlines')
ordering = ['-deadline']
def clean(self, *args, **kwargs):
"""Validate the deadline.
Always call this before save()! Read about validation here:
http://docs.djangoproject.com/en/dev/ref/models/instances/#id1
Raises ValidationError if: