|
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 from django import http |
|
33 from django import shortcuts |
|
34 from django import newforms as forms |
|
35 |
|
36 from soc.models import person |
|
37 from soc.views.helpers import forms_helpers |
|
38 |
|
39 |
|
40 class EditForm(forms_helpers.DbModelForm): |
|
41 """Django form displayed when creating or editing a Person. |
|
42 """ |
|
43 |
|
44 class Meta: |
|
45 """Inner Meta class that defines some behavior for the form. |
|
46 """ |
|
47 #: db.Model subclass for which the form will gather information |
|
48 model = person.Person |
|
49 |
|
50 #: list of model fields which will *not* be gathered by the form |
|
51 exclude = ['user'] |
|
52 |
|
53 |
|
54 def edit(request, program=None, linkname=None, |
|
55 template='soc/person/profile/edit.html'): |
|
56 """View for a Person to modify the properties of a Person Model. |
|
57 |
|
58 Args: |
|
59 request: the standard django request object. |
|
60 template: the template path to use for rendering the template. |
|
61 |
|
62 Returns: |
|
63 A subclass of django.http.HttpResponse which either contains the form to |
|
64 be filled out, or a redirect to the correct view in the interface. |
|
65 """ |
|
66 user = users.get_current_user() |
|
67 if not user: |
|
68 return http.HttpResponseRedirect(users.create_login_url(request.path)) |
|
69 |
|
70 # TODO(tlarsen) |
|
71 # if program: |
|
72 # query for the human-readable program name and pass that to the form |
|
73 |
|
74 # TODO(tlarsen) |
|
75 # if linkname: |
|
76 # query for a site-wide user profile for a friendly display name |
|
77 # to use in the greeting |
|
78 # else: |
|
79 # use user to query for a site-wide user profile for a friendly |
|
80 # display name to use in the greeting |
|
81 |
|
82 form = EditForm() |
|
83 if request.method=='POST': |
|
84 form = EditForm(request.POST) |
|
85 |
|
86 if not form.errors: |
|
87 return http.HttpResponse('This would update the model') |
|
88 |
|
89 return shortcuts.render_to_response( |
|
90 template, dictionary={'template': template, 'form': form, 'user': user, |
|
91 'program': program, 'linkname': linkname}) |