1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """Views of Person entity contents, a "profile". |
|
18 |
|
19 edit: read-write form for modifying Person fields |
|
20 |
|
21 TODO: |
|
22 public: read-only view of "public-only" Person fields |
|
23 """ |
|
24 |
|
25 __authors__ = [ |
|
26 '"Augie Fackler" <durin42@gmail.com>', |
|
27 '"Todd Larsen" <tlarsen@google.com>', |
|
28 ] |
|
29 |
|
30 |
|
31 from google.appengine.api import users |
|
32 |
|
33 from django import http |
|
34 from django import shortcuts |
|
35 |
|
36 from soc.models import person |
|
37 from soc.views import helper |
|
38 from soc.views.helper import decorators |
|
39 |
|
40 import soc.views.helper.forms |
|
41 |
|
42 |
|
43 class EditForm(helper.forms.BaseForm): |
|
44 """Django form displayed when creating or editing a Person. |
|
45 """ |
|
46 |
|
47 class Meta: |
|
48 """Inner Meta class that defines some behavior for the form. |
|
49 """ |
|
50 #: db.Model subclass for which the form will gather information |
|
51 model = person.Person |
|
52 |
|
53 #: list of model fields which will *not* be gathered by the form |
|
54 exclude = ['user'] |
|
55 |
|
56 |
|
57 @decorators.view |
|
58 def edit(request, page_name=None, program=None, link_id=None, |
|
59 template='soc/person/profile/edit.html'): |
|
60 """View for a Person to modify the properties of a Person Model. |
|
61 |
|
62 Args: |
|
63 request: the standard django request object. |
|
64 page_name: the page name displayed in templates as page and header title |
|
65 template: the template path to use for rendering the template. |
|
66 |
|
67 Returns: |
|
68 A subclass of django.http.HttpResponse which either contains the form to |
|
69 be filled out, or a redirect to the correct view in the interface. |
|
70 """ |
|
71 user = users.get_current_user() |
|
72 if not user: |
|
73 return http.HttpResponseRedirect(users.create_login_url(request.path)) |
|
74 |
|
75 # TODO(tlarsen) |
|
76 # if program: |
|
77 # query for the human-readable program name and pass that to the form |
|
78 |
|
79 # TODO(tlarsen) |
|
80 # if link_id: |
|
81 # query for a site-wide user profile for a friendly display name |
|
82 # to use in the greeting |
|
83 # else: |
|
84 # use user to query for a site-wide user profile for a friendly |
|
85 # display name to use in the greeting |
|
86 |
|
87 form = EditForm() |
|
88 if request.method == 'POST': |
|
89 form = EditForm(request.POST) |
|
90 |
|
91 if not form.errors: |
|
92 return http.HttpResponse('This would update the model') |
|
93 |
|
94 return shortcuts.render_to_response( |
|
95 template, dictionary={'template': template, 'form': form, 'user': user, |
|
96 'program': program, 'link_id': link_id}) |
|