Contest and Org css
This commit is contained in:
parent
d6832a0550
commit
ba96d83db8
16 changed files with 648 additions and 676 deletions
|
@ -8,6 +8,7 @@ from django.core.cache.utils import make_template_fragment_key
|
|||
from django.db.models.signals import post_delete, post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
import judge
|
||||
from judge.utils.problems import finished_submission
|
||||
from .models import (
|
||||
BlogPost,
|
||||
|
@ -22,6 +23,7 @@ from .models import (
|
|||
Problem,
|
||||
Profile,
|
||||
Submission,
|
||||
NavigationBar,
|
||||
)
|
||||
|
||||
|
||||
|
@ -166,3 +168,8 @@ def contest_submission_update(sender, instance, **kwargs):
|
|||
Submission.objects.filter(id=instance.submission_id).update(
|
||||
contest_object_id=instance.participation.contest_id
|
||||
)
|
||||
|
||||
|
||||
@receiver(post_save, sender=NavigationBar)
|
||||
def navbar_update(sender, instance, **kwargs):
|
||||
judge.template_context._nav_bar.dirty()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from functools import partial
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -7,6 +8,7 @@ from django.core.cache import cache
|
|||
from django.utils.functional import SimpleLazyObject, new_method_proxy
|
||||
|
||||
from .models import MiscConfig, NavigationBar, Profile
|
||||
from judge.caching import cache_wrapper
|
||||
|
||||
|
||||
class FixedSimpleLazyObject(SimpleLazyObject):
|
||||
|
@ -50,22 +52,28 @@ def comet_location(request):
|
|||
return {"EVENT_DAEMON_LOCATION": websocket, "EVENT_DAEMON_POLL_LOCATION": poll}
|
||||
|
||||
|
||||
@cache_wrapper(prefix="nb")
|
||||
def _nav_bar():
|
||||
return NavigationBar.objects.all()
|
||||
|
||||
|
||||
def __nav_tab(path):
|
||||
result = list(
|
||||
NavigationBar.objects.extra(where=["%s REGEXP BINARY regex"], params=[path])[:1]
|
||||
)
|
||||
return (
|
||||
result[0].get_ancestors(include_self=True).values_list("key", flat=True)
|
||||
if result
|
||||
else []
|
||||
)
|
||||
nav_bar_list = list(_nav_bar())
|
||||
nav_bar_dict = {nb.id: nb for nb in nav_bar_list}
|
||||
result = next((nb for nb in nav_bar_list if re.match(nb.regex, path)), None)
|
||||
if result:
|
||||
while result.parent_id:
|
||||
result = nav_bar_dict.get(result.parent_id)
|
||||
return result.key
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def general_info(request):
|
||||
path = request.get_full_path()
|
||||
return {
|
||||
"nav_tab": FixedSimpleLazyObject(partial(__nav_tab, request.path)),
|
||||
"nav_bar": NavigationBar.objects.all(),
|
||||
"nav_bar": _nav_bar(),
|
||||
"LOGIN_RETURN_PATH": "" if path.startswith("/accounts/") else path,
|
||||
"perms": PermWrapper(request.user),
|
||||
}
|
||||
|
|
|
@ -184,20 +184,21 @@ class PostView(TitleMixin, CommentedDetailView, PageVoteDetailView, BookMarkDeta
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(PostView, self).get_context_data(**kwargs)
|
||||
context["og_image"] = self.object.og_image
|
||||
context["valid_user_to_show_edit"] = False
|
||||
context["valid_org_to_show_edit"] = []
|
||||
context["editable_orgs"] = []
|
||||
|
||||
if self.request.profile in self.object.authors.all():
|
||||
context["valid_user_to_show_edit"] = True
|
||||
can_edit = False
|
||||
if self.request.profile.id in self.object.get_authors():
|
||||
can_edit = True
|
||||
|
||||
for valid_org_to_show_edit in self.object.organizations.all():
|
||||
if self.request.profile in valid_org_to_show_edit.admins.all():
|
||||
context["valid_user_to_show_edit"] = True
|
||||
orgs = list(self.object.organizations.all())
|
||||
for org in orgs:
|
||||
if org.is_admin(self.request.profile):
|
||||
can_edit = True
|
||||
|
||||
if context["valid_user_to_show_edit"]:
|
||||
for post_org in self.object.organizations.all():
|
||||
if post_org in self.request.profile.organizations.all():
|
||||
context["valid_org_to_show_edit"].append(post_org)
|
||||
if can_edit:
|
||||
for org in orgs:
|
||||
if org.is_member(self.request.profile):
|
||||
context["editable_orgs"].append(org)
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
@ -486,9 +486,9 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
).exists()
|
||||
)
|
||||
|
||||
context["has_comments"] = queryset.exists()
|
||||
context["comment_lock"] = self.is_comment_locked()
|
||||
context["comment_list"] = list(queryset)
|
||||
context["has_comments"] = len(context["comment_list"]) > 0
|
||||
|
||||
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
||||
|
||||
|
|
|
@ -235,31 +235,33 @@ class ContestList(
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(ContestList, self).get_context_data(**kwargs)
|
||||
present, active, future = [], [], []
|
||||
for contest in self._get_queryset().exclude(end_time__lt=self._now):
|
||||
if contest.start_time > self._now:
|
||||
future.append(contest)
|
||||
else:
|
||||
present.append(contest)
|
||||
if not context["page_obj"] or context["page_obj"].number == 1:
|
||||
for contest in self._get_queryset().exclude(end_time__lt=self._now):
|
||||
if contest.start_time > self._now:
|
||||
future.append(contest)
|
||||
else:
|
||||
present.append(contest)
|
||||
|
||||
if self.request.user.is_authenticated:
|
||||
for participation in (
|
||||
ContestParticipation.objects.filter(
|
||||
virtual=0, user=self.request.profile, contest_id__in=present
|
||||
)
|
||||
.select_related("contest")
|
||||
.prefetch_related(
|
||||
"contest__authors", "contest__curators", "contest__testers"
|
||||
)
|
||||
.annotate(key=F("contest__key"))
|
||||
):
|
||||
if not participation.ended:
|
||||
active.append(participation)
|
||||
present.remove(participation.contest)
|
||||
if self.request.user.is_authenticated:
|
||||
for participation in (
|
||||
ContestParticipation.objects.filter(
|
||||
virtual=0, user=self.request.profile, contest_id__in=present
|
||||
)
|
||||
.select_related("contest")
|
||||
.prefetch_related(
|
||||
"contest__authors", "contest__curators", "contest__testers"
|
||||
)
|
||||
.annotate(key=F("contest__key"))
|
||||
):
|
||||
if not participation.ended:
|
||||
active.append(participation)
|
||||
present.remove(participation.contest)
|
||||
|
||||
if not ("contest" in self.request.GET and settings.ENABLE_FTS):
|
||||
active.sort(key=attrgetter("end_time", "key"))
|
||||
present.sort(key=attrgetter("end_time", "key"))
|
||||
future.sort(key=attrgetter("start_time"))
|
||||
|
||||
if not ("contest" in self.request.GET and settings.ENABLE_FTS):
|
||||
active.sort(key=attrgetter("end_time", "key"))
|
||||
present.sort(key=attrgetter("end_time", "key"))
|
||||
future.sort(key=attrgetter("start_time"))
|
||||
context["active_participations"] = active
|
||||
context["current_contests"] = present
|
||||
context["future_contests"] = future
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue