Browse Source

édition des utilisateurs et asso

Élie Bouttier 8 years ago
parent
commit
744923851a
5 changed files with 6 additions and 19 deletions
  1. 2 8
      accounts/forms.py
  2. 2 0
      accounts/views.py
  3. 2 2
      adhesions/views.py
  4. 0 8
      djadhere/forms.py
  5. 0 1
      services/forms.py

+ 2 - 8
accounts/forms.py

@@ -1,7 +1,6 @@
 from django.forms import ModelForm
 from django.contrib.auth.models import User
 
-from djadhere.forms import ReadOnlyModelForm
 from .models import Profile
 
 
@@ -11,16 +10,11 @@ class UserCreateForm(ModelForm):
         fields = ('username', 'first_name', 'last_name', 'email',)
 
 
-class UserChangeForm(ReadOnlyModelForm):
-    #def __init__(self, *args, **kwargs):
-    #    super().__init__(*args, **kwargs)
-    #    for key in self.Meta.readonly_fields:
-    #        self.fields[key].disabled = True
-
+class UserChangeForm(ModelForm):
     class Meta:
         model = User
         fields = ('username', 'first_name', 'last_name', 'email',)
-        readonly_fields = ('username', 'first_name', 'last_name',)
+        admin_only_fields = ('username', 'first_name', 'last_name',)
 
 
 class ProfileForm(ModelForm):

+ 2 - 0
accounts/views.py

@@ -8,6 +8,8 @@ from .forms import UserChangeForm, ProfileForm
 @login_required
 def profile(request):
     user_form = UserChangeForm(request.POST or None, instance=request.user)
+    for key in user_form.Meta.admin_only_fields:
+        user_form.fields[key].disabled = True
     profile_form = ProfileForm(request.POST or None, instance=request.user.profile)
     forms = [user_form, profile_form]
     if request.method == 'POST' and all(form.is_valid() for form in forms):

+ 2 - 2
adhesions/views.py

@@ -118,11 +118,11 @@ class CorporationDetail(CorporationMixin, DetailView):
 
 
 class CorporationCreate(CorporationMixin, CreateView):
-    fields = ('social_reason',)
+    fields = ('social_reason', 'email', 'phone_number', 'address', 'notes')
 
 
 class CorporationUpdate(CorporationMixin, UpdateView):
-    fields = ('social_reason',)
+    fields = ('social_reason', 'email', 'phone_number', 'address', 'notes')
 
 
 class AdhesionMixin(PermissionRequiredMixin):

+ 0 - 8
djadhere/forms.py

@@ -1,8 +0,0 @@
-from django.forms import ModelForm
-
-
-class ReadOnlyModelForm(ModelForm):
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
-        for key in self.Meta.readonly_fields:
-            self.fields[key].disabled = True

+ 0 - 1
services/forms.py

@@ -3,7 +3,6 @@ from django.utils import timezone
 
 from django_select2.forms import Select2Widget
 
-from djadhere.forms import ReadOnlyModelForm
 from .models import Service, ResourceAllocation