Contest and Org css

This commit is contained in:
cuom1999 2024-04-23 15:36:51 -05:00
parent d6832a0550
commit ba96d83db8
16 changed files with 648 additions and 676 deletions

View file

@ -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()

View file

@ -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),
}

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -240,6 +240,7 @@ a.view-pdf {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
align-items: center;
.spacer {
display: inline-block;

View file

@ -9,14 +9,10 @@
box-sizing: border-box;
display: flex;
.info-contest:first-child {
.info-contest:first-child, .info-contest:nth-child(2) {
margin-right: 15px;
}
.info-contest:nth-child(2) {
margin-right: 5px;
}
.info-contest {
flex: 1;
}
@ -155,64 +151,21 @@
.time-left {
text-align: left;
color: #777;
padding-top: 0.5em;
padding-bottom: 0.5em;
}
.contest-list {
td {
vertical-align: middle !important;
&:nth-child(2) {
min-width: 4em;
}
&:nth-child(3) {
min-width: 6em;
}
}
tbody tr {
height: 4em;
}
.floating-time-left {
position: absolute;
left: 0;
}
.floating-time-right {
position: absolute;
right: 0;
line-height: 1.2em;
}
.floating-time {
position: absolute;
right: 0;
bottom: 0;
}
.list-contest {
.contest-tags {
padding-left: 0.75em;
vertical-align: top;
display: flex;
flex-wrap: wrap;
margin-top: 5px;
}
.contest-tag-hidden {
background-color: #000000;
color: #ffffff;
}
.participate-button {
display: inline-block;
width: 90px;
}
.contest-block {
text-align: left;
padding: 0.5em 0.5em 0.5em 1em;
}
}
.first-solve {
@ -220,12 +173,14 @@
}
.contest-tag {
box-shadow: inset 0 -0.1em 0 rgba(0, 0, 0, 0.12);
padding: 0.15em 0.3em;
border-radius: 0.15em;
font-weight: 600;
margin-right: 0.45em;
position: relative;
display: flex;
align-items: center;
gap: 0.2em;
}
.contest-tag-edit {

View file

@ -53,3 +53,4 @@
display: block;
color: gray;
}

View file

@ -174,15 +174,15 @@ ul.problem-list {
}
.organization-tag {
box-shadow: inset 0 -0.1em 0 rgba(0, 0, 0, 0.12);
display: flex;
align-items: center;
padding: 0.15em 0.3em;
border-radius: 0.15em;
font-weight: 600;
margin-right: 0.45em;
position: relative;
background-color: #ccc;
transform: translateY(+35%);
display: inline-block;
color: initial;
}
.organization-tag a {

View file

@ -30,8 +30,8 @@
{% if post.is_editable_by(request.user) %}
<span> [<a href="{{ url('admin:judge_blogpost_change', post.id) }}">{{ _('Edit') }}</a>]</span>
{% endif %}
{% if valid_user_to_show_edit %}
{% for org in valid_org_to_show_edit %}
{% if editable_orgs %}
{% for org in editable_orgs %}
<span> [<a href="{{ url('edit_organization_blog', org.id , org.slug , post.id) }}">{{ _('Edit in') }} {{org.slug}}</a>]</span>
{% endfor %}
{% endif %}

View file

@ -1,5 +1,12 @@
{% for post in posts %}
<section class="{% if post.sticky %}sticky {% endif %}blog-box">
{% if post.is_organization_private and show_organization_private_icon %}
<div style="margin-bottom: 1em; display: flex;">
{% for org in post.organizations.all() %}
{% include "organization/tag.html" %}
{% endfor %}
</div>
{% endif %}
<div style="margin-bottom: 0.5em">
<span class="post-content-header time">
{% with authors=post.get_authors() %}
@ -14,18 +21,6 @@
{{ relative_time(post.publish_on) }}
{%- if post.sticky %} &#8226;
<i title="Sticky" class="fa fa-star fa-fw"></i>{% endif -%}
{% if post.is_organization_private and show_organization_private_icon %}
&#8226;
<span>
{% for org in post.organizations.all() %}
<span class="organization-tag" style="display: inherit;">
<a href="{{ org.get_absolute_url() }}">
<i class="fa fa-lock"></i> {{ org.name }}
</a>
</span>
{% endfor %}
</span>
{% endif %}
</span>
<span style="float: right">
<a href="{{ url('blog_post', post.id, post.slug) }}#comments" class="blog-comment-count-link">

View file

@ -80,15 +80,11 @@
<div style="clear: both"></div>
{% if contest.is_organization_private %}
{% for org in contest.organizations.all() %}
<div style="margin-bottom: 1em;">
<span class="contest-tag contest-tag-org">
<a href="{{ org.get_absolute_url() }}">
<i class="fa fa-lock"></i> {{ org.name }}
</a>
</span>
</div>
{% endfor %}
<div style="display: flex; margin-bottom: 1em">
{% for org in contest.organizations.all() %}
{% include "organization/tag.html" %}
{% endfor %}
</div>
{% endif %}
{% if editable_organizations or is_clonable %}

View file

@ -9,10 +9,6 @@
padding-top: 0;
}
.content-description ul {
padding: 0 !important;
}
.btn-contest {
display: inline-block;
padding: 1px 6px;
@ -20,6 +16,7 @@
.contest-group-header {
padding-bottom: 1em;
margin-top: 1.5em;
}
{% if page_obj and page_obj.number > 1%}
@ -115,8 +112,7 @@
<a href="{{ url('contest_view', contest.key) }}" class="contest-list-title" style="margin-right: 5px;">
{{contest.name}}
</a>
<br>
<div class="contest-tags" style="margin-top: 5px;">
<div class="contest-tags">
{% if not contest.is_visible %}
<span class="contest-tag contest-tag-hidden">
<i class="fa fa-eye-slash"></i> {{ _('hidden') }}
@ -137,11 +133,7 @@
{% if not hide_contest_orgs %}
{% if contest.is_organization_private %}
{% for org in contest.organizations.all() %}
<span class="contest-tag contest-tag-org">
<a href="{{ org.get_absolute_url() }}">
<i class="fa fa-lock"></i> {{ org.name }}
</a>
</span>
{% include "organization/tag.html" %}
{% endfor %}
{% endif %}
{% endif %}
@ -162,15 +154,22 @@
</div>
{% endmacro %}
{% macro time_left(contest, padding_top = true) %}
<div class="time time-left {{ 'non-padding-top' if padding_top == false }}">
{% macro time_left(contest) %}
<div class="time-left">
{% if contest.time_limit %}
{{ contest.start_time|date(_("M j, Y, G:i")) }} -
{{ contest.end_time|date(_("M j, Y, G:i")) }}
<div>
<b>{{_("Start")}}</b>: {{ contest.start_time|date(_("g:i a d/m/Y")) }}
</div>
<div>
<b>{{_("End")}}</b>: {{ contest.end_time|date(_("g:i a d/m/Y")) }}
</div>
{% else %}
{{ contest.start_time|date(_("M j, Y, G:i")) }}
<div>
<b>{{_("Start")}}</b>: {{ contest.start_time|date(_("g:i a d/m/Y")) }}
</div>
{% endif %}
<br>
</div>
<div class="time">
{% if contest.time_limit %}
{% trans time_limit=contest.time_limit|timedelta('localized-no-seconds') %}{{ time_limit }} window{% endtrans %}
{% else %}
@ -206,48 +205,49 @@
{% endmacro %}
{% block middle_content %}
<div class="content-description">
<form id="filter-form">
<input id="search-contest" type="text" name="contest" value="{{ contest_query or '' }}"
placeholder="{{ _('Search contests...') }}">
{% if organizations %}
<select id="search-org" name="orgs" multiple>
{% for org in organizations %}
<option value="{{ org.id }}"{% if org.id in org_query %} selected{% endif %}>
{{ org.name }}
</option>
{% endfor %}
</select>
{% endif %}
<button id="search-btn" class="btn-green small"> {{ _('Search')}} </button>
{% if organizations %}
<div>
<input id="show_orgs" type="checkbox" name="show_orgs" value="1" {% if show_orgs %}checked{% endif %}>
<label for="show_orgs">{{ _('Hide organization contests') }}</label>
</div>
{% endif %}
{% if create_url %}
<a href="{{create_url}}" class="button small" style="float: right"><i class="fa fa-plus"></i> {{ _('Create')}}</a>
{% endif %}
</form>
<form id="filter-form">
<input id="search-contest" type="text" name="contest" value="{{ contest_query or '' }}"
placeholder="{{ _('Search contests...') }}">
{% if organizations %}
<select id="search-org" name="orgs" multiple>
{% for org in organizations %}
<option value="{{ org.id }}"{% if org.id in org_query %} selected{% endif %}>
{{ org.name }}
</option>
{% endfor %}
</select>
{% endif %}
<button id="search-btn" class="btn-green small"> {{ _('Search')}} </button>
{% if organizations %}
<div>
<input id="show_orgs" type="checkbox" name="show_orgs" value="1" {% if show_orgs %}checked{% endif %}>
<label for="show_orgs">{{ _('Hide organization contests') }}</label>
</div>
{% endif %}
{% if create_url %}
<a href="{{create_url}}" class="button small" style="float: right"><i class="fa fa-plus"></i> {{ _('Create')}}</a>
{% endif %}
</form>
<div id="ongoing-table">
{% if active_participations %}
<h3 class="toggle open contest-group-header">
<i class="fa fa-chevron-right fa-fw"></i>
{{ _('Active Contests') }}
</h3>
<div class="toggled">
{% for participation in active_participations %}
{% with contest=participation.contest %}
<div class="list-contest">
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Contests') }} </div>
{{ contest_head(contest) }}
</div>
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Time') }} </div>
<div class="contest-block">
{% if contest.start_time %}
{{ time_left(contest) }}
{% if contest.time_limit %}
<span class="time">
{% trans countdown=participation.end_time|as_countdown %}Window ends in {{countdown}}{% endtrans %}
@ -255,15 +255,14 @@
{% elif contest.time_before_end %}
<span class="time">{% trans countdown=contest.end_time|as_countdown %}Ends in {{countdown}}{% endtrans %}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}
</div>
</div>
<div class="info-contest">
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Format') }} </div>
{{ contest.format.name }}
</div>
<div class="info-contest">
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Users') }} </div>
{{ user_count(contest, request.user) }}
</div>
@ -274,7 +273,6 @@
{% endwith %}
{% endfor %}
</div>
<br>
{% endif %}
<h3 class="toggle open contest-group-header">
@ -282,29 +280,29 @@
{{ _('Ongoing Contests') }}
</h3>
{% if current_contests %}
<div id="ongoing-table" class="toggled">
<div class="toggled">
{% for contest in current_contests %}
<div class="list-contest">
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Contests') }} </div>
{{ contest_head(contest) }}
</div>
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Time') }} </div>
<div class="contest-block">
{% if contest.start_time %}
{{ time_left(contest) }}
{% if contest.time_before_end %}
<span class="time">{% trans countdown=contest.end_time|as_countdown %}Ends in {{countdown}}{% endtrans %}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}
</div>
</div>
<div class="info-contest">
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Format') }} </div>
{{ contest.format.name }}
</div>
<div class="info-contest">
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Users') }} </div>
{{ user_count(contest, request.user) }}
</div>
@ -313,12 +311,11 @@
</div>
</div>
{% endfor %}
<br>
</div>
{% else %}
<div class="toggled">
<i> {{ _('There is no ongoing contest at this time.') }} </i>
<br>
<br><br>
</div>
{% endif %}
@ -330,22 +327,22 @@
<div class="toggled">
{% for contest in future_contests %}
<div class="list-contest">
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Contests') }} </div>
{{ contest_head(contest) }}
</div>
<div class="info-contest" style="flex: 1.5">
<div class="info-contest">
<div class="contest-title"> {{ _('Time') }} </div>
<div class="contest-block">
{% if contest.start_time %}
{{ time_left(contest) }}
{% if contest.time_before_start %}
<span class="time">{{ _('Starting in %(countdown)s.', countdown=contest.start_time|as_countdown) }}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}
</div>
</div>
<div class="info-contest">
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Format') }} </div>
{{ contest.format.name }}
</div>
@ -355,62 +352,61 @@
{% else %}
<div class="toggled">
<i>{{ _('There is no scheduled contest at this time.') }}</i>
<br>
</div>
{% endif %}
<br>
<h3 class="toggle open contest-group-header">
{{ _('Past Contests') }}
</h3>
{% if past_contests %}
{% if page_obj and page_obj.num_pages > 1 %}
<div style="margin-bottom: 10px;">
{% include "list-pages.html" %}
</div>
{% endif %}
{% for contest in past_contests %}
<div class="list-contest">
<div class="info-contest" style="flex: 1.5">
<div class="contest-title"> {{ _('Contests') }} </div>
{{ contest_head(contest) }}
</div>
<div class="info-contest" style="flex: 1.5">
<div class="contest-title"> {{ _('Time') }} </div>
<div class="contest-block">
{{ time_left(contest, false) }}
</div>
</div>
<div class="info-contest">
<div class="contest-title"> {{ _('Format') }} </div>
{{ contest.format.name }}
</div>
<div class="info-contest">
<div class="contest-title"> {{ _('Users') }} </div>
{{ user_count(contest, request.user) }}
</div>
{% if not request.in_contest %}
<div class="participate-button">
<form action="{{ url('contest_join', contest.key) }}" method="post">
{% csrf_token %}
<input type="submit" class="unselectable button full small"
value="{{ _('Virtual join') }}">
</form>
</div>
{% endif %}
</div>
{% endfor %}
{% if page_obj and page_obj.num_pages > 1 %}
<div style="margin-top: 10px;">
{% include "list-pages.html" %}
</div>
{% endif %}
{% else %}
<div class="toggled">
<i> {{ _('There is no past contest.') }} </i>
<br>
<br><br>
</div>
{% endif %}
</div>
<h3 class="toggle open contest-group-header">
{{ _('Past Contests') }}
</h3>
{% if past_contests %}
{% if page_obj and page_obj.num_pages > 1 %}
<div style="margin-bottom: 10px;">
{% include "list-pages.html" %}
</div>
{% endif %}
{% for contest in past_contests %}
<div class="list-contest">
<div class="info-contest">
<div class="contest-title"> {{ _('Contests') }} </div>
{{ contest_head(contest) }}
</div>
<div class="info-contest">
<div class="contest-title"> {{ _('Time') }} </div>
<div class="contest-block">
{{ time_left(contest) }}
</div>
</div>
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Format') }} </div>
{{ contest.format.name }}
</div>
<div class="info-contest" style="flex: 0.5;">
<div class="contest-title"> {{ _('Users') }} </div>
{{ user_count(contest, request.user) }}
</div>
{% if not request.in_contest %}
<div class="participate-button">
<form action="{{ url('contest_join', contest.key) }}" method="post">
{% csrf_token %}
<input type="submit" class="unselectable button full small"
value="{{ _('Virtual join') }}">
</form>
</div>
{% endif %}
</div>
{% endfor %}
{% if page_obj and page_obj.num_pages > 1 %}
<div style="margin-top: 10px;">
{% include "list-pages.html" %}
</div>
{% endif %}
{% else %}
<div class="toggled">
<i> {{ _('There is no past contest.') }} </i>
<br>
</div>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,8 @@
<a href="{{ org.get_absolute_url() }}">
<span class="organization-tag" style="gap: 0.2em;">
{% if org.logo_override_image %}
<img class="user-img" style="height: 1.5em; width: 1.5em;" loading="lazy" src="{{ org.logo_override_image }}">
{% endif %}
{{ org.name }}
</span>
</a>

View file

@ -118,11 +118,7 @@
{% if problem.is_organization_private %}
<span class="organization-tags">
{% for org in problem.organizations.all() %}
<span class="organization-tag">
<a href="{{ org.get_absolute_url() }}">
<i class="fa fa-lock"></i> {{ org.name }}
</a>
</span>
{% include "organization/tag.html" %}
{% endfor %}
</span>
{% endif %}