Remove stop parameter from home_settings and site_settings views. This is something...
[Melange.git] / app / soc / views / models / home_settings.py
blob8ad845c1a543dcbad03c4f269f41366f74d5989c
1 #!/usr/bin/python2.5
3 # Copyright 2008 the Melange authors.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """Views for Home Settings.
18 """
20 __authors__ = [
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
25 from google.appengine.ext import db
26 from google.appengine.api import users
28 from django import forms
29 from django.utils.translation import ugettext_lazy
31 from soc.logic import dicts
32 from soc.logic import validate
33 from soc.logic.models import document as document_logic
34 from soc.views import helper
35 from soc.views.helper import widgets
36 from soc.views.models import base
38 import soc.models.home_settings
39 import soc.logic.models.home_settings
40 import soc.logic.dicts
41 import soc.views.helper
42 import soc.views.helper.widgets
45 class SettingsValidationForm(helper.forms.BaseForm):
46 """Django form displayed when creating or editing Settings.
48 This form includes validation functions for Settings fields.
49 """
51 # TODO(tlarsen): partial_path will be a hard-coded read-only
52 # field for some (most?) User Roles
53 doc_partial_path = forms.CharField(required=False,
54 label=soc.models.work.Work.partial_path.verbose_name,
55 help_text=soc.models.work.Work.partial_path.help_text)
57 # TODO(tlarsen): actually, using these two text fields to specify
58 # the Document is pretty cheesy; this needs to be some much better
59 # Role-scoped Document selector that we don't have yet
60 doc_link_name = forms.CharField(required=False,
61 label=soc.models.work.Work.link_name.verbose_name,
62 help_text=soc.models.work.Work.link_name.help_text)
64 def clean_feed_url(self):
65 feed_url = self.cleaned_data.get('feed_url')
67 if feed_url == '':
68 # feed url not supplied (which is OK), so do not try to validate it
69 return None
71 if not validate.isFeedURLValid(feed_url):
72 raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
74 return feed_url
77 class CreateForm(SettingsValidationForm):
78 """Django form displayed when creating or editing Settings.
79 """
81 class Meta:
82 """Inner Meta class that defines some behavior for the form.
83 """
84 #: db.Model subclass for which the form will gather information
85 model = soc.models.home_settings.HomeSettings
87 #: list of model fields which will *not* be gathered by the form
88 exclude = ['inheritance_line', 'home']
91 class EditForm(CreateForm):
92 """Django form displayed a Document is edited.
93 """
95 pass
98 class View(base.View):
99 """View methods for the Docs model
102 def __init__(self, original_params=None, original_rights=None):
103 """Defines the fields and methods required for the base View class
104 to provide the user with list, public, create, edit and delete views.
106 Params:
107 original_params: a dict with params for this View
108 original_rights: a dict with right definitions for this View
111 params = {}
112 rights = {}
114 params['name'] = "Home Settings"
115 params['name_short'] = "Home"
116 params['name_plural'] = "Home Settings"
118 params['edit_form'] = EditForm
119 params['create_form'] = CreateForm
121 # TODO(tlarsen) Add support for Django style template lookup
122 params['edit_template'] = 'soc/models/edit.html'
123 params['public_template'] = 'soc/home_settings/public.html'
124 params['list_template'] = 'soc/models/list.html'
126 params['lists_template'] = {
127 'list_main': 'soc/list/list_main.html',
128 'list_pagination': 'soc/list/list_pagination.html',
129 'list_row': 'soc/home_settings/list/home_row.html',
130 'list_heading': 'soc/home_settings/list/home_heading.html',
133 params['delete_redirect'] = '/home/list'
134 params['create_redirect'] = '/home/edit'
136 params['save_message'] = [ugettext_lazy('Profile saved.')]
138 params['edit_params'] = {
139 self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
142 rights['list'] = [helper.access.checkIsDeveloper]
143 rights['delete'] = [helper.access.checkIsDeveloper]
145 params = dicts.merge(original_params, params)
146 rights = dicts.merge(original_rights, rights)
148 base.View.__init__(self, rights=rights, params=params)
150 self._logic = soc.logic.models.home_settings.logic
152 def _public(self, request, entity, context):
156 if not entity:
157 return
159 try:
160 home_doc = entity.home
161 except db.Error:
162 home_doc = None
164 if home_doc:
165 home_doc.content = helper.templates.unescape(home_doc.content)
166 context['home_document'] = home_doc
168 def _editGet(self, request, entity, form):
169 """See base.View._editGet().
172 try:
173 if entity.home:
174 form.fields['doc_partial_path'].initial = entity.home.partial_path
175 form.fields['doc_link_name'].initial = entity.home.link_name
176 except db.Error:
177 pass
179 def _editPost(self, request, entity, fields):
180 """See base.View._editPost().
183 doc_partial_path = fields['doc_partial_path']
184 doc_link_name = fields['doc_link_name']
186 # TODO notify the user if home_doc is not found
187 home_doc = document_logic.logic.getFromFields(
188 partial_path=doc_partial_path, link_name=doc_link_name)
190 fields['home'] = home_doc
193 view = View()
195 create = view.create
196 edit = view.edit
197 delete = view.delete
198 list = view.list
199 public = view.public