20 __authors__ = [ |
20 __authors__ = [ |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 '"Matthew Wilkes" <matthew@matthewwilkes.co.uk>', |
22 '"Matthew Wilkes" <matthew@matthewwilkes.co.uk>', |
23 ] |
23 ] |
24 |
24 |
|
25 |
25 import time |
26 import time |
26 |
|
27 from google.appengine.api import users |
|
28 from google.appengine.ext.db import Key |
|
29 |
27 |
30 from django import forms |
28 from django import forms |
31 |
29 |
32 from soc.logic import cleaning |
|
33 from soc.logic import dicts |
30 from soc.logic import dicts |
34 from soc.logic import validate |
|
35 from soc.logic.models.user import logic as user_logic |
31 from soc.logic.models.user import logic as user_logic |
36 from soc.logic.models.comment import logic as comment_logic |
32 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 |
33 from soc.views import helper |
41 from soc.views.helper import access |
34 from soc.views.helper import access |
42 from soc.views.helper import redirects |
35 from soc.views.helper import redirects |
43 from soc.views.helper import params as params_helper |
|
44 from soc.views.models import base |
36 from soc.views.models import base |
45 |
|
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 |
|
51 |
37 |
52 |
38 |
53 class View(base.View): |
39 class View(base.View): |
54 """View methods for the comment model. |
40 """View methods for the comment model. |
55 """ |
41 """ |
63 comment_on_name: e.g. 'Document' |
49 comment_on_name: e.g. 'Document' |
64 comment_on_url_name: e.g. 'document' |
50 comment_on_url_name: e.g. 'document' |
65 """ |
51 """ |
66 |
52 |
67 rights = access.Checker(params) |
53 rights = access.Checker(params) |
68 rights['create'] = [('checkSeeded', ['checkIsDocumentReadable','scope_path'])] |
54 rights['create'] = [('checkSeeded', ['checkIsDocumentReadable', |
69 rights['edit'] = [('checkIsMyEntity', [comment_logic,'author', True])] |
55 'scope_path'])] |
70 rights['delete'] = [('checkIsMyEntity', [comment_logic,'author', True])] |
56 rights['edit'] = [('checkIsMyEntity', [comment_logic, 'author', True])] |
|
57 rights['delete'] = [('checkIsMyEntity', [comment_logic, 'author', True])] |
71 |
58 |
72 new_params = {} |
59 new_params = {} |
73 new_params['logic'] = comment_logic |
60 new_params['logic'] = comment_logic |
74 new_params['rights'] = rights |
61 new_params['rights'] = rights |
75 |
62 |
93 } |
80 } |
94 new_params['extra_dynaexclude'] = ['author', 'link_id', 'modified_by'] |
81 new_params['extra_dynaexclude'] = ['author', 'link_id', 'modified_by'] |
95 |
82 |
96 new_params['edit_extra_dynaproperties'] = { |
83 new_params['edit_extra_dynaproperties'] = { |
97 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), |
84 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), |
98 'created_by': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
85 'created_by': forms.fields.CharField( |
99 required=False), |
86 widget=helper.widgets.ReadOnlyInput(), required=False), |
100 } |
87 } |
101 |
88 |
102 params = dicts.merge(params, new_params) |
89 params = dicts.merge(params, new_params) |
103 super(View, self).__init__(params=params) |
90 super(View, self).__init__(params=params) |
104 |
91 |
119 |
106 |
120 context['comment_on_url_name'] = self._params['comment_on_url_name'] |
107 context['comment_on_url_name'] = self._params['comment_on_url_name'] |
121 context['comment_on_name'] = self._params['comment_on_name'] |
108 context['comment_on_name'] = self._params['comment_on_name'] |
122 context['work_link'] = redirect |
109 context['work_link'] = redirect |
123 |
110 |
124 def _editPost(self, request, entity, fields, params=None): |
111 def _editPost(self, request, entity, fields): |
125 """See base.View._editPost(). |
112 """See base.View._editPost(). |
126 """ |
113 """ |
127 |
114 |
128 user = user_logic.getForCurrentAccount() |
115 user = user_logic.getForCurrentAccount() |
129 scope_path = fields['scope_path'] |
116 scope_path = fields['scope_path'] |
130 |
117 |
131 if not entity: |
118 if not entity: |
132 fields['author'] = user |
119 fields['author'] = user |
133 fields['link_id'] = 't%i' %(int(time.time()*100)) |
120 fields['link_id'] = 't%i' % (int(time.time()*100)) |
134 else: |
121 else: |
135 fields['author'] = entity.author |
122 fields['author'] = entity.author |
136 fields['link_id'] = entity.link_id |
123 fields['link_id'] = entity.link_id |
137 fields['modified_by'] = user |
124 fields['modified_by'] = user |
138 |
125 |