Skip to content
Snippets Groups Projects
Commit ad3af33f authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Change definition of submissiion pool and fixed error messages

parent e440f555
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,6 @@ from django.db.models import Q ...@@ -50,7 +50,6 @@ from django.db.models import Q
SLUG_LENGTH = 16 SLUG_LENGTH = 16
def random_slug(): def random_slug():
return ''.join(sample(ascii_lowercase, SLUG_LENGTH)) return ''.join(sample(ascii_lowercase, SLUG_LENGTH))
...@@ -125,7 +124,7 @@ class Submission(models.Model): ...@@ -125,7 +124,7 @@ class Submission(models.Model):
) )
@classmethod @classmethod
def assign_tutor(cls, tutor, type_slug=None) -> bool: def assign_tutor(cls, tutor, slug=None) -> bool:
"""Assigns a tutor to a submission """Assigns a tutor to a submission
A submission is not assigned to the specified tutor in the case A submission is not assigned to the specified tutor in the case
...@@ -144,18 +143,27 @@ class Submission(models.Model): ...@@ -144,18 +143,27 @@ class Submission(models.Model):
if unfinished: if unfinished:
return False return False
ready = cls.objects.filter(feedback__isnull=True) candidates = cls.objects.filter(
(
Q(feedback__isnull=True)
| Q(feedback__origin=Feedback.DID_NOT_COMPILE)
| Q(feedback__origin=Feedback.COULD_NOT_LINK)
)
& ~Q(feedback__of_tutor=tutor)
)
# we want a submission of a specific type
if slug:
candidates = candidates.filter(type__slug=slug)
# we do not want this tutor to correct the same submission twice # we couldn't find any submission to correct
if type_slug: if not candidates:
ready = ready.filter(type__slug=type_slug)
ready = ready.exclude(feedback__of_tutor=tutor)
if not ready:
return False return False
submission = ready[0] submission = candidates[0]
feedback = Feedback() feedback = submission.feedback if hasattr(submission, 'feedback') else Feedback()
feedback.origin = Feedback.MANUAL feedback.origin = Feedback.MANUAL
feedback.status = Feedback.EDITABLE
feedback.of_tutor = tutor feedback.of_tutor = tutor
feedback.of_submission = submission feedback.of_submission = submission
feedback.save() feedback.save()
......
{# This is where all the messages pop up #} {# This is where all the messages pop up #}
{% if messages %} {% if messages or form.errors %}
<div class="row"> <div class="row">
<div class="col my-2"> <div class="col my-2">
{% for message in messages %} {% for message in messages %}
......
...@@ -72,13 +72,18 @@ class FeedbackEdit(UpdateView): ...@@ -72,13 +72,18 @@ class FeedbackEdit(UpdateView):
# ugly needs patch # ugly needs patch
if 'Next' in self.request.POST['update']: if 'Next' in self.request.POST['update']:
if in_groups(self.request.user, ('Reviewers',)): if in_groups(self.request.user, ('Reviewers',)):
needs_review = Feedback.objects.filter(status=Feedback.NEEDS_REVIEW, of_submission__type=form.instance.of_submission.type)
needs_review = needs_review[0] if needs_review else None needs_review = Feedback.objects.filter(
status=Feedback.NEEDS_REVIEW,
of_submission__type=form.instance.of_submission.type
)
if needs_review: if needs_review:
return HttpResponseRedirect(reverse('FeedbackEdit', args=(needs_review.slug,))) return HttpResponseRedirect(reverse('FeedbackEdit', args=(needs_review[0].slug,)))
else:
return HttpResponseRedirect(self.get_success_url()) else: # in_groups(self.request.user, ('Tutor',)):
return HttpResponseRedirect(reverse('CreateFeedbackForType', args=(form.instance.of_submission.type.slug,))) return HttpResponseRedirect(reverse('CreateFeedbackForType', args=(form.instance.of_submission.type.slug,)))
return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(self.get_success_url())
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment