Style fixes and removal of unused imports in soc.views.models.
[Melange.git] / app / soc / views / models / presence_with_tos.py
blob22bef824f47cec4c7a9384145a2323997db65279
1 #!/usr/bin/python2.5
3 # Copyright 2009 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 PresenceWithToS.
18 """
20 __authors__ = [
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
25 from google.appengine.ext import db
27 from django.utils.translation import ugettext
29 from soc.logic import cleaning
30 from soc.logic import dicts
31 from soc.views.models import presence
32 from soc.views.helper import widgets
34 import soc.logic.models.presence_with_tos
35 import soc.models.work
38 class View(presence.View):
39 """View methods for the PresenceWithToS model.
40 """
42 def __init__(self, params):
43 """Defines the fields and methods required for the base View class
44 to provide the user with list, public, create, edit and delete views.
46 Params:
47 params: a dict with params for this View
48 """
50 new_params = {}
51 new_params['extra_dynaexclude'] = ['tos']
53 new_params['edit_extra_dynaproperties'] = {
54 'tos_link_id': widgets.ReferenceField(
55 reference_url='document', filter=['scope_path'], required=False,
56 filter_fields={'prefix': params['document_prefix']},
57 label=ugettext('Terms of Service Document link ID'),
58 help_text=soc.models.work.Work.link_id.help_text),
59 'clean': cleaning.clean_refs(params,
60 ['home_link_id', 'tos_link_id']),
63 params = dicts.merge(params, new_params, sub_merge=True)
65 super(View, self).__init__(params=params)
67 def _editGet(self, request, entity, form):
68 """See base.View._editGet().
69 """
71 try:
72 if entity.tos:
73 form.fields['tos_link_id'].initial = entity.tos.link_id
74 except db.Error:
75 pass
77 super(View, self)._editGet(request, entity, form)
79 def _editPost(self, request, entity, fields):
80 """See base.View._editPost().
81 """
83 if 'tos_link_id' not in fields:
84 return super(View, self)._editPost(request, entity, fields)
86 tos_doc = fields.get('resolved_tos_link_id')
87 fields['tos'] = tos_doc
89 super(View, self)._editPost(request, entity, fields)