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_queryset(self):
return Assignment.objects.filter_admin_has_access(self.request.user)\
.select_related(
'parentnode', # Period
'parentnode__parentnode') # Subject
def get_context_data(self, **kwargs):
context = super(DashboardView, self).get_context_data(**kwargs)
active_assignments = Assignment.objects\
.filter_examiner_has_access(self.request.user)\
.order_by('-publishing_time')\
.select_related('parentnode', 'parentnode__parentnode', 'examiners')\
.annotate(count_total_groups=Count('assignmentgroups'))
context['active_assignments'] = map(self._add_statistics, active_assignments)
return context
def _get_assignment(self):
return Assignment.objects\
.filter(id=self.feedbackset.group.assignment.id)\
.prefetch_point_to_grade_map()\
def assignment_count( self, instance ):
return Assignment.objects.filter(parentnode__parentnode__parentnode=instance).count()
**NOTE**: If the assignment has ``first_deadline`` set, the deadline will be created.
This will set ``is_open`` to ``true`` even if the ``is_open``-parameter
is set to ``false``. We have not made a workaround for this, since setting
``is_open=False`` when creating a group have no know use-cases, and a workaround
would require one extra save.
# Returns
An object/map with the following attributes:
{responsetable}
"""
datalist = self.CONTENT
created_groups = []
usercache = {}
try:
assignment = Assignment.objects.filter(id=assignment_id)\
.select_related(
'parentnode',
'parentnode__parentnode')\
.prefetch_related(
'admins',
'parentnode__admins',
'parentnode__parentnode__admins'
)\
.get()
except Assignment.DoesNotExist:
raise NotFoundError('No assignment with ID={} exists.'.format(assignment_id))
with transaction.commit_on_success():
for data in datalist:
try:
manager = GroupManager(request.user, assignment, createmode=True, usercache={})
def get_assignment_by_shortname(self, parentnode_shortname, parentnode_parentnode_shortname, shortname):
"""
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
def period_admin_access_semi_anonymous_assignments_restricted(self, period=None):
"""
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
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_queryset(self):
return Assignment.objects.filter_examiner_has_access(self.request.user)
def _get_assignment_type(self, *args, **kwargs):
assignmentid = kwargs.get('assignmentid')
assignment = Assignment.objects.get(id=assignmentid)
assignment_type = "normal"
if assignment.anonymous:
assignment_type = "anonymous"
return assignment_type