forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
37 lines (32 loc) · 1.31 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.http import Http404, HttpResponse
from course.viewbase import CourseInstanceMixin
from lib.viewbase import BaseRedirectView
from .models import Notification
class NotificationRedirectView(CourseInstanceMixin, BaseRedirectView):
notification_kw = "notification_id"
def get_resource_objects(self):
super().get_resource_objects()
nid = self._get_kwarg(self.notification_kw)
self.notification = Notification.objects.filter(
id=nid,
course_instance=self.instance,
).select_related("submission__exercise").first()
if not self.notification:
raise Http404()
def get(self, request, *args, **kwargs):
self.notification.seen = True
self.notification.save()
submission = self.notification.submission
# Sends an update to Jutut that the feedback response has been seen.
if self.notification.regrade_when_seen:
submission.exercise.grade(submission)
if self.notification.submission:
return self.redirect(
self.notification.submission.get_url('submission-plain')
)
return HttpResponse(
"[Old Notification] {}: {}".format(
self.notification.subject,
self.notification.notification,
)
)