Reformat using black

This commit is contained in:
cuom1999 2022-05-14 12:57:27 -05:00
parent efee4ad081
commit a87fb49918
221 changed files with 19127 additions and 7310 deletions

View file

@ -7,46 +7,48 @@ from django.db.models import BooleanField, Value
from judge.utils.cachedict import CacheDict
from judge.models import Profile, Comment, Notification
__all__ = ['NotificationList']
__all__ = ["NotificationList"]
class NotificationList(ListView):
model = Notification
context_object_name = 'notifications'
template_name = 'notification/list.html'
context_object_name = "notifications"
template_name = "notification/list.html"
def get_queryset(self):
self.unseen_cnt = self.request.profile.count_unseen_notifications
query = {
'owner': self.request.profile,
"owner": self.request.profile,
}
self.queryset = Notification.objects.filter(**query)\
.order_by('-time')[:100] \
.annotate(seen=Value(True, output_field=BooleanField()))
self.queryset = (
Notification.objects.filter(**query)
.order_by("-time")[:100]
.annotate(seen=Value(True, output_field=BooleanField()))
)
# Mark the several first unseen
for cnt, q in enumerate(self.queryset):
if (cnt < self.unseen_cnt):
if cnt < self.unseen_cnt:
q.seen = False
else:
break
return self.queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['unseen_count'] = self.unseen_cnt
context['title'] = _('Notifications (%d unseen)' % context['unseen_count'])
context['has_notifications'] = self.queryset.exists()
context['page_titles'] = CacheDict(lambda page: Comment.get_page_title(page))
context["unseen_count"] = self.unseen_cnt
context["title"] = _("Notifications (%d unseen)" % context["unseen_count"])
context["has_notifications"] = self.queryset.exists()
context["page_titles"] = CacheDict(lambda page: Comment.get_page_title(page))
return context
def get(self, request, *args, **kwargs):
ret = super().get(request, *args, **kwargs)
# update after rendering
Notification.objects.filter(owner=self.request.profile).update(read=True)
return ret
return ret