mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 16:09:54 +00:00
Add club group
This commit is contained in:
1 parent
fb25e4586e
commit
04b200cdc5
5 files changed
+41
-9
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user