97 Returns: |
98 Returns: |
98 A subclass of django.http.HttpResponse which either contains the form to |
99 A subclass of django.http.HttpResponse which either contains the form to |
99 be filled out, or a redirect to the correct view in the interface. |
100 be filled out, or a redirect to the correct view in the interface. |
100 """ |
101 """ |
101 id = users.get_current_user() |
102 id = users.get_current_user() |
102 |
103 |
103 # create default template context for use with any templates |
104 # create default template context for use with any templates |
104 context = helper.responses.getUniversalContext(request) |
105 context = helper.responses.getUniversalContext(request) |
105 |
106 |
106 if (not id) and (not link_name): |
107 if (not id) and (not link_name): |
107 # not logged in, and no link name, so request that the user sign in |
108 # not logged in, and no link name, so request that the user sign in |
143 'link_name': new_link_name, |
144 'link_name': new_link_name, |
144 'nick_name': form.cleaned_data.get("nick_name"), |
145 'nick_name': form.cleaned_data.get("nick_name"), |
145 'id': id, |
146 'id': id, |
146 } |
147 } |
147 |
148 |
148 key_fields = {'email': id.email()} |
149 # check if user account is not in former_ids |
149 user = models.user.logic.updateOrCreateFromFields(properties, |
150 # if it is show error message that account is invalid |
150 key_fields) |
151 if models.user.logic.isFormerId(id): |
151 |
152 msg = DEF_USER_ACCOUNT_INVALID_MSG |
|
153 error = out_of_band.ErrorResponse(msg) |
|
154 return simple.errorResponse(request, page, error, template, context) |
|
155 |
|
156 user = models.user.logic.updateOrCreateFromId(properties, id) |
|
157 |
152 # redirect to /user/profile?s=0 |
158 # redirect to /user/profile?s=0 |
153 # (causes 'Profile saved' message to be displayed) |
159 # (causes 'Profile saved' message to be displayed) |
154 return helper.responses.redirectToChangedSuffix( |
160 return helper.responses.redirectToChangedSuffix( |
155 request, None, params=SUBMIT_PROFILE_SAVED_PARAMS) |
161 request, None, params=SUBMIT_PROFILE_SAVED_PARAMS) |
156 else: # request.method == 'GET' |
162 else: # request.method == 'GET' |
157 # try to fetch User entity corresponding to Google Account if one exists |
163 # try to fetch User entity corresponding to Google Account if one exists |
158 user = models.user.logic.getFromFields(email=id.email()) |
164 user = models.user.logic.getForFields({'id': id}, unique=True) |
159 |
165 |
160 if user: |
166 if user: |
161 # is 'Profile saved' parameter present, but referrer was not ourself? |
167 # is 'Profile saved' parameter present, but referrer was not ourself? |
162 # (e.g. someone bookmarked the GET that followed the POST submit) |
168 # (e.g. someone bookmarked the GET that followed the POST submit) |
163 if (request.GET.get(SUBMIT_MSG_PARAM_NAME) |
169 if (request.GET.get(SUBMIT_MSG_PARAM_NAME) |