Add club group

This commit is contained in:
MatthieuHR committed 2026-11-09 11:34:16 +00:00
1 parent fb25e4586e
commit 04b200cdc5
5 files changed
+41 -9

No files matched your search

+14
View File
@@ -299,6 +299,12 @@ class ClubSearchForm(forms.ModelForm):
class ClubRoleForm(forms.ModelForm):
error_css_class = "error"
required_css_class = "required"
is_stock_group = forms.BooleanField(
required=False,
label=_("Can edit stock"),
widget=forms.CheckboxInput(attrs={"class": "switch"}),
help_text=_("Tell if the user can edit all stocks belongings to the club"),
)
class Meta:
model = ClubRole
@@ -309,12 +315,20 @@ class ClubRoleForm(forms.ModelForm):
"is_active": forms.CheckboxInput(attrs={"class": "switch"}),
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["is_stock_group"].initial = self.instance.is_stock_group
def clean(self):
cleaned_data = super().clean()
if "ORDER" in cleaned_data:
self.instance.order = cleaned_data["ORDER"] - 1
return cleaned_data
def _save_m2m(self):
super()._save_m2m()
self.instance.is_stock_group = self.cleaned_data["is_stock_group"]
def save(self, commit=True): # noqa: FBT002
instance: ClubRole = super().save(commit=commit)
if commit and "is_board" in self.changed_data:
+2 -2
View File
@@ -15,10 +15,10 @@ def add_stock_groups(apps, schema_editor):
club.stock_group = new_group
club.save()
class Migration(migrations.Migration):
class Migration(migrations.Migration):
dependencies = [
('club', '0019_remove_mailingsubscription_mailing_and_more'),
("club", "0019_remove_mailingsubscription_mailing_and_more"),
]
operations = [
+13
View File
@@ -301,6 +301,19 @@ class ClubRole(OrderedModel):
order_with_respect_to = "club"
@property
def is_stock_group(self):
if not self.pk:
return False
return self.linked_groups.contains(self.club.stock_group)
@is_stock_group.setter
def is_stock_group(self, value):
if value is True:
self.linked_groups.add(self.club.stock_group)
else:
self.linked_groups.remove(self.club.stock_group)
class Meta(OrderedModel.Meta):
verbose_name = _("club role")
verbose_name_plural = _("club roles")
+12 -1
View File
@@ -49,7 +49,18 @@
{{ subform.is_active.help_text }}
</span>
</div>
{% set groups = subform.instance.linked_groups.all()|list %}
<div class="form-group">
<div>
{{ subform.is_stock_group }}
{{ subform.is_stock_group.label_tag() }}
</div>
<span class="helptext">
{{ subform.is_stock_group.help_text }}
</span>
</div>
{# I don't know why it has no id in my case.... Maybe I'm big dum #}
{% set groups = subform.instance.linked_groups.all()|list if subform.instance.pk else [] %}
{% if groups %}
<div>
<p>
-6
View File
@@ -508,12 +508,6 @@ class ClubRoleBoardCreateView(ClubRoleBaseCreateView):
role_description = _("club role \u2013 board")
class ClubRoleMemberCreateView(ClubRoleBaseCreateView):
is_presidency = False
is_board = True
role_description = _("club role \u2013 stock manager")
class ClubRoleMemberCreateView(ClubRoleBaseCreateView):
is_presidency = False
is_board = False