mirror of
https://github.com/ae-utbm/sith.git
synced 2025-03-10 07:17:11 +00:00
merge ClubEditView
and ClubEditPropView
This commit is contained in:
parent
fa5ddfaeda
commit
3d5cf98fb6
@ -34,13 +34,20 @@ from counter.models import Counter
|
|||||||
|
|
||||||
|
|
||||||
class ClubEditForm(forms.ModelForm):
|
class ClubEditForm(forms.ModelForm):
|
||||||
|
error_css_class = "error"
|
||||||
|
required_css_class = "required"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Club
|
model = Club
|
||||||
fields = ["address", "logo", "short_description"]
|
fields = ["address", "logo", "short_description"]
|
||||||
|
widgets = {"short_description": forms.Textarea()}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
class ClubAdminEditForm(ClubEditForm):
|
||||||
self.fields["short_description"].widget = forms.Textarea()
|
admin_fields = ["name", "parent", "is_active"]
|
||||||
|
|
||||||
|
class Meta(ClubEditForm.Meta):
|
||||||
|
fields = ["name", "parent", "is_active", *ClubEditForm.Meta.fields]
|
||||||
|
|
||||||
|
|
||||||
class MailingForm(forms.Form):
|
class MailingForm(forms.Form):
|
||||||
|
54
club/templates/club/edit_club.jinja
Normal file
54
club/templates/club/edit_club.jinja
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% trans name=object %}Edit {{ name }}{% endtrans %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>{% trans name=object %}Edit {{ name }}{% endtrans %}</h2>
|
||||||
|
|
||||||
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
{{ form.non_field_errors() }}
|
||||||
|
|
||||||
|
{% if form.admin_fields %}
|
||||||
|
{# If the user is admin, display the admin fields,
|
||||||
|
and explicitly separate them from the non-admin ones,
|
||||||
|
with some help text.
|
||||||
|
Non-admin users will only see the regular form fields,
|
||||||
|
so they don't need thoses explanations #}
|
||||||
|
<h3>{% trans %}Club properties{% endtrans %}</h3>
|
||||||
|
<p class="helptext">
|
||||||
|
{% trans trimmed %}
|
||||||
|
The following form fields are linked to the core properties of a club.
|
||||||
|
Only admin users can see and edit them.
|
||||||
|
{% endtrans %}
|
||||||
|
</p>
|
||||||
|
<fieldset class="required margin-bottom">
|
||||||
|
{% for field_name in form.admin_fields %}
|
||||||
|
{% set field = form.pop(field_name) %}
|
||||||
|
<div class="form-group">
|
||||||
|
{{ field.errors }}
|
||||||
|
{{ field.label_tag() }}
|
||||||
|
{{ field }}
|
||||||
|
</div>
|
||||||
|
{# Remove the the admin fields from the form.
|
||||||
|
The remaining non-admin fields will be rendered
|
||||||
|
at once with a simple {{ form.as_p() }} #}
|
||||||
|
{% set _ = form.fields.pop(field_name) %}
|
||||||
|
{% endfor %}
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<h3>{% trans %}Club informations{% endtrans %}</h3>
|
||||||
|
<p class="helptext">
|
||||||
|
{% trans trimmed %}
|
||||||
|
The following form fields are linked to the basic description of a club.
|
||||||
|
All board members of this club can see and edit them.
|
||||||
|
{% endtrans %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{{ form.as_p() }}
|
||||||
|
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
@ -26,7 +26,6 @@ from django.urls import path
|
|||||||
|
|
||||||
from club.views import (
|
from club.views import (
|
||||||
ClubCreateView,
|
ClubCreateView,
|
||||||
ClubEditPropView,
|
|
||||||
ClubEditView,
|
ClubEditView,
|
||||||
ClubListView,
|
ClubListView,
|
||||||
ClubMailingView,
|
ClubMailingView,
|
||||||
@ -70,7 +69,6 @@ urlpatterns = [
|
|||||||
path(
|
path(
|
||||||
"<int:club_id>/sellings/csv/", ClubSellingCSVView.as_view(), name="sellings_csv"
|
"<int:club_id>/sellings/csv/", ClubSellingCSVView.as_view(), name="sellings_csv"
|
||||||
),
|
),
|
||||||
path("<int:club_id>/prop/", ClubEditPropView.as_view(), name="club_prop"),
|
|
||||||
path("<int:club_id>/tools/", ClubToolsView.as_view(), name="tools"),
|
path("<int:club_id>/tools/", ClubToolsView.as_view(), name="tools"),
|
||||||
path("<int:club_id>/mailing/", ClubMailingView.as_view(), name="mailing"),
|
path("<int:club_id>/mailing/", ClubMailingView.as_view(), name="mailing"),
|
||||||
path(
|
path(
|
||||||
|
@ -56,12 +56,7 @@ from com.views import (
|
|||||||
PosterEditBaseView,
|
PosterEditBaseView,
|
||||||
PosterListBaseView,
|
PosterListBaseView,
|
||||||
)
|
)
|
||||||
from core.auth.mixins import (
|
from core.auth.mixins import CanCreateMixin, CanEditMixin, CanViewMixin
|
||||||
CanCreateMixin,
|
|
||||||
CanEditMixin,
|
|
||||||
CanEditPropMixin,
|
|
||||||
CanViewMixin,
|
|
||||||
)
|
|
||||||
from core.models import PageRev
|
from core.models import PageRev
|
||||||
from core.views import DetailFormView, PageEditViewBase
|
from core.views import DetailFormView, PageEditViewBase
|
||||||
from core.views.mixins import TabedViewMixin
|
from core.views.mixins import TabedViewMixin
|
||||||
@ -113,21 +108,23 @@ class ClubTabsMixin(TabedViewMixin):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if self.request.user.can_edit(self.object):
|
if self.request.user.can_edit(self.object):
|
||||||
tab_list.append(
|
tab_list.extend(
|
||||||
{
|
[
|
||||||
"url": reverse("club:tools", kwargs={"club_id": self.object.id}),
|
{
|
||||||
"slug": "tools",
|
"url": reverse(
|
||||||
"name": _("Tools"),
|
"club:tools", kwargs={"club_id": self.object.id}
|
||||||
}
|
),
|
||||||
)
|
"slug": "tools",
|
||||||
tab_list.append(
|
"name": _("Tools"),
|
||||||
{
|
},
|
||||||
"url": reverse(
|
{
|
||||||
"club:club_edit", kwargs={"club_id": self.object.id}
|
"url": reverse(
|
||||||
),
|
"club:club_edit", kwargs={"club_id": self.object.id}
|
||||||
"slug": "edit",
|
),
|
||||||
"name": _("Edit"),
|
"slug": "edit",
|
||||||
}
|
"name": _("Edit"),
|
||||||
|
},
|
||||||
|
]
|
||||||
)
|
)
|
||||||
if self.object.page and self.request.user.can_edit(self.object.page):
|
if self.object.page and self.request.user.can_edit(self.object.page):
|
||||||
tab_list.append(
|
tab_list.append(
|
||||||
@ -165,16 +162,6 @@ class ClubTabsMixin(TabedViewMixin):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if self.request.user.is_owner(self.object):
|
|
||||||
tab_list.append(
|
|
||||||
{
|
|
||||||
"url": reverse(
|
|
||||||
"club:club_prop", kwargs={"club_id": self.object.id}
|
|
||||||
),
|
|
||||||
"slug": "props",
|
|
||||||
"name": _("Props"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return tab_list
|
return tab_list
|
||||||
|
|
||||||
|
|
||||||
@ -461,23 +448,23 @@ class ClubSellingCSVView(ClubSellingView):
|
|||||||
|
|
||||||
|
|
||||||
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
||||||
"""Edit a Club's main informations (for the club's members)."""
|
"""Edit a Club.
|
||||||
|
|
||||||
|
Regular club board members will be able to edit the main infos
|
||||||
|
(like the logo and the description).
|
||||||
|
Admins will also be able to edit the club properties
|
||||||
|
(like the name and the parent club).
|
||||||
|
"""
|
||||||
|
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
form_class = ClubEditForm
|
template_name = "club/edit_club.jinja"
|
||||||
template_name = "core/edit.jinja"
|
|
||||||
current_tab = "edit"
|
current_tab = "edit"
|
||||||
|
|
||||||
|
def get_form_class(self):
|
||||||
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
if self.object.is_owned_by(self.request.user):
|
||||||
"""Edit the properties of a Club object (for the Sith admins)."""
|
return ClubAdminEditForm
|
||||||
|
return ClubEditForm
|
||||||
model = Club
|
|
||||||
pk_url_kwarg = "club_id"
|
|
||||||
fields = ["name", "parent", "is_active"]
|
|
||||||
template_name = "core/edit.jinja"
|
|
||||||
current_tab = "props"
|
|
||||||
|
|
||||||
|
|
||||||
class ClubCreateView(PermissionRequiredMixin, CreateView):
|
class ClubCreateView(PermissionRequiredMixin, CreateView):
|
||||||
|
@ -130,8 +130,7 @@ class Command(BaseCommand):
|
|||||||
self.clubs = Club.objects.bulk_create(
|
self.clubs = Club.objects.bulk_create(
|
||||||
[
|
[
|
||||||
Club(
|
Club(
|
||||||
unix_name=f"galaxy-club-{i}",
|
name=f"galaxy-club-{i}",
|
||||||
name=f"club-{i}",
|
|
||||||
board_group=Group.objects.create(name=f"board {i}"),
|
board_group=Group.objects.create(name=f"board {i}"),
|
||||||
members_group=Group.objects.create(name=f"members {i}"),
|
members_group=Group.objects.create(name=f"members {i}"),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user