author | Todd Larsen <tlarsen@google.com> |
Tue, 26 Aug 2008 21:05:43 +0000 | |
changeset 102 | a2d3ac82142f |
parent 99 | 8c38b546a3cf |
child 118 | d2e61a490969 |
permissions | -rw-r--r-- |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
"""Views relevant to the User role. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
""" |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
] |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
|
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
24 |
import re |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
from google.appengine.api import users |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
27 |
from django import http |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
28 |
from django import shortcuts |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
29 |
from django import newforms as forms |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
30 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
31 |
from soc.views.helpers import forms_helpers |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
32 |
from soc.views.helpers import response_helpers |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
33 |
|
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
34 |
import soc.models.user |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
35 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
36 |
class UserForm(forms_helpers.DbModelForm): |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
37 |
"""Django form displayed when creating or editing a User. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
38 |
""" |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
39 |
LINKNAME_PATTERN = r'''(?x) |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
40 |
^ |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
41 |
[0-9a-z] # start with ASCII digit or lowercase |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
42 |
( |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
43 |
[0-9a-z] # additional ASCII digit or lowercase |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
44 |
| # -OR- |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
45 |
_[0-9a-z] # underscore and ASCII digit or lowercase |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
46 |
)* # zero or more of OR group |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
47 |
$''' |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
48 |
LINKNAME_REGEX = re.compile(LINKNAME_PATTERN) |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
49 |
|
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
50 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
51 |
class Meta: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
52 |
"""Inner Meta class that defines some behavior for the form. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
53 |
""" |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
#: db.Model subclass for which the form will gather information |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
55 |
model = soc.models.user.User |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
56 |
|
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
57 |
#: list of model fields which will *not* be gathered by the form |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
58 |
exclude = ['id'] |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
59 |
|
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
60 |
def clean_link_name(self): |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
61 |
linkname = self.cleaned_data.get('link_name') |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
62 |
linkname_user = soc.models.user.User.getUserForLinkname(linkname) |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
63 |
current_id = users.get_current_user() |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
64 |
# if linkname exist in datastore and doesn't belong to current user |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
65 |
if linkname_user and (linkname_user.id != current_id): |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
66 |
raise forms.ValidationError("This link name is already in use.") |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
67 |
elif not self.LINKNAME_REGEX.match(linkname): |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
68 |
raise forms.ValidationError("This link name is in wrong format.") |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
69 |
return linkname |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
71 |
|
85
426b4ca2a72a
Move soc.views.user.profile.profile() to soc.views.user.profile.edit().
Todd Larsen <tlarsen@google.com>
parents:
83
diff
changeset
|
72 |
def edit(request, linkname=None, template='soc/user/profile/edit.html'): |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
73 |
"""View for a User to modify the properties of a UserModel. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
74 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
75 |
Args: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
76 |
request: the standard django request object. |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
77 |
linkname: the User's site-unique "linkname" extracted from the URL |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
78 |
template: the template path to use for rendering the template. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
79 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
80 |
Returns: |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
81 |
A subclass of django.http.HttpResponse which either contains the form to |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
82 |
be filled out, or a redirect to the correct view in the interface. |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
83 |
""" |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
84 |
#TODO(solydzajs): create controller for User and cleanup code in this handler |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
85 |
|
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
86 |
#TODO(solydzajs): use makeSiblingTemplatePath from templates_helpers and pass |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
87 |
# result to public view |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
88 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
89 |
# TODO: use something like the code below, define global public tmpl |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
90 |
# template_choices = [makeSiblingTemplatePath(template, 'public.html'), |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
91 |
# DEF_USER_PROFILE_PUBLIC_TMPL]) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
92 |
# public(request, linkname=linkname, template=template_choices) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
93 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
94 |
#: If user not signed and there is no linkname redirect to sign-in page |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
95 |
#: otherwise show public profile for linkname user |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
96 |
current_id = users.get_current_user() |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
97 |
if not current_id and not linkname: |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
98 |
return http.HttpResponseRedirect(users.create_login_url(request.path)) |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
99 |
elif not current_id and linkname: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
100 |
return public(request, linkname) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
101 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
102 |
user = soc.models.user.User.getUserForId(current_id) |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
103 |
|
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
104 |
#: Show custom 404 page when linkname doesn't exist in datastore |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
105 |
#: or show public view for linkname user |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
106 |
if linkname: |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
107 |
linkname_user = soc.models.user.User.getUserForLinkname(linkname) |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
108 |
if not linkname_user: |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
109 |
return http.HttpResponseNotFound('No user exists with that link name "%s"' % |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
110 |
linkname) |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
111 |
elif linkname_user and (linkname_user.id != current_id): |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
112 |
return public(request, linkname) |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
113 |
|
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
114 |
#: GET method |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
115 |
if (request.method != 'POST') and user: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
116 |
form = UserForm(initial={'nick_name': user.nick_name, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
117 |
'link_name': user.link_name}) |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
118 |
return response_helpers.respond(request, |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
119 |
template, {'template': template, |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
120 |
'form': form, |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
121 |
'user': user}) |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
122 |
|
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
123 |
#: POST method |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
124 |
form = UserForm() |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
125 |
if request.method == 'POST': |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
126 |
form = UserForm(request.POST) |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
127 |
|
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
128 |
if form.is_valid(): |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
129 |
linkname = form.cleaned_data.get('link_name') |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
130 |
nickname = form.cleaned_data.get("nick_name") |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
131 |
if not user: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
132 |
user = soc.models.user.User(id = user,link_name = linkname, |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
133 |
nick_name = nickname) |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
134 |
else: |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
135 |
user.nick_name = nickname |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
136 |
user.link_name = linkname |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
137 |
user.put() |
98
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
138 |
return response_helpers.respond(request, |
b2b823466a8b
User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
85
diff
changeset
|
139 |
template, {'template': template, |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
140 |
'form': form, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
141 |
'user': user, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
142 |
'submit_message': 'Profile saved.'}) |
83
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
143 |
|
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
144 |
return response_helpers.respond(request, |
3f4f7c540b75
Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
145 |
template, {'template': template, 'form': form}) |
99
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
146 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
147 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
148 |
def public(request, linkname=None, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
149 |
template='soc/user/profile/public.html'): |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
150 |
"""A "general public" view of a User on the site. |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
151 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
152 |
Args: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
153 |
request: the standard django request object. |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
154 |
linkname: the User's site-unique "linkname" extracted from the URL |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
155 |
template: the template path to use for rendering the template. |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
156 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
157 |
Returns: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
158 |
A subclass of django.http.HttpResponse with generated template. |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
159 |
""" |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
160 |
#: If linkname is empty or not a valid linkname on the site, display |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
161 |
#: "user does not exist", otherwise render public view for linkname user |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
162 |
if linkname: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
163 |
linkname_user = soc.models.user.User.getUserForLinkname(linkname) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
164 |
if not linkname_user: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
165 |
return http.HttpResponseNotFound('No user exists with that link name "%s"' % |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
166 |
linkname) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
167 |
else: |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
168 |
return response_helpers.respond(request, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
169 |
template, {'template': template, |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
170 |
'user': linkname_user}) |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
171 |
|
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
172 |
return http.HttpResponseNotFound('No user exists with that link name "%s"' % |
8c38b546a3cf
Added public view support (not using controller yet)
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
98
diff
changeset
|
173 |
linkname) |