Skip to content

Commit

Permalink
Changed forms.py
Browse files Browse the repository at this point in the history
Changed so that section sorting occurs on all ModelForm's.
This allows us to yet again use a custom ModelForm for admin page
and another for the registration page.
  • Loading branch information
hato1883 committed Nov 8, 2023
1 parent 1a9427c commit e1dad4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/members/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@


class MemberForm(forms.ModelForm):
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)
person_number = PersonNumberField(
label=_('Person number'),
help_text=_('Person number using the YYYYMMDD-XXXX format.'),
Expand Down Expand Up @@ -81,6 +86,12 @@ def save(self, commit=True):


class RegistrationForm(MemberForm, auth.UserCreationForm):
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

class Meta:
model = Member
fields = ['username', 'email', 'phone_number', 'section']
Expand Down Expand Up @@ -216,6 +227,12 @@ def password_enabled(self):
widget=forms.PasswordInput,
help_text=_("Enter the same password as above, for verification."))

section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

is_superuser = forms.BooleanField(
label=_("Administrator"), required=False,
help_text=_('Administrators have full access to manage any object '
Expand Down Expand Up @@ -304,6 +321,11 @@ def save(self, commit=True):

class UserEditForm(UserForm):
password_required = False
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

def __init__(self, *args, **kwargs):
kwargs.pop('editing_self', False)
Expand Down
4 changes: 2 additions & 2 deletions src/members/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.views.generic import CreateView

from members import views
from members.forms import CustomUserCreationForm
from members.forms import RegistrationForm

urlpatterns = [
re_path(r'^profile/$', views.ProfileView.as_view(), name='profile'),
Expand All @@ -14,7 +14,7 @@
),
re_path('^register/', CreateView.as_view(
template_name='members/register.html',
form_class=CustomUserCreationForm,
form_class=RegistrationForm,
success_url=reverse_lazy('login'),
), name='register'),

Expand Down

0 comments on commit e1dad4e

Please sign in to comment.