Commit 442161fdac937139e46e268cdde74ee781bb26dc

Authored by Carlos Coêlho
Committed by Sergio Oliveira
1 parent 8d3f32bd

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,17 +137,22 @@ def signup(request):
137 if request.method == 'GET': 137 if request.method == 'GET':
138 user_form = UserCreationForm() 138 user_form = UserCreationForm()
139 lists_form = ListsForm() 139 lists_form = ListsForm()
  140 +
  141 + user_form.fields['email'].initial = user.email
  142 +
140 return render(request, 'accounts/user_create_form.html', 143 return render(request, 'accounts/user_create_form.html',
141 {'user_form': user_form, 'lists_form': lists_form}) 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 lists_form = ListsForm(request.POST) 147 lists_form = ListsForm(request.POST)
145 148
146 if not user_form.is_valid() or not lists_form.is_valid(): 149 if not user_form.is_valid() or not lists_form.is_valid():
147 return render(request, 'accounts/user_create_form.html', 150 return render(request, 'accounts/user_create_form.html',
148 {'user_form': user_form, 'lists_form': lists_form}) 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 # Check if the user's email have been used previously 157 # Check if the user's email have been used previously
153 # in the mainling lists to link the user to old messages 158 # in the mainling lists to link the user to old messages