author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 29 Nov 2008 18:30:58 +0000 | |
changeset 611 | 2ec30182e5f1 |
parent 606 | 65d35584ee31 |
child 623 | 01757248f7c3 |
permissions | -rw-r--r-- |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Views for Sponsor profiles. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
429
e50e18936f06
Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
583
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
] |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from google.appengine.api import users |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from django import forms |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from django.utils.translation import ugettext_lazy |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
|
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
363
diff
changeset
|
32 |
from soc.logic import dicts |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
33 |
from soc.logic import models |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from soc.views import helper |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
from soc.views.helper import widgets |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
from soc.views.models import base |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
import soc.models.sponsor |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
import soc.logic.models.sponsor |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
import soc.logic.dicts |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
import soc.views.helper |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
import soc.views.helper.widgets |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
class View(base.View): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
494
diff
changeset
|
46 |
"""View methods for the Sponsor model. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
49 |
def __init__(self, original_params=None): |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
"""Defines the fields and methods required for the base View class |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
to provide the user with list, public, create, edit and delete views. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
Params: |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
original_params: a dict with params for this View |
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
363
diff
changeset
|
55 |
""" |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
params = {} |
605
4a384d412640
Made _logic a param
Sverre Rabbelier <srabbelier@gmail.com>
parents:
603
diff
changeset
|
58 |
params['logic'] = soc.logic.models.sponsor.logic |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
params['name'] = "Sponsor" |
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
363
diff
changeset
|
61 |
params['name_short'] = "Sponsor" |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
params['name_plural'] = "Sponsors" |
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
63 |
# TODO(pawel.solyga): create url_name and module_name automatically |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
64 |
# from name. Make that work for all other Views too. Hopefully |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
65 |
# solution that will be implemented in base View. |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
66 |
params['url_name'] = "sponsor" |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
67 |
params['module_name'] = "sponsor" |
606 | 68 |
|
69 |
params['extra_dynaexclude'] = ['founder', 'home'] |
|
70 |
params['extra_dynafields'] = { |
|
71 |
'founded_by': forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
|
72 |
required=False), |
|
73 |
} |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
|
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
75 |
# TODO(tlarsen): Add support for Django style template lookup |
445
31927f21970d
Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
429
diff
changeset
|
76 |
params['edit_template'] = 'soc/sponsor/edit.html' |
31927f21970d
Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
429
diff
changeset
|
77 |
params['public_template'] = 'soc/group/public.html' |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
|
554
68c7a1dd3c52
Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents:
553
diff
changeset
|
79 |
params['list_row'] = 'soc/group/list/row.html' |
68c7a1dd3c52
Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents:
553
diff
changeset
|
80 |
params['list_heading'] = 'soc/group/list/heading.html' |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
81 |
|
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
363
diff
changeset
|
82 |
params = dicts.merge(original_params, params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
84 |
base.View.__init__(self, params=params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
|
583
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
86 |
def _editGet(self, request, entity, form): |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
87 |
"""See base.View._editGet(). |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
88 |
""" |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
89 |
|
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
90 |
# fill in the founded_by with data from the entity |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
91 |
form.fields['founded_by'].initial = entity.founder.name |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
92 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
def _editPost(self, request, entity, fields): |
402
021e86368600
Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents:
399
diff
changeset
|
94 |
"""See base.View._editPost(). |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
|
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
454
diff
changeset
|
97 |
account = users.get_current_user() |
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
454
diff
changeset
|
98 |
user = soc.logic.models.user.logic.getForFields({'account': account}, |
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
454
diff
changeset
|
99 |
unique=True) |
583
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
100 |
if not entity: |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
101 |
# only if we are creating a new entity we should fill in founder |
12960609a69c
Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
102 |
fields['founder'] = user |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
103 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
104 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
105 |
view = View() |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
106 |
|
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
107 |
create = view.create |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
108 |
delete = view.delete |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
109 |
edit = view.edit |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
110 |
list = view.list |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
111 |
public = view.public |