Skip to content

Commit

Permalink
Merge branches 'coach', 'confirm-delete-draw' and 'bug/2463' into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
tienne-B committed Oct 5, 2024
3 parents cd722ac + 1190ab8 + d6b79df commit 26c50ec
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 57 deletions.
14 changes: 14 additions & 0 deletions tabbycat/draw/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import forms
from django.utils.translation import gettext as _


class ConfirmDrawDeletionForm(forms.Form):
round_name = forms.CharField(label=_("Full round name"), required=True)

def __init__(self, round, **kwargs):
self.round = round
super().__init__(**kwargs)

def clean_round_name(self):
if self.cleaned_data['round_name'] != self.round.name:
raise forms.ValidationError(_("You must type '%s' to confirm draw and results deletion.") % self.round.name)
2 changes: 1 addition & 1 deletion tabbycat/draw/templates/draw_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</a>
</div>
<div class="btn-group flex-wrap" role="group">
<a href="{% roundurl 'draw-confirm-regenerate' %}" class="btn btn-outline-primary">
<a href="{% roundurl 'draw-regenerate' %}" class="btn btn-outline-primary">
{% trans "Redo Draw" %}
</a>
<a href="{% roundurl 'draw-details' %}" class="btn btn-outline-primary">
Expand Down
11 changes: 6 additions & 5 deletions tabbycat/draw/templates/draw_confirm_regeneration.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@

<form method="POST" action="{% roundurl 'draw-regenerate' %}">
{% csrf_token %}
<button class="btn btn-block btn-danger " type="submit">
{% blocktrans trimmed with round=round.name %}
Yes, I want to delete the current draw for {{ round }}
{% endblocktrans %}
</button>
{% include "components/form-main.html" %}

{% blocktrans trimmed with round=round.name asvar title %}
Yes, I want to delete the current draw for {{ round }}
{% endblocktrans %}
{% include "components/form-submit.html" with type='danger' %}
</form>

{% endblock %}
2 changes: 1 addition & 1 deletion tabbycat/draw/templates/draw_status_draft.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load debate_tags i18n standingsformat %}

{% block page-subnav-sections %}
<a href="{% roundurl 'draw-confirm-regenerate' %}" class="btn btn-outline-danger">
<a href="{% roundurl 'draw-regenerate' %}" class="btn btn-outline-danger">
<i data-feather="chevron-left"></i> {% trans "Delete Draw" %}
</a>
<a href="{% roundurl 'edit-debate-teams' round %}" class="btn btn-outline-primary">
Expand Down
5 changes: 1 addition & 4 deletions tabbycat/draw/urls_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
path('confirm/',
views.ConfirmDrawCreationView.as_view(),
name='draw-confirm'),
path('regenerate/confirm/',
views.ConfirmDrawRegenerationView.as_view(),
name='draw-confirm-regenerate'),
path('regenerate/',
views.DrawRegenerateView.as_view(),
views.ConfirmDrawRegenerationView.as_view(),
name='draw-regenerate'),

# Email
Expand Down
26 changes: 17 additions & 9 deletions tabbycat/draw/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy, ngettext
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView

from actionlog.mixins import LogActionMixin
from actionlog.models import ActionLogEntry
Expand Down Expand Up @@ -46,6 +47,7 @@
from venues.utils import venue_conflicts_display

from .dbutils import delete_round_draw
from .forms import ConfirmDrawDeletionForm
from .generator import DrawFatalError, DrawUserError
from .manager import DrawManager
from .models import Debate, TeamSideAllocation
Expand Down Expand Up @@ -732,20 +734,26 @@ def post(self, request, *args, **kwargs):
return super().post(request, *args, **kwargs)


class DrawRegenerateView(DrawStatusEdit):
class ConfirmDrawRegenerationView(LogActionMixin, AdministratorMixin, RoundMixin, FormView):
template_name = "draw_confirm_regeneration.html"
view_permission = Permission.DELETE_DEBATE
form_class = ConfirmDrawDeletionForm

action_log_type = ActionLogEntry.ActionType.DRAW_REGENERATE
round_redirect_pattern_name = 'availability-index'

def post(self, request, *args, **kwargs):
delete_round_draw(self.round)
self.log_action()
messages.success(request, _("Deleted the draw. You can now recreate it as normal."))
return super().post(request, *args, **kwargs)
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['round'] = self.round
return kwargs

def form_valid(self, form):
delete_round_draw(self.round)
messages.success(self.request, _("Deleted the draw. You can now recreate it as normal."))
return super().form_valid(form)

class ConfirmDrawRegenerationView(AdministratorMixin, TemplateView):
template_name = "draw_confirm_regeneration.html"
view_permission = Permission.GENERATE_DEBATE
def get_success_url(self):
return self.get_redirect_url()


