author | Todd Larsen <tlarsen@google.com> |
Thu, 02 Oct 2008 20:22:15 +0000 | |
changeset 262 | 52a42831d9d6 |
parent 260 | 8b393bef717a |
child 266 | 3b47bfd4f1b3 |
permissions | -rw-r--r-- |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Developer views for editing and examining User profiles. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
""" |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
'"Todd Larsen" <tlarsen@google.com>', |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
] |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
from google.appengine.api import users |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
26 |
|
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
from django import http |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
from django import newforms as forms |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
29 |
from django.utils.translation import ugettext_lazy |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
|
249
325fb70c61a9
Replace common module with validate module. Move validation function from feed module to validate module and remove feed.py. Correct any usage of validation functions from common and feed modules into validate module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
245
diff
changeset
|
31 |
from soc.logic import validate |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
from soc.logic import out_of_band |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
from soc.logic.site import id_user |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
from soc.views import simple |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
from soc.views.helpers import forms_helpers |
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
36 |
from soc.views.helpers import list_helpers |
189
1cf3e7531382
Split out HTTP request manipulation functions from template_helpers.py, which
Todd Larsen <tlarsen@google.com>
parents:
184
diff
changeset
|
37 |
from soc.views.helpers import request_helpers |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
from soc.views.helpers import response_helpers |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
39 |
from soc.views.user import profile |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
import soc.models.user |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
class LookupForm(forms_helpers.DbModelForm): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
"""Django form displayed for a Developer to look up a User. |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
46 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
47 |
This form is manually specified, instead of using |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
48 |
model = soc.models.user.User |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
49 |
in the Meta class, because the form behavior is unusual and normally |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
50 |
required Properties of the User model need to sometimes be omitted. |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
51 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
52 |
Also, this form only permits entry and editing of some of the User entity |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
53 |
Properties, not all of them. |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
""" |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
55 |
id = forms.EmailField(required=False, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
56 |
label=soc.models.user.User.id.verbose_name, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
57 |
help_text=soc.models.user.User.id.help_text) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
58 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
59 |
link_name = forms.CharField(required=False, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
60 |
label=soc.models.user.User.link_name.verbose_name, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
61 |
help_text=soc.models.user.User.link_name.help_text) |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
class Meta: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
model = None |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
def clean_link_name(self): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
link_name = self.cleaned_data.get('link_name') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
if not link_name: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
# link name not supplied (which is OK), so do not try to validate it |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
return None |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
|
249
325fb70c61a9
Replace common module with validate module. Move validation function from feed module to validate module and remove feed.py. Correct any usage of validation functions from common and feed modules into validate module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
245
diff
changeset
|
73 |
if not validate.isLinkNameFormatValid(link_name): |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
raise forms.ValidationError('This link name is in wrong format.') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
76 |
return link_name |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
78 |
def clean_id(self): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
79 |
email = self.cleaned_data.get('id') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
80 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
81 |
if not email: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
82 |
# email not supplied (which is OK), so do not try to convert it |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
83 |
return None |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
84 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
85 |
try: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
86 |
return users.User(email=email) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
except users.UserNotFoundError: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
raise forms.ValidationError('Account not found.') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
DEF_SITE_USER_PROFILE_LOOKUP_TMPL = 'soc/site/user/profile/lookup.html' |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
def lookup(request, template=DEF_SITE_USER_PROFILE_LOOKUP_TMPL): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
"""View for a Developer to look up a User Model entity. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
Args: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
request: the standard django request object |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
98 |
template: the "sibling" template (or a search list of such templates) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
from which to construct the public.html template name (or names) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
Returns: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
A subclass of django.http.HttpResponse which either contains the form to |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
be filled out, or a redirect to the correct view in the interface. |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
""" |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
# create default template context for use with any templates |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
context = response_helpers.getUniversalContext(request) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
|
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
108 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
109 |
context=context) |
141
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
134
diff
changeset
|
110 |
if alt_response: |
e120c24b89e2
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
134
diff
changeset
|
111 |
return alt_response |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
user = None # assume that no User entity will be found |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
114 |
form = None # assume blank form needs to be displayed |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
115 |
lookup_message = ugettext_lazy('Enter information to look up a User.') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
116 |
email_error = None # assume no email look-up errors |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
118 |
if request.method == 'POST': |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
119 |
form = LookupForm(request.POST) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
120 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
121 |
if form.is_valid(): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
form_id = form.cleaned_data.get('id') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
123 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
if form_id: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
125 |
# email provided, so attempt to look up user by email |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
126 |
user = id_user.getUserFromId(form_id) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
if user: |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
129 |
lookup_message = ugettext_lazy('User found by email.') |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
130 |
else: |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
131 |
email_error = ugettext_lazy('User with that email not found.') |
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
132 |
range_width = list_helpers.getPreferredListPagination() |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
133 |
nearest_user_range_start = id_user.findNearestUsersOffset( |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
134 |
range_width, id=form_id) |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
135 |
|
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
136 |
if nearest_user_range_start is not None: |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
137 |
context['lookup_link'] = './list?offset=%s&limit=%s' % ( |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
138 |
nearest_user_range_start, range_width) |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
139 |
if not user: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
# user not found yet, so see if link name was provided |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
141 |
linkname = form.cleaned_data.get('link_name') |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
if linkname: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
# link name provided, so try to look up by link name |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
145 |
user = id_user.getUserFromLinkName(linkname) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
146 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
147 |
if user: |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
148 |
lookup_message = ugettext_lazy('User found by link name.') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
149 |
email_error = None # clear previous error, since User was found |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
else: |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
151 |
context['linkname_error'] = ugettext_lazy( |
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
152 |
'User with that link name not found.') |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
153 |
range_width = list_helpers.getPreferredListPagination() |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
154 |
nearest_user_range_start = id_user.findNearestUsersOffset( |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
155 |
range_width, link_name=linkname) |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
156 |
|
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
157 |
if nearest_user_range_start is not None: |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
158 |
context['lookup_link'] = './list?offset=%s&limit=%s' % ( |
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
159 |
nearest_user_range_start, range_width) |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
# else: form was not valid |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
161 |
# else: # method == 'GET' |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
162 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
163 |
if user: |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
210
diff
changeset
|
164 |
# User entity found, so populate form with existing User information |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
# context['found_user'] = user |
171
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
166 |
form = LookupForm(initial={'id': user.id.email, |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
167 |
'link_name': user.link_name}) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
if request.path.endswith('lookup'): |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
# convert /lookup path into /profile/link_name path |
190
b1351bf81064
Move isReferrerSelf() and replaceSuffix() into new request_helpers.py module,
Todd Larsen <tlarsen@google.com>
parents:
189
diff
changeset
|
171 |
context['edit_link'] = request_helpers.replaceSuffix( |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
172 |
request.path, 'lookup', 'profile/%s' % user.link_name) |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
# else: URL is not one that was expected, so do not display edit link |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
elif not form: |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
# no pre-populated form was constructed, so show the empty look-up form |
134
1f64d7a4d82d
Fixed wrong user variable in lookup.html template for edit link (was user should be found_user).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
132
diff
changeset
|
176 |
form = LookupForm() |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
177 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
178 |
context.update({'form': form, |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
179 |
'found_user': user, |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
180 |
'email_error': email_error, |
132
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
'lookup_message': lookup_message}) |
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
182 |
|
15d89c284106
Add a /site/user/lookup view that provides Developers with a form to look up
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
return response_helpers.respond(request, template, context) |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
184 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
185 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
186 |
class EditForm(forms_helpers.DbModelForm): |
205
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
187 |
"""Django form displayed when Developer edits a User. |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
188 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
189 |
This form is manually specified, instead of using |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
190 |
model = soc.models.user.User |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
191 |
in the Meta class, because the form behavior is unusual and normally |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
192 |
required Properties of the User model need to sometimes be omitted. |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
193 |
""" |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
194 |
id = forms.EmailField( |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
195 |
label=soc.models.user.User.id.verbose_name, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
196 |
help_text=soc.models.user.User.id.help_text) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
197 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
198 |
link_name = forms.CharField( |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
199 |
label=soc.models.user.User.link_name.verbose_name, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
200 |
help_text=soc.models.user.User.link_name.help_text) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
201 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
202 |
nick_name = forms.CharField( |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
203 |
label=soc.models.user.User.nick_name.verbose_name) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
204 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
205 |
is_developer = forms.BooleanField(required=False, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
206 |
label=soc.models.user.User.is_developer.verbose_name, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
207 |
help_text=soc.models.user.User.is_developer.help_text) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
208 |
|
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
209 |
key_name = forms.CharField(widget=forms.HiddenInput) |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
210 |
|
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
211 |
class Meta: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
212 |
model = None |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
213 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
214 |
def clean_link_name(self): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
215 |
link_name = self.cleaned_data.get('link_name') |
249
325fb70c61a9
Replace common module with validate module. Move validation function from feed module to validate module and remove feed.py. Correct any usage of validation functions from common and feed modules into validate module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
245
diff
changeset
|
216 |
if not validate.isLinkNameFormatValid(link_name): |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
217 |
raise forms.ValidationError("This link name is in wrong format.") |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
218 |
else: |
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
219 |
key_name = self.data.get('key_name') |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
220 |
if not id_user.isLinkNameAvailableForId( |
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
221 |
link_name, id=id_user.getUserFromKeyName(key_name).id) : |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
222 |
raise forms.ValidationError("This link name is already in use.") |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
223 |
return link_name |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
224 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
225 |
def clean_id(self): |
262
52a42831d9d6
Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents:
260
diff
changeset
|
226 |
form_id = users.User(email=self.cleaned_data.get('id')) |
52a42831d9d6
Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents:
260
diff
changeset
|
227 |
if not id_user.isIdAvailable( |
52a42831d9d6
Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents:
260
diff
changeset
|
228 |
form_id, existing_key_name=self.data.get('key_name')): |
52a42831d9d6
Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents:
260
diff
changeset
|
229 |
raise forms.ValidationError("This account is already in use.") |
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
230 |
return form_id |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
231 |
|
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
232 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
233 |
DEF_SITE_USER_PROFILE_EDIT_TMPL = 'soc/site/user/profile/edit.html' |
179
4882d6c5630d
Add custom 404 error message with link to "Create a New User" which is displayed when linkname in User Profile Developer view URL (/site/user/profile/<linkname>) doesn't exist. Add default value (None) to new_suffix parameter of template_helpers replaceSuffix and redirectToChangedSuffix functions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
171
diff
changeset
|
234 |
DEF_CREATE_NEW_USER_MSG = ' You can create a new user by visiting' \ |
4882d6c5630d
Add custom 404 error message with link to "Create a New User" which is displayed when linkname in User Profile Developer view URL (/site/user/profile/<linkname>) doesn't exist. Add default value (None) to new_suffix parameter of template_helpers replaceSuffix and redirectToChangedSuffix functions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
171
diff
changeset
|
235 |
' <a href="/site/user/profile">Create ' \ |
4882d6c5630d
Add custom 404 error message with link to "Create a New User" which is displayed when linkname in User Profile Developer view URL (/site/user/profile/<linkname>) doesn't exist. Add default value (None) to new_suffix parameter of template_helpers replaceSuffix and redirectToChangedSuffix functions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
171
diff
changeset
|
236 |
'a New User</a> page.' |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
237 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
238 |
def edit(request, linkname=None, template=DEF_SITE_USER_PROFILE_EDIT_TMPL): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
239 |
"""View for a Developer to modify the properties of a User Model entity. |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
240 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
241 |
Args: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
242 |
request: the standard django request object |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
243 |
linkname: the User's site-unique "linkname" extracted from the URL |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
244 |
template: the "sibling" template (or a search list of such templates) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
245 |
from which to construct the public.html template name (or names) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
246 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
247 |
Returns: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
248 |
A subclass of django.http.HttpResponse which either contains the form to |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
249 |
be filled out, or a redirect to the correct view in the interface. |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
250 |
""" |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
251 |
# create default template context for use with any templates |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
252 |
context = response_helpers.getUniversalContext(request) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
253 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
254 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
255 |
context=context) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
256 |
if alt_response: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
257 |
return alt_response |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
258 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
259 |
user = None # assume that no User entity will be found |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
260 |
|
171
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
261 |
# try to fetch User entity corresponding to linkname if one exists |
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
262 |
try: |
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
263 |
user = id_user.getUserIfLinkName(linkname) |
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
264 |
except out_of_band.ErrorResponse, error: |
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
265 |
# show custom 404 page when link name doesn't exist in Datastore |
179
4882d6c5630d
Add custom 404 error message with link to "Create a New User" which is displayed when linkname in User Profile Developer view URL (/site/user/profile/<linkname>) doesn't exist. Add default value (None) to new_suffix parameter of template_helpers replaceSuffix and redirectToChangedSuffix functions.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
171
diff
changeset
|
266 |
error.message = error.message + DEF_CREATE_NEW_USER_MSG |
171
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
267 |
return simple.errorResponse(request, error, template, context) |
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
268 |
|
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
269 |
if request.method == 'POST': |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
270 |
form = EditForm(request.POST) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
271 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
272 |
if form.is_valid(): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
273 |
form_id = form.cleaned_data.get('id') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
274 |
new_linkname = form.cleaned_data.get('link_name') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
275 |
nickname = form.cleaned_data.get('nick_name') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
276 |
is_developer = form.cleaned_data.get('is_developer') |
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
277 |
key_name = form.cleaned_data.get('key_name') |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
278 |
|
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
279 |
user = id_user.updateUserForKeyName(key_name=key_name, id=form_id, |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
280 |
link_name=new_linkname, nick_name=nickname, |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
281 |
is_developer=is_developer) |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
282 |
|
184
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
283 |
if not user: |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
284 |
return http.HttpResponseRedirect('/') |
7c0b42aecd9b
Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
179
diff
changeset
|
285 |
|
171
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
286 |
# redirect to new /site/user/profile/new_linkname?s=0 |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
287 |
# (causes 'Profile saved' message to be displayed) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
288 |
return response_helpers.redirectToChangedSuffix( |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
289 |
request, linkname, new_linkname, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
290 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
291 |
else: # method == 'GET': |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
292 |
# try to fetch User entity corresponding to link name if one exists |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
293 |
if linkname: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
294 |
if user: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
295 |
# is 'Profile saved' parameter present, but referrer was not ourself? |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
296 |
# (e.g. someone bookmarked the GET that followed the POST submit) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
297 |
if (request.GET.get(profile.SUBMIT_MSG_PARAM_NAME) |
190
b1351bf81064
Move isReferrerSelf() and replaceSuffix() into new request_helpers.py module,
Todd Larsen <tlarsen@google.com>
parents:
189
diff
changeset
|
298 |
and (not request_helpers.isReferrerSelf(request, |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
299 |
suffix=linkname))): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
300 |
# redirect to aggressively remove 'Profile saved' query parameter |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
301 |
return http.HttpResponseRedirect(request.path) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
302 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
303 |
# referrer was us, so select which submit message to display |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
304 |
# (may display no message if ?s=0 parameter is not present) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
305 |
context['submit_message'] = ( |
189
1cf3e7531382
Split out HTTP request manipulation functions from template_helpers.py, which
Todd Larsen <tlarsen@google.com>
parents:
184
diff
changeset
|
306 |
request_helpers.getSingleIndexedParamValue( |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
307 |
request, profile.SUBMIT_MSG_PARAM_NAME, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
308 |
values=profile.SUBMIT_MESSAGES)) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
309 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
310 |
# populate form with the existing User entity |
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
311 |
form = EditForm(initial={'key_name': user.key().name(), |
171
b62f1cf5e878
Bug fixes to revision r596. User Account field in Developer User Profile view needs to be an email not a login name. Header title of User Profile Developer view, when form validation failes is now showing correct value ("Modify existing ..." instead of "Create new user ...").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
170
diff
changeset
|
312 |
'id': user.id.email, 'link_name': user.link_name, |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
210
diff
changeset
|
313 |
'nick_name': user.nick_name, 'is_developer': user.is_developer}) |
170
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
314 |
else: |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
315 |
if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
316 |
# redirect to aggressively remove 'Profile saved' query parameter |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
317 |
return http.HttpResponseRedirect(request.path) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
318 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
319 |
context['lookup_error'] = ugettext_lazy( |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
320 |
'User with that link name not found.') |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
321 |
form = EditForm(initial={'link_name': linkname}) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
322 |
else: # no link name specified in the URL |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
323 |
if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
324 |
# redirect to aggressively remove 'Profile saved' query parameter |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
325 |
return http.HttpResponseRedirect(request.path) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
326 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
327 |
# no link name specified, so start with an empty form |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
328 |
form = EditForm() |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
329 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
330 |
context.update({'form': form, |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
331 |
'existing_user': user}) |
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
332 |
|
1fadf6e0348d
Add /site/user/profile Developer view for editing arbitrary User entities.
Todd Larsen <tlarsen@google.com>
parents:
141
diff
changeset
|
333 |
return response_helpers.respond(request, template, context) |
205
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
334 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
335 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
336 |
class CreateForm(forms_helpers.DbModelForm): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
337 |
"""Django form displayed when Developer creates a User. |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
338 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
339 |
This form is manually specified, instead of using |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
340 |
model = soc.models.user.User |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
341 |
in the Meta class, because the form behavior is unusual and normally |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
342 |
required Properties of the User model need to sometimes be omitted. |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
343 |
""" |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
344 |
id = forms.EmailField( |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
345 |
label=soc.models.user.User.id.verbose_name, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
346 |
help_text=soc.models.user.User.id.help_text) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
347 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
348 |
link_name = forms.CharField( |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
349 |
label=soc.models.user.User.link_name.verbose_name, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
350 |
help_text=soc.models.user.User.link_name.help_text) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
351 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
352 |
nick_name = forms.CharField( |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
353 |
label=soc.models.user.User.nick_name.verbose_name) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
354 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
355 |
is_developer = forms.BooleanField(required=False, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
356 |
label=soc.models.user.User.is_developer.verbose_name, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
357 |
help_text=soc.models.user.User.is_developer.help_text) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
358 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
359 |
class Meta: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
360 |
model = None |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
361 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
362 |
def clean_link_name(self): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
363 |
link_name = self.cleaned_data.get('link_name') |
260
8b393bef717a
Fix typo in recent validate.py changes (r682).
Todd Larsen <tlarsen@google.com>
parents:
249
diff
changeset
|
364 |
if not validate.isLinkNameFormatValid(link_name): |
205
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
365 |
raise forms.ValidationError("This link name is in wrong format.") |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
366 |
else: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
367 |
if id_user.doesLinkNameExist(link_name): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
368 |
raise forms.ValidationError("This link name is already in use.") |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
369 |
return link_name |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
370 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
371 |
def clean_id(self): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
372 |
new_email = self.cleaned_data.get('id') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
373 |
form_id = users.User(email=new_email) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
374 |
if id_user.isIdUser(form_id): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
375 |
raise forms.ValidationError("This account is already in use.") |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
376 |
return form_id |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
377 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
378 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
379 |
DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/site/user/profile/edit.html' |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
380 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
381 |
def create(request, template=DEF_SITE_CREATE_USER_PROFILE_TMPL): |
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
382 |
"""View for a Developer to create a new User Model entity. |
205
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
383 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
384 |
Args: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
385 |
request: the standard django request object |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
386 |
template: the "sibling" template (or a search list of such templates) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
387 |
from which to construct the public.html template name (or names) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
388 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
389 |
Returns: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
390 |
A subclass of django.http.HttpResponse which either contains the form to |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
391 |
be filled out, or a redirect to the correct view in the interface. |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
392 |
""" |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
393 |
# create default template context for use with any templates |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
394 |
context = response_helpers.getUniversalContext(request) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
395 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
396 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
397 |
context=context) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
398 |
if alt_response: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
399 |
return alt_response |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
400 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
401 |
if request.method == 'POST': |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
402 |
form = CreateForm(request.POST) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
403 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
404 |
if form.is_valid(): |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
405 |
form_id = form.cleaned_data.get('id') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
406 |
new_linkname = form.cleaned_data.get('link_name') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
407 |
nickname = form.cleaned_data.get('nick_name') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
408 |
is_developer = form.cleaned_data.get('is_developer') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
409 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
410 |
user = id_user.updateOrCreateUserFromId(id=form_id, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
411 |
link_name=new_linkname, nick_name=nickname, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
412 |
is_developer=is_developer) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
413 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
414 |
if not user: |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
415 |
return http.HttpResponseRedirect('/') |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
416 |
|
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
417 |
# redirect to new /site/user/profile/new_linkname?s=0 |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
418 |
# (causes 'Profile saved' message to be displayed) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
419 |
return response_helpers.redirectToChangedSuffix( |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
420 |
request, None, new_linkname, |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
421 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
422 |
else: # method == 'GET': |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
423 |
# no link name specified, so start with an empty form |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
424 |
form = CreateForm() |
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
425 |
|
210
d05444cf4641
Replaced context.update call to simple value assignment in site.user.profile.create view function.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
205
diff
changeset
|
426 |
context['form'] = form |
205
4a86df751222
Fixed not working "Create New User" view which was caused by adding key_name into User Edit Developer view. This commit divides edit() view function in soc.views.site.user.profile into edit() and create() request handlers. New create() request handler is used only in "Create New User" view and has specific form validation functions and uses updateOrCreateUserFromId() instead of updateUserForKeyName().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
190
diff
changeset
|
427 |
|
229
a46c238be8db
Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
428 |
return response_helpers.respond(request, template, context) |