diff --git a/club/forms.py b/club/forms.py index 57ab91da..16fac2bd 100644 --- a/club/forms.py +++ b/club/forms.py @@ -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: diff --git a/club/migrations/0020_club_stock_group.py b/club/migrations/0020_club_stock_group.py index 78f0fd2c..8e52cbe9 100644 --- a/club/migrations/0020_club_stock_group.py +++ b/club/migrations/0020_club_stock_group.py @@ -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 = [ diff --git a/club/models.py b/club/models.py index 650a216f..dffa2431 100644 --- a/club/models.py +++ b/club/models.py @@ -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") diff --git a/club/templates/club/club_roles.jinja b/club/templates/club/club_roles.jinja index bb860f10..3a1aa1e2 100644 --- a/club/templates/club/club_roles.jinja +++ b/club/templates/club/club_roles.jinja @@ -49,7 +49,18 @@ {{ subform.is_active.help_text }} - {% set groups = subform.instance.linked_groups.all()|list %} +
diff --git a/club/views.py b/club/views.py index 61b60f5e..b5532111 100644 --- a/club/views.py +++ b/club/views.py @@ -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