Skip to content

Commit

Permalink
Fix private contest error page after #1039
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher authored and Xyene committed Oct 27, 2019
1 parent 86ee0b1 commit b56f159
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 6 additions & 5 deletions judge/views/contests.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ def get_context_data(self, **kwargs):


class PrivateContestError(Exception):
def __init__(self, name, private_users, orgs):
def __init__(self, name, is_private, is_organization_private, orgs):
self.name = name
self.private_users = private_users
self.is_private = is_private
self.is_organization_private = is_organization_private
self.orgs = orgs


Expand Down Expand Up @@ -188,8 +189,8 @@ def get_object(self, queryset=None):
raise Http404()

if contest.is_private or contest.is_organization_private:
private_contest_error = PrivateContestError(contest.name, contest.private_contestants.all(),
contest.organizations.all())
private_contest_error = PrivateContestError(contest.name, contest.is_private,
contest.is_organization_private, contest.organizations.all())
if profile is None:
raise private_contest_error
if user.has_perm('judge.edit_all_contest'):
Expand All @@ -214,7 +215,7 @@ def dispatch(self, request, *args, **kwargs):
_('Could not find such contest.'))
except PrivateContestError as e:
return render(request, 'contest/private.html', {
'orgs': e.orgs, 'title': _('Access to contest "%s" denied') % escape(e.name),
'error': e, 'title': _('Access to contest "%s" denied') % escape(e.name),
}, status=403)


Expand Down
24 changes: 17 additions & 7 deletions templates/contest/private.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{% extends "base.html" %}

{% block body %}
<p>{{ _('Only the following organizations may access this contest:') }}</p>
<ul>
{% for org in orgs %}
<li><a href="{{ org.get_absolute_url() }}">{{ org.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}
{% if error.is_private %}
<p><i>{{ _('This contest is private to specific users.') }}</i></p>
{% endif %}

{% if error.is_organization_private %}
{% if error.is_private %}
<p>{{ _('Additionally, only the following organizations may access this contest:') }}</p>
{% else %}
<p>{{ _('Only the following organizations may access this contest:') }}</p>
{% endif %}
<ul>
{% for org in error.orgs %}
<li><a href="{{ org.get_absolute_url() }}">{{ org.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

0 comments on commit b56f159

Please # to comment.