class DrawReleaseView(DrawStatusEdit):
Expand Down
1 change: 1 addition & 0 deletions tabbycat/settings/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
MIDDLEWARE = [
'django.middleware.gzip.GZipMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# User language preferences; must be after Session
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/templates/components/form-submit.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="list-group-item pt-4 pb-2">

<button type="submit" name="continue" class="btn btn-block btn-success mb-3">
<button type="submit" name="continue" class="btn btn-block btn-{% if type %}{{ type }}{% else %}success{% endif %} mb-3">
{{ title }}
</button>

Expand Down
12 changes: 7 additions & 5 deletions tabbycat/templates/nav/admin_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@
{% endfor %}

<div class="list-group-item d-inline-block">
<a href="{% url 'logout' %}" data-parent="#sidebar"
class="collapsed">
<i data-feather="log-out"></i>
<span class="d-none d-md-inline">{% trans "Log Out" %}</span>
</a>
<form id="logout-form" action="{% url 'logout' %}" data-parent="#sidebar" method="post" class="collapsed">
{% csrf_token %}
<button type="submit" class="btn btn-link">
<i data-feather="log-out"></i>
<span class="d-none d-md-inline">{% trans "Log Out" %}</span>
</button>
</form>
</div>

</div>
9 changes: 6 additions & 3 deletions tabbycat/templates/nav/top_nav_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@
<ul class="navbar-nav navbar-my-lg-0">
<li class="nav-item">
{% if user.is_authenticated %}
<a class="nav-link" href="{% url 'logout' %}">
{% trans "Log Out" %} ({{ user }})
</a>
<form id="logout-form" action="{% url 'logout' %}" method="post">
{% csrf_token %}
<button type="submit" class="btn btn-link nav-link">
{% trans "Log Out" %} ({{ user }})
</button>
</form>
{% else %}
<a class="nav-link" href="{% url 'login' %}">
{% trans "Login" %}
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/templates/registration/password_reset_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% endblocktrans %}

{% blocktrans trimmed %}
Your username is: {{ user }}
Your username is: {{ user }}
{% endblocktrans %}

{% blocktrans trimmed %}
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/templates/scss/modules/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

// Fix bad inheritance
.list-group-item .btn .feather {
.list-group-item .btn:not(.btn-link) .feather {
margin-right: 0;
}

Expand Down
55 changes: 32 additions & 23 deletions tabbycat/templates/scss/modules/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
border-right: 0;
padding: 0;

a {
a,
form > button {
color: $sidebar-muted-text;
display: block;

Expand Down Expand Up @@ -223,16 +224,20 @@
// Applies just to tablets
@include media-breakpoint-up(md) {

.admin-sidebar .list-group-item a {
font-size: 12px;
padding: 0.5rem 0.5rem;
.admin-sidebar .list-group-item {

.feather {
width: 12px;
height: 12px;
padding-right: 2px;
margin-right: 0;
padding-bottom: 2px;
a,
form > button {
font-size: 12px;
padding: 0.5rem 0.5rem;

.feather {
width: 12px;
height: 12px;
padding-right: 2px;
margin-right: 0;
padding-bottom: 2px;
}
}
}

Expand All @@ -258,20 +263,24 @@
// Applies just to screens
@include media-breakpoint-up(lg) {

.admin-sidebar .list-group-item a {
font-size: $font-size-base;
padding: 0.5rem 1rem;

.feather {
width: 20px;
height: 16px;
padding-right: 4px;
}
.admin-sidebar .list-group-item {

.feather-chevron-down,
.feather-chevron-up {
margin-top: 2px;
margin-right: 0;
a,
form > button {
font-size: $font-size-base;
padding: 0.5rem 1rem;

.feather {
width: 20px;
height: 16px;
padding-right: 4px;
}

.feather-chevron-down,
.feather-chevron-up {
margin-top: 2px;
margin-right: 0;
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions tabbycat/tournaments/templates/site_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,24 @@
{% url 'password_change' as url %}
{% include "components/item-action.html" with icon="rotate-cw" %}

{% blocktrans asvar text %}Log Out ({{ user }}){% endblocktrans %}
{% url 'logout' as url %}
{% include "components/item-action.html" with icon="log-out" %}
<form id="logout-link-form" method="post" action="{% url 'logout' %}" class="list-group-item list-group-item-action text-primary">
{% csrf_token %}
<button type="submit" class="btn btn-link p-0 list-group-item-action text-primary">
<div class="row align-items-center">
<div class="col-auto pr-1">
<i data-feather="log-out"></i>
</div>

<div class="col pl-0 pr-0">
{% blocktrans %}Log Out ({{ user }}){% endblocktrans %}
</div>

<div class="col-auto pr-1">
<i data-feather="chevron-right"></i>
</div>
</div>
</button>
</form>

{% else %}

Expand Down
1 change: 1 addition & 0 deletions tabbycat/users/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Permission(TextChoices):
VIEW_DEBATE = 'view.debate', _("view debates (draw)")
VIEW_ADMIN_DRAW = 'view.debate.admin', _("view debates (detailed draw)")
GENERATE_DEBATE = 'generate.debate', _("generate debates (draw)")
DELETE_DEBATE = 'delete.debate', _("delete debates (draw)")
EDIT_DEBATETEAMS = 'edit.debateteam', _("edit debate teams (pairings)")
VIEW_DEBATEADJUDICATORS = 'view.debateadjudicator', _("view debate adjudicators (allocations)")
EDIT_DEBATEADJUDICATORS = 'edit.debateadjudicator', _("edit debate adjudicators (allocations)")
Expand Down

0 comments on commit 26c50ec

Please sign in to comment.