Skip to content

Commit

Permalink
Merge pull request #957 from ae-utbm/user-model
Browse files Browse the repository at this point in the history
Fix groups displayed on user profile group edition
  • Loading branch information
imperosol authored Dec 19, 2024
2 parents 29c4a36 + 87b6197 commit 38ceaf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 7 additions & 4 deletions core/views/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from PIL import Image

from antispam.forms import AntiSpamEmailField
from core.models import Gift, Page, SithFile, User
from core.models import Gift, Page, RealGroup, SithFile, User
from core.utils import resize_image
from core.views.widgets.select import (
AutoCompleteSelect,
Expand Down Expand Up @@ -285,15 +285,18 @@ def process(self, files):
self._post_clean()


class UserPropForm(forms.ModelForm):
class UserRealGroupForm(forms.ModelForm):
error_css_class = "error"
required_css_class = "required"

groups = forms.ModelChoiceField(
RealGroup.objects.all(),
widget=CheckboxSelectMultiple,
)

class Meta:
model = User
fields = ["groups"]
help_texts = {"groups": "Which groups this user belongs to"}
widgets = {"groups": CheckboxSelectMultiple}


class UserGodfathersForm(forms.Form):
Expand Down
6 changes: 2 additions & 4 deletions core/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from django.core.exceptions import PermissionDenied
from django.db.models import DateField, QuerySet
from django.db.models.functions import Trunc
from django.forms import CheckboxSelectMultiple
from django.forms.models import modelform_factory
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -69,6 +68,7 @@
RegisteringForm,
UserGodfathersForm,
UserProfileForm,
UserRealGroupForm,
)
from counter.models import Refilling, Selling
from counter.views.student_card import StudentCardFormView
Expand Down Expand Up @@ -583,9 +583,7 @@ class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
model = User
pk_url_kwarg = "user_id"
template_name = "core/user_group.jinja"
form_class = modelform_factory(
User, fields=["groups"], widgets={"groups": CheckboxSelectMultiple}
)
form_class = UserRealGroupForm
context_object_name = "profile"
current_tab = "groups"

Expand Down

0 comments on commit 38ceaf3

Please sign in to comment.