Allow clone ended contests

This commit is contained in:
cuom1999 2023-10-16 17:37:52 -05:00
parent 1291d750de
commit 35756d2f15
7 changed files with 659 additions and 620 deletions

View file

@ -441,16 +441,32 @@ class ContestDetail(
.add_i18n_name(self.request.LANGUAGE_CODE)
)
context["editable_organizations"] = self.get_editable_organizations()
context["is_clonable"] = is_contest_clonable(self.request, self.object)
return context
class ContestClone(
ContestMixin, PermissionRequiredMixin, TitleMixin, SingleObjectFormView
):
def is_contest_clonable(request, contest):
if not request.profile:
return False
if not Organization.objects.filter(admins=request.profile).exists():
return False
if request.user.has_perm("judge.clone_contest"):
return True
if contest.ended:
return True
return False
class ContestClone(ContestMixin, TitleMixin, SingleObjectFormView):
title = _("Clone Contest")
template_name = "contest/clone.html"
form_class = ContestCloneForm
permission_required = "judge.clone_contest"
def get_object(self, queryset=None):
contest = super().get_object(queryset)
if not is_contest_clonable(self.request, contest):
raise Http404()
return contest
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()

File diff suppressed because it is too large Load diff

View file

@ -39,12 +39,6 @@ msgstr "Đăng ký tên"
msgid "Report"
msgstr "Báo cáo"
msgid "Insert Image"
msgstr "Chèn hình ảnh"
msgid "Save"
msgstr "Lưu"
msgid "2sat"
msgstr ""
@ -600,3 +594,8 @@ msgstr ""
msgid "z-function"
msgstr ""
#~ msgid "Insert Image"
#~ msgstr "Chèn hình ảnh"
#~ msgid "Save"
#~ msgstr "Lưu"

View file

@ -383,7 +383,7 @@
<footer>
<span id="footer-content">
<br>
<a class="background-footer" target="_blank" href="https://dmoj.ca">proudly powered by <b>DMOJ</b></a><a target="_blank" href="https://github.com/LQDJudge/online-judge"> | developed by LQDJudge team</a> |
<a class="background-footer" target="_blank" href="https://dmoj.ca">proudly powered by <b>DMOJ</b></a>|<a target="_blank" href="https://github.com/LQDJudge/online-judge"> developed by LQDJudge team</a>
{% if i18n_config.footer %}
{{ i18n_config.footer|safe }} |
{% endif %}

View file

@ -44,7 +44,7 @@
<div><label class="inline-header grayed">{{ _('Enter a new key for the cloned contest:') }}</label></div>
<div id="contest-key-container"><span class="fullwidth">{{ form.key }}</span></div>
<div><label class="inline-header grayed">{{ _('Group:') }}</label></div>
<div><label class="inline-header grayed">{{ _('Group') }}:</label></div>
{{form.organization}}
{% if form.organization.errors %}
<div id="form-errors">

View file

@ -36,7 +36,4 @@
{% endif %}
{{ make_tab_item('edit', 'fa fa-edit', url('admin:judge_contest_change', contest.id), _('Edit')) }}
{% endif %}
{% if perms.judge.clone_contest %}
{{ make_tab_item('clone', 'fa fa-copy', url('contest_clone', contest.key), _('Clone')) }}
{% endif %}
</div>

View file

@ -82,11 +82,16 @@
{{ contest.description|markdown|reference|str|safe }}
{% endcache %}
</div>
{% if editable_organizations %}
<div>
{% if editable_organizations or is_clonable %}
<div style="display: flex; gap: 0.5em;">
{% for org in editable_organizations %}
<span> [<a href="{{ url('organization_contest_edit', org.id , org.slug , contest.key) }}">{{ _('Edit in') }} {{org.slug}}</a>]</span>
{% endfor %}
{% if is_clonable %}
<span>
[<a href="{{url('contest_clone', contest.key)}}"}}>{{_('Clone')}}</a>]
</span>
{% endif %}
</div>
{% endif %}