Commit 442161fdac937139e46e268cdde74ee781bb26dc
Committed by
Sergio Oliveira
1 parent
8d3f32bd
Exists in
master
and in
39 other branches
Linked user instance with form
Linked user instance to form in order to only update it instead of create another user Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
1 changed file
with
7 additions
and
2 deletions
Show diff stats
colab/accounts/views.py
... | ... | @@ -137,17 +137,22 @@ def signup(request): |
137 | 137 | if request.method == 'GET': |
138 | 138 | user_form = UserCreationForm() |
139 | 139 | lists_form = ListsForm() |
140 | + | |
141 | + user_form.fields['email'].initial = user.email | |
142 | + | |
140 | 143 | return render(request, 'accounts/user_create_form.html', |
141 | 144 | {'user_form': user_form, 'lists_form': lists_form}) |
142 | 145 | |
143 | - user_form = UserCreationForm(request.POST) | |
146 | + user_form = UserCreationForm(request.POST, instance=user) | |
144 | 147 | lists_form = ListsForm(request.POST) |
145 | 148 | |
146 | 149 | if not user_form.is_valid() or not lists_form.is_valid(): |
147 | 150 | return render(request, 'accounts/user_create_form.html', |
148 | 151 | {'user_form': user_form, 'lists_form': lists_form}) |
149 | 152 | |
150 | - user = user_form.save() | |
153 | + user = user_form.save(commit=False) | |
154 | + user.needs_update = False | |
155 | + user.save() | |
151 | 156 | |
152 | 157 | # Check if the user's email have been used previously |
153 | 158 | # in the mainling lists to link the user to old messages | ... | ... |