1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00
This commit is contained in:
Pierre-antoine Comby 2020-02-27 20:56:06 +01:00
parent c372b6587e
commit 0ea0d77707
2 changed files with 5 additions and 7 deletions

View File

@ -51,15 +51,13 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
model = User model = User
fields = ['first_name', 'last_name', 'username', 'email'] fields = ['first_name', 'last_name', 'username', 'email']
template_name = 'member/profile_update.html' template_name = 'member/profile_update.html'
context_object_name = 'user_object'
second_form = ProfileForm second_form = ProfileForm
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['user_modified'] = context['user']
context['user'] = self.request.user
context["profile_form"] = self.second_form( context["profile_form"] = self.second_form(
instance=context['user_modified'].profile) instance=context['user_object'].profile)
context['title'] = _("Update Profile") context['title'] = _("Update Profile")
return context return context
@ -74,7 +72,7 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
# Si l'utilisateur cherche à modifier son pseudo, le nouveau pseudo ne doit pas être proche d'un alias existant # Si l'utilisateur cherche à modifier son pseudo, le nouveau pseudo ne doit pas être proche d'un alias existant
note = NoteUser.objects.filter( note = NoteUser.objects.filter(
alias__normalized_name=Alias.normalize(new_username)) alias__normalized_name=Alias.normalize(new_username))
if note.exists() and note.get().user != self.request.user: if note.exists() and note.get().user != self.object:
form.add_error('username', form.add_error('username',
_("An alias with a similar name already exists.")) _("An alias with a similar name already exists."))
@ -83,7 +81,7 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
def form_valid(self, form): def form_valid(self, form):
profile_form = ProfileForm( profile_form = ProfileForm(
data=self.request.POST, data=self.request.POST,
instance=self.request.user.profile, instance=self.object.profile,
) )
if form.is_valid() and profile_form.is_valid(): if form.is_valid() and profile_form.is_valid():
new_username = form.data['username'] new_username = form.data['username']

View File

@ -12,7 +12,7 @@
<dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd> <dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd>
<dt class="col-xl-6">{% trans 'username'|capfirst %}</dt> <dt class="col-xl-6">{% trans 'username'|capfirst %}</dt>
<dd class="col-xl-6">{{ user.username }}</dd> <dd class="col-xl-6">{{ object.username }}</dd>
<dt class="col-xl-6">{% trans 'password'|capfirst %}</dt> <dt class="col-xl-6">{% trans 'password'|capfirst %}</dt>
<dd class="col-xl-6"> <dd class="col-xl-6">