forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
34 lines (29 loc) · 1.16 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
from django.http import Http404, HttpResponse
from authorization.permissions import ACCESS
from course.viewbase import CourseInstanceBaseView, 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()
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,
)
)