Skip to content

Commit

Permalink
enable team editing after registration deadline before the game end
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmasrna1 committed Sep 27, 2024
1 parent a13b2b0 commit 7bd0c80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions kos/templates/kos/change_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ <h2>Zmena údajov tímu</h2>
{% else %}
<div class="answer-alert error">Platbu za súťaž zatiaľ neevidujeme.</div>
{% endif %}

<script>
// TODO: Solve this more properly and also check for this on backend
// Hack to remove the disable attribute of is_online field on submit
// Otherwise the value of is_online is not sent at post and the team
// is marked as offline upon e. g. changing their name after the
// registration ends but before the game concludes.
$("form").submit(function() {
$("input").removeAttr("disabled");
});
</script>
{% endblock %}
12 changes: 9 additions & 3 deletions kos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,25 +420,31 @@ def get_context_data(self, **kwargs):
context['paid'] = (
team.paid if hasattr(team, 'paid') else False
)
context['disabled'] = team.game.year.registration_deadline < now()
context['disabled'] = not team.editable
return context

def post(self, request, *args, **kwargs):
team = self.get_team()
if team is None:
return redirect('kos:game')
if team.game.year.registration_deadline < now():
if not team.editable:
messages.error(
request, 'Tieto údaje nie je možné meniť po skončení registrácie')
return redirect('kos:change-profile')
# TODO: Check that the team did not change their is_online
# status after the registration deadline. Currently this
# is only disabled on frontend but can be bypassed.
return super().post(request, *args, **kwargs)

def get_form(self, form_class=None):
form = super().get_form(form_class)
team = self.get_team()
if team.game.year.registration_deadline < now():
if not team.editable:
for field in form.fields.values():
field.widget.attrs['disabled'] = True
# Po konci registracie uz nechceme timu dovolit menit ci je online
if team.game.year.registration_deadline < now():
form.fields['is_online'].widget.attrs['disabled'] = True
return form

def form_valid(self, form):
Expand Down

0 comments on commit 7bd0c80

Please sign in to comment.