|
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 for Site Settings. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
22 ] |
|
23 |
|
24 |
|
25 from google.appengine.ext import db |
|
26 from google.appengine.api import users |
|
27 |
|
28 from django import forms |
|
29 from django.utils.translation import ugettext_lazy |
|
30 |
|
31 from soc.logic import dicts |
|
32 from soc.logic import validate |
|
33 from soc.views import helper |
|
34 from soc.views.helper import widgets |
|
35 from soc.views.models import presence |
|
36 |
|
37 import soc.models.site |
|
38 import soc.logic.models.site |
|
39 import soc.logic.dicts |
|
40 import soc.views.helper |
|
41 import soc.views.helper.widgets |
|
42 |
|
43 |
|
44 class CreateForm(presence.SettingsValidationForm): |
|
45 """Django form displayed when creating or editing Site Settings. |
|
46 """ |
|
47 |
|
48 class Meta: |
|
49 """Inner Meta class that defines some behavior for the form. |
|
50 """ |
|
51 #: db.Model subclass for which the form will gather information |
|
52 model = soc.models.site.Site |
|
53 |
|
54 #: list of model fields which will *not* be gathered by the form |
|
55 exclude = ['inheritance_line', 'home', 'scope_path', 'link_id'] |
|
56 |
|
57 scope_path = forms.CharField(widget=forms.HiddenInput) |
|
58 |
|
59 link_id = forms.CharField(widget=forms.HiddenInput) |
|
60 |
|
61 |
|
62 class EditForm(CreateForm): |
|
63 """Django form displayed a Document is edited. |
|
64 """ |
|
65 |
|
66 pass |
|
67 |
|
68 |
|
69 class View(presence.View): |
|
70 """View methods for the Document model. |
|
71 """ |
|
72 |
|
73 def __init__(self, original_params=None): |
|
74 """Defines the fields and methods required for the base View class |
|
75 to provide the user with list, public, create, edit and delete views. |
|
76 |
|
77 Params: |
|
78 original_params: a dict with params for this View |
|
79 """ |
|
80 |
|
81 params = {} |
|
82 |
|
83 # add ugettext_lazy ? |
|
84 params['name'] = "Site Settings" |
|
85 params['name_short'] = "Site Settings" |
|
86 params['name_plural'] = "Site Settings" |
|
87 # lower name and replace " " with "/" |
|
88 # for module name lower name and replace " " with "_" |
|
89 params['url_name'] = "site/settings" |
|
90 params['module_name'] = "site" |
|
91 |
|
92 params['edit_form'] = EditForm |
|
93 params['create_form'] = CreateForm |
|
94 |
|
95 params['lists_template'] = { |
|
96 'list_main': 'soc/list/list_main.html', |
|
97 'list_pagination': 'soc/list/list_pagination.html', |
|
98 'list_row': 'soc/site/list/site_row.html', |
|
99 'list_heading': 'soc/site/list/site_heading.html', |
|
100 } |
|
101 |
|
102 params['delete_redirect'] = '/' + params['url_name'] + '/list' |
|
103 |
|
104 params['sidebar_additional'] = [ ( '/' + params['url_name'] + '/edit', 'Edit Main Site Settings')] |
|
105 |
|
106 params = dicts.merge(original_params, params) |
|
107 |
|
108 presence.View.__init__(self, original_params=params) |
|
109 |
|
110 self._logic = soc.logic.models.site.logic |
|
111 |
|
112 def main_public(self, request, page_name=None, **kwargs): |
|
113 """Displays the main site settings page. |
|
114 |
|
115 Args: |
|
116 request: the standard Django HTTP request object |
|
117 page_name: the page name displayed in templates as page and header title |
|
118 kwargs: not used |
|
119 """ |
|
120 |
|
121 keys = self._logic.getKeyFieldNames() |
|
122 values = self._logic.getMainKeyValues() |
|
123 key_values = dicts.zip(keys, values) |
|
124 |
|
125 return self.public(request, page_name, **key_values) |
|
126 |
|
127 def main_edit(self, request, page_name=None, **kwargs): |
|
128 """Displays the edit page for the main site settings page. |
|
129 |
|
130 Args: |
|
131 request: the standard Django HTTP request object |
|
132 page_name: the page name displayed in templates as page and header title |
|
133 kwargs: not used |
|
134 """ |
|
135 |
|
136 keys = self._logic.getKeyFieldNames() |
|
137 values = self._logic.getMainKeyValues() |
|
138 key_values = dicts.zip(keys, values) |
|
139 |
|
140 return self.edit(request, page_name, seed=key_values, **key_values) |
|
141 |
|
142 def getDjangoURLPatterns(self): |
|
143 """See base.View.getDjangoURLPatterns(). |
|
144 """ |
|
145 |
|
146 patterns = super(View, self).getDjangoURLPatterns() |
|
147 patterns += [(r'^$','soc.views.models.site.main_public')] |
|
148 patterns += [(r'^' + self._params['url_name'] + '/edit$', |
|
149 'soc.views.models.site.main_edit')] |
|
150 return patterns |
|
151 |
|
152 view = View() |
|
153 |
|
154 create = view.create |
|
155 edit = view.edit |
|
156 delete = view.delete |
|
157 list = view.list |
|
158 public = view.public |
|
159 main_public = view.main_public |
|
160 main_edit = view.main_edit |