Remove some copy/pasted docstring in soc.views.models.comment module.
[Melange.git] / app / soc / views / models / comment.py
blob5af62f5c3a93c125da150d0bd463c0f28fbc241a
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 comments.
18 """
20 __authors__ = [
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
22 '"Matthew Wilkes" <matthew@matthewwilkes.co.uk>',
25 import time
27 from google.appengine.api import users
28 from google.appengine.ext.db import Key
30 from django import forms
32 from soc.logic import cleaning
33 from soc.logic import dicts
34 from soc.logic import validate
35 from soc.logic.models.user import logic as user_logic
36 from soc.logic.models.comment import logic as comment_logic
37 from soc.logic.models.document import logic as document_logic
38 from soc.logic.models.linkable import logic as link_logic
39 from soc.models import linkable
40 from soc.views import helper
41 from soc.views.helper import access
42 from soc.views.helper import redirects
43 from soc.views.helper import params as params_helper
44 from soc.views.models import base
46 import soc.models.comment
47 import soc.logic.models.comment
48 import soc.logic.dicts
49 import soc.views.helper
50 import soc.views.helper.widgets
53 class View(base.View):
54 """View methods for the comment model.
55 """
57 def __init__(self, params=None):
58 """Defines the fields and methods required for the base View class
59 to provide the user with list, public, create, edit and delete views.
61 Params:
62 params: a dict with params for this View
63 comment_on_name: e.g. 'Document'
64 comment_on_url_name: e.g. 'document'
65 """
67 rights = access.Checker(params)
68 rights['create'] = [('checkSeeded', ['checkIsDocumentReadable','scope_path'])]
69 rights['edit'] = [('checkIsMyEntity', [comment_logic,'author', True])]
70 rights['delete'] = [('checkIsMyEntity', [comment_logic,'author', True])]
72 new_params = {}
73 new_params['logic'] = comment_logic
74 new_params['rights'] = rights
76 new_params['name'] = "Comment"
78 new_params['create_template'] = 'soc/comment/edit.html'
79 new_params['edit_template'] = 'soc/comment/edit.html'
81 new_params['no_show'] = True
82 new_params['no_admin'] = True
83 new_params['no_create_raw'] = True
84 new_params['no_create_with_key_fields'] = True
85 new_params['no_list_raw'] = True
87 new_params['create_extra_dynaproperties'] = {
88 'on': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
89 required=False),
90 'content': forms.fields.CharField(
91 widget=helper.widgets.TinyMCE(attrs={'rows':10, 'cols':40})),
92 'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
94 new_params['extra_dynaexclude'] = ['author', 'link_id', 'modified_by']
96 new_params['edit_extra_dynaproperties'] = {
97 'link_id': forms.CharField(widget=forms.HiddenInput, required=True),
98 'created_by': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
99 required=False),
102 params = dicts.merge(params, new_params)
103 super(View, self).__init__(params=params)
105 def _editContext(self, request, context):
106 """see base.View._editContext.
109 entity = context['entity']
111 if entity:
112 on = entity.scope
113 else:
114 seed = context['seed']
115 on = seed['commented']
117 params = {'url_name': self._params['comment_on_url_name']}
118 redirect = redirects.getPublicRedirect(on, params)
120 context['comment_on_url_name'] = self._params['comment_on_url_name']
121 context['comment_on_name'] = self._params['comment_on_name']
122 context['work_link'] = redirect
124 def _editPost(self, request, entity, fields, params=None):
125 """See base.View._editPost().
128 user = user_logic.getForCurrentAccount()
129 scope_path = fields['scope_path']
131 if not entity:
132 fields['author'] = user
133 fields['link_id'] = 't%i' % (time.time())
134 else:
135 fields['author'] = entity.author
136 fields['link_id'] = entity.link_id
137 fields['modified_by'] = user
139 fields['commented'] = self._getWorkByKeyName(scope_path).key()
141 super(View, self)._editPost(request, entity, fields)
143 def _editGet(self, request, entity, form):
144 """See base.View._editGet().
147 form.fields['created_by'].initial = entity.author.name
148 form.fields['on'].initial = entity.scope.name
149 form.fields['link_id'].initial = entity.link_id
150 form.fields['scope_path'].initial = entity.scope_path
152 super(View, self)._editGet(request, entity, form)
154 def _getWorkByKeyName(self, keyname):
155 """Returns the work for the specified key name.
158 logic = self._params['comment_on_logic']
159 return logic.getFromKeyName(keyname)
161 def _editSeed(self, request, seed):
162 """See base._editSeed().
165 scope_path = seed['scope_path']
166 work = self._getWorkByKeyName(scope_path)
167 seed['on'] = work.title
168 seed['commented'] = work
170 def getMenusForScope(self, entity, params):
171 """Returns the featured menu items for one specifc entity.
173 A link to the home page of the specified entity is also included.
175 Args:
176 entity: the entity for which the entry should be constructed
177 params: a dict with params for this View.
180 return []