author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Thu, 16 Oct 2008 15:22:41 +0000 | |
changeset 358 | 843d83b87282 |
parent 324 | 05e21c089be6 |
child 365 | 74dec172944e |
permissions | -rw-r--r-- |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
17 |
"""Views of Person entity contents, a "profile". |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
18 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
19 |
edit: read-write form for modifying Person fields |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
20 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
21 |
TODO: |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
22 |
public: read-only view of "public-only" Person fields |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
""" |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
__authors__ = [ |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
'"Augie Fackler" <durin42@gmail.com>', |
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
27 |
'"Todd Larsen" <tlarsen@google.com>', |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
] |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
from google.appengine.api import users |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
299
diff
changeset
|
32 |
|
324
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
33 |
from django import forms |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
from django import http |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
from django import shortcuts |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
from soc.models import person |
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
66
diff
changeset
|
38 |
from soc.views import helper |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
299
diff
changeset
|
39 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
66
diff
changeset
|
40 |
import soc.views.helper.forms |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
66
diff
changeset
|
43 |
class EditForm(helper.forms.DbModelForm): |
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
44 |
"""Django form displayed when creating or editing a Person. |
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
45 |
""" |
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
46 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
class Meta: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
"""Inner Meta class that defines some behavior for the form. |
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
49 |
""" |
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
50 |
#: db.Model subclass for which the form will gather information |
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
51 |
model = person.Person |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
|
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
53 |
#: list of model fields which will *not* be gathered by the form |
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
54 |
exclude = ['user'] |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
|
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
57 |
def edit(request, page=None, program=None, link_name=None, |
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
58 |
template='soc/person/profile/edit.html'): |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
59 |
"""View for a Person to modify the properties of a Person Model. |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
Args: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
request: the standard django request object. |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
63 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
64 |
a Django view with sidebar menu info |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
template: the template path to use for rendering the template. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
Returns: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
A subclass of django.http.HttpResponse which either contains the form to |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
be filled out, or a redirect to the correct view in the interface. |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
""" |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
user = users.get_current_user() |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
if not user: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
return http.HttpResponseRedirect(users.create_login_url(request.path)) |
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
74 |
|
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
75 |
# TODO(tlarsen) |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
76 |
# if program: |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
77 |
# query for the human-readable program name and pass that to the form |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
78 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
79 |
# TODO(tlarsen) |
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
274
diff
changeset
|
80 |
# if link_name: |
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
81 |
# query for a site-wide user profile for a friendly display name |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
82 |
# to use in the greeting |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
83 |
# else: |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
84 |
# use user to query for a site-wide user profile for a friendly |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
85 |
# display name to use in the greeting |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
86 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
87 |
form = EditForm() |
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
if request.method=='POST': |
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
89 |
form = EditForm(request.POST) |
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
90 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
if not form.errors: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
return http.HttpResponse('This would update the model') |
39
fa3545f99c02
Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents:
32
diff
changeset
|
93 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
return shortcuts.render_to_response( |
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
95 |
template, dictionary={'template': template, 'form': form, 'user': user, |
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
274
diff
changeset
|
96 |
'program': program, 'link_name': link_name}) |