1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-02-19 06:31:17 +00:00

Cancel modifications

This commit is contained in:
thomasl 2025-02-13 19:40:04 +01:00
parent 6e49140900
commit 62baad7b69
2 changed files with 2 additions and 12 deletions

View File

@ -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."))
return promotion
def __init__(self, *args, request=None, **kwargs):
def __init__(self, *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['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
def save(self, commit=True):

View File

@ -74,8 +74,7 @@ class UserUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
form.fields['email'].help_text = _("This address must be valid.")
profile_form = self.profile_form(instance=context['user_object'].profile,
data=self.request.POST if self.request.POST else None,
request=self.request)
data=self.request.POST if self.request.POST else None)
if not self.object.profile.report_frequency:
del profile_form.fields["last_report"]