Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _find_assignment(self):
from devilry.apps.core.models import Assignment
subject_short_name, period_short_name, assignment_short_name = self.assignmentpath.split('.')
self.assignment = Assignment.objects.get(
short_name=assignment_short_name,
parentnode__short_name=period_short_name,
parentnode__parentnode__short_name=subject_short_name)
setupexaminers_mode, copyfromassignment_id=None,
user=None, only_copy_passing_groups=False):
if setupstudents_mode == 'do_not_setup':
return
if not first_deadline and assignment.delivery_types != NON_ELECTRONIC:
raise BadRequestFieldError('first_deadline',
_('Required when adding students.'))
if setupstudents_mode == 'allrelated':
autosetup_examiners = setupexaminers_mode == 'bytags'
self._add_all_relatedstudents(assignment, first_deadline,
autosetup_examiners)
elif setupstudents_mode == 'copyfromassignment':
if not isinstance(copyfromassignment_id, int):
raise BadRequestFieldError('copyfromassignment_id', 'Must be an int, got {0!r}'.format(copyfromassignment_id))
try:
copyfromassignment = Assignment.objects.get(id=copyfromassignment_id,
parentnode=assignment.parentnode)
except Assignment.DoesNotExist:
raise BadRequestFieldError('copyfromassignment_id', 'Assignment with id={0} does not exist in this period.'.format(copyfromassignment_id))
else:
copy_examiners = False
if setupexaminers_mode == 'copyfromassignment':
copy_examiners = True
self._copy_students_from_assignment(assignment, first_deadline,
copyfromassignment,
copy_examiners=copy_examiners,
only_copy_passing_groups=only_copy_passing_groups)
else:
raise BadRequestFieldError('setupexaminers_mode', 'Invalid value: {0}'.format(setupstudents_mode))
setupexaminers_mode, copyfromassignment_id=None,
user=None, only_copy_passing_groups=False):
if setupstudents_mode == 'do_not_setup':
return
if not first_deadline and assignment.delivery_types != NON_ELECTRONIC:
raise BadRequestFieldError('first_deadline',
_('Required when adding students.'))
if setupstudents_mode == 'allrelated':
autosetup_examiners = setupexaminers_mode == 'bytags'
self._add_all_relatedstudents(assignment, first_deadline,
autosetup_examiners)
elif setupstudents_mode == 'copyfromassignment':
if not isinstance(copyfromassignment_id, int):
raise BadRequestFieldError('copyfromassignment_id', 'Must be an int, got {0!r}'.format(copyfromassignment_id))
try:
copyfromassignment = Assignment.objects.get(id=copyfromassignment_id,
parentnode=assignment.parentnode)
except Assignment.DoesNotExist:
raise BadRequestFieldError('copyfromassignment_id', 'Assignment with id={0} does not exist in this period.'.format(copyfromassignment_id))
else:
copy_examiners = False
if setupexaminers_mode == 'copyfromassignment':
copy_examiners = True
self._copy_students_from_assignment(assignment, first_deadline,
copyfromassignment,
copy_examiners=copy_examiners,
only_copy_passing_groups=only_copy_passing_groups)
else:
raise BadRequestFieldError('setupexaminers_mode', 'Invalid value: {0}'.format(setupstudents_mode))
def dispatch(self, request, *args, **kwargs):
try:
self.from_assignment = Assignment.objects.get(id=kwargs.get('from_assignment_id'))
except Assignment.DoesNotExist:
raise Http404()
return super(ConfirmView, self).dispatch(request, *args, **kwargs)
def get_period_id(self):
assignment_id = self.kwargs['assignment_id']
assignment = Assignment.objects.get(id=assignment_id)
return assignment.parentnode_id
def read_authorize(cls, user, obj):
try:
Assignment.objects.get(Assignment.q_is_examiner(user) & Q(id=obj.id))
except Assignment.DoesNotExist:
raise PermissionDenied()
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
def _get_assignment(self, id):
try:
return Assignment.objects.get(id=id)
except Assignment.DoesNotExist:
raise NotFoundError('Assignment with id={0} not found'.format(id))