author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 15 Nov 2008 16:17:11 +0000 | |
changeset 482 | 839740b061ad |
parent 408 | 7cd6bdfbf95c |
child 500 | 44ea4620c5c0 |
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 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
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
|
37 |
from soc.views import helper |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
38 |
from soc.views.helper import decorators |
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 |
|
408
7cd6bdfbf95c
Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
365
diff
changeset
|
43 |
class EditForm(helper.forms.BaseForm): |
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 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
57 |
@decorators.view |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
408
diff
changeset
|
58 |
def edit(request, page_name=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
|
59 |
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
|
60 |
"""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
|
61 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
Args: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
|
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
Returns: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
""" |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
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
|
73 |
if not user: |
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
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
|
75 |
|
66
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
76 |
# TODO(tlarsen) |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
77 |
# if program: |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
78 |
# 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
|
79 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
80 |
# TODO(tlarsen) |
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
274
diff
changeset
|
81 |
# 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
|
82 |
# 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
|
83 |
# 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
|
84 |
# else: |
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
85 |
# 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
|
86 |
# 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
|
87 |
|
8c86470746fc
Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents:
54
diff
changeset
|
88 |
form = EditForm() |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
|
31
8b43c541afa7
First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
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
|
96 |
template, dictionary={'template': template, 'form': form, 'user': user, |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
358
diff
changeset
|
97 |
'program': program, 'link_name': link_name}) |