mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-10-30 23:39:54 +01:00 
			
		
		
		
	Cancel modifications
This commit is contained in:
		| @@ -63,19 +63,10 @@ class ProfileForm(forms.ModelForm): | |||||||
|             self.add_error("promotion", _("You can't register to the note if you come from the future.")) |             self.add_error("promotion", _("You can't register to the note if you come from the future.")) | ||||||
|         return promotion |         return promotion | ||||||
|  |  | ||||||
|     def __init__(self, *args, request=None, **kwargs): |     def __init__(self, *args, **kwargs): | ||||||
|         super().__init__(*args, **kwargs) |         super().__init__(*args, **kwargs) | ||||||
|         self.request = request |  | ||||||
|         self.fields['address'].widget.attrs.update({"placeholder": "4 avenue des Sciences, 91190 GIF-SUR-YVETTE"}) |         self.fields['address'].widget.attrs.update({"placeholder": "4 avenue des Sciences, 91190 GIF-SUR-YVETTE"}) | ||||||
|         self.fields['promotion'].widget.attrs.update({"max": timezone.now().year}) |         self.fields['promotion'].widget.attrs.update({"max": timezone.now().year}) | ||||||
|      |  | ||||||
|     def clean(self): |  | ||||||
|         """Force the values of fields that the user does not have permission to modify..""" |  | ||||||
|         cleaned_data = super().clean() |  | ||||||
|         for field_name in self.fields.keys(): |  | ||||||
|             if not PermissionBackend.check_perm(self.request, f"member.change_profile_{field_name}", self.instance): |  | ||||||
|                 cleaned_data[field_name] = getattr(self.instance, field_name)  # Force the old value |  | ||||||
|         return cleaned_data |  | ||||||
|  |  | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|     def save(self, commit=True): |     def save(self, commit=True): | ||||||
|   | |||||||
| @@ -74,8 +74,7 @@ class UserUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView): | |||||||
|         form.fields['email'].help_text = _("This address must be valid.") |         form.fields['email'].help_text = _("This address must be valid.") | ||||||
|  |  | ||||||
|         profile_form = self.profile_form(instance=context['user_object'].profile, |         profile_form = self.profile_form(instance=context['user_object'].profile, | ||||||
|                                          data=self.request.POST if self.request.POST else None, |                                          data=self.request.POST if self.request.POST else None) | ||||||
|                                          request=self.request) |  | ||||||
|         if not self.object.profile.report_frequency: |         if not self.object.profile.report_frequency: | ||||||
|             del profile_form.fields["last_report"] |             del profile_form.fields["last_report"] | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user