author | Lennard de Rijk <ljvderijk@gmail.com> |
Mon, 29 Jun 2009 23:16:21 +0200 | |
changeset 2452 | 4abc27894b61 |
parent 2386 | a518ea56f6b5 |
child 2748 | 7fbc98f3adde |
permissions | -rw-r--r-- |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
476
3b0662786f95
Fixed typo in docstring
Sverre Rabbelier <srabbelier@gmail.com>
parents:
462
diff
changeset
|
17 |
"""Views for Documents. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
429
e50e18936f06
Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents:
408
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
462
1f164cd0529b
Adds a check to logic/valididate.py that checks the partial path format using a regexp. This regexp has been added to logic/path_link_name.py, therefore changing PATH_LINKNAME_REGEX to use the PARTIAL_PATH in building this regexp. Plus views/models/docs.py now uses the validation functions in the clean_ methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
448
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
] |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import forms |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
29 |
from soc.logic import cleaning |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
1145
b2034ab78e3a
Fix import sorting in soc.views.models.document module to comply with our style guide.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1135
diff
changeset
|
31 |
from soc.logic.models.document import logic as document_logic |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
32 |
from soc.logic.models.user import logic as user_logic |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
33 |
from soc.views.helper import access |
1583 | 34 |
from soc.views.helper import decorators |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
35 |
from soc.views.helper import redirects |
1642
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
36 |
from soc.views.helper import widgets |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
from soc.views.models import base |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
629
492df53e4a0f
Add missing dots and fix too long line in soc.views.helper.dynaform module. Remove unused imports in soc.views.models.document module. Fix too long lines. Add missing docstring for Meta classes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
605
diff
changeset
|
39 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
class View(base.View): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
494
diff
changeset
|
41 |
"""View methods for the Document model. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
44 |
def __init__(self, params=None): |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
"""Defines the fields and methods required for the base View class |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
to provide the user with list, public, create, edit and delete views. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
Params: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
49 |
params: a dict with params for this View |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
|
1007
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
934
diff
changeset
|
52 |
rights = access.Checker(params) |
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
934
diff
changeset
|
53 |
rights['any_access'] = ['allow'] |
1135
24d695060863
Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1095
diff
changeset
|
54 |
rights['show'] = ['checkIsDocumentReadable'] |
24d695060863
Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1095
diff
changeset
|
55 |
rights['create'] = ['checkIsUser'] |
24d695060863
Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1095
diff
changeset
|
56 |
rights['edit'] = ['checkIsDocumentWritable'] |
24d695060863
Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1095
diff
changeset
|
57 |
rights['delete'] = ['checkIsDocumentWritable'] |
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1316
diff
changeset
|
58 |
rights['list'] = ['checkDocumentList'] |
1305
9567bb475d6d
Do access checks on the pick url for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
59 |
rights['pick'] = ['checkDocumentPick'] |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
60 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
61 |
new_params = {} |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
62 |
new_params['logic'] = document_logic |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
63 |
new_params['rights'] = rights |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
|
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
65 |
new_params['name'] = "Document" |
1480
d2d9087d712f
Make all default URLS customizable
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1446
diff
changeset
|
66 |
new_params['pickable'] = True |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
67 |
|
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
68 |
new_params['export_content_type'] = 'text/text' |
1399
5b154edd94ac
Make it easier to support other extensions per-Model (such as .csv, etc.).
Todd Larsen <tlarsen@google.com>
parents:
1343
diff
changeset
|
69 |
new_params['export_extension'] = '.html' |
1805
7204ec5ead23
Factor download functionality out of export()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1682
diff
changeset
|
70 |
new_params['export_function'] = lambda x: (x.content, x.link_id) |
1671
7959bc7b77a9
Don't redirect to non-existant /document/list after deleting
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1642
diff
changeset
|
71 |
new_params['delete_redirect'] = '/' |
1813
5cc9e055a818
Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1805
diff
changeset
|
72 |
new_params['list_key_order'] = [ |
5cc9e055a818
Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1805
diff
changeset
|
73 |
'link_id', 'scope_path', 'name', 'short_name', 'title', |
5cc9e055a818
Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1805
diff
changeset
|
74 |
'content', 'prefix','read_access','write_access'] |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
75 |
|
1319
042347748c45
Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1318
diff
changeset
|
76 |
new_params['no_create_raw'] = True |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
77 |
new_params['no_create_with_scope'] = True |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
78 |
new_params['no_create_with_key_fields'] = True |
1319
042347748c45
Disable the raw create and list link for documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1318
diff
changeset
|
79 |
new_params['no_list_raw'] = True |
1324
8cf30dee8048
Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1319
diff
changeset
|
80 |
new_params['sans_link_id_create'] = True |
8cf30dee8048
Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1319
diff
changeset
|
81 |
new_params['sans_link_id_list'] = True |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
|
1875
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
83 |
new_params['create_dynafields'] = [ |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
84 |
{'name': 'link_id', |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
85 |
'base': forms.fields.CharField, |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
86 |
'label': 'Document Link ID', |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
87 |
}, |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
88 |
] |
69d60793092a
Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1813
diff
changeset
|
89 |
|
1430
ff8cc6b15e6a
Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1416
diff
changeset
|
90 |
new_params['create_extra_dynaproperties'] = { |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
91 |
'content': forms.fields.CharField( |
1642
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
92 |
widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
93 |
'scope_path': forms.fields.CharField(widget=forms.HiddenInput, |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
94 |
required=True), |
1642
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
95 |
'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
96 |
required=True), |
1682
242ca517c340
Make clean_document_content generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1671
diff
changeset
|
97 |
'clean_content': cleaning.clean_html_content('content'), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
98 |
'clean_link_id': cleaning.clean_link_id('link_id'), |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
99 |
'clean_scope_path': cleaning.clean_scope_path('scope_path'), |
1988
d826f7aed8f2
Make sure the user has restricted rights to create a new document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1875
diff
changeset
|
100 |
'clean': cleaning.validate_document_acl(self, True), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
101 |
} |
1416
6c94a1531ead
Add an home_for reference property
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1399
diff
changeset
|
102 |
new_params['extra_dynaexclude'] = ['author', 'created', 'home_for', |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
103 |
'modified_by', 'modified'] |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
104 |
|
1430
ff8cc6b15e6a
Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1416
diff
changeset
|
105 |
new_params['edit_extra_dynaproperties'] = { |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
106 |
'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput), |
1642
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
107 |
'created_by': forms.fields.CharField( |
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
108 |
widget=widgets.ReadOnlyInput(), required=False), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
109 |
'last_modified_by': forms.fields.CharField( |
1642
a9308b2462fc
Some style fixes and removal of unused imports in soc.views.models.document module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1584
diff
changeset
|
110 |
widget=widgets.ReadOnlyInput(), required=False), |
1988
d826f7aed8f2
Make sure the user has restricted rights to create a new document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1875
diff
changeset
|
111 |
'clean': cleaning.validate_document_acl(self), |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
112 |
} |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
113 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
114 |
params = dicts.merge(params, new_params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
115 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
116 |
super(View, self).__init__(params=params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
|
2076
1cd180cc56c9
Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2014
diff
changeset
|
118 |
def list(self, request, access_type, |
1cd180cc56c9
Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2014
diff
changeset
|
119 |
page_name=None, params=None, filter=None, order=None, **kwargs): |
1316
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
120 |
"""See base.View.list. |
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
121 |
""" |
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
122 |
|
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
123 |
return super(View, self).list(request, access_type, page_name=page_name, |
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
124 |
params=params, filter=kwargs) |
1ddf04976bee
Allow documents to be filtered by prefix and scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1311
diff
changeset
|
125 |
|
2382
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
126 |
def _public(self, request, entity, context): |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
127 |
"""Performs any processing needed for the Document's public page. |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
128 |
|
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
129 |
For args see base.View._public(). |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
130 |
""" |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
131 |
|
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
132 |
# check if the current user is allowed to visit the edit page |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
133 |
rights = self._params['rights'] |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
134 |
|
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
135 |
allowed_to_edit = False |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
136 |
try: |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
137 |
# use the IsDocumentWritable check because we have no django args |
2386
a518ea56f6b5
Fixed an issue where some access checks would fail due to missing arguments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2382
diff
changeset
|
138 |
rights.checkIsDocumentWritable({'key_name': entity.key().name(), |
a518ea56f6b5
Fixed an issue where some access checks would fail due to missing arguments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2382
diff
changeset
|
139 |
'prefix': entity.prefix, |
a518ea56f6b5
Fixed an issue where some access checks would fail due to missing arguments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2382
diff
changeset
|
140 |
'scope_path': entity.scope_path, |
a518ea56f6b5
Fixed an issue where some access checks would fail due to missing arguments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2382
diff
changeset
|
141 |
'link_id': entity.link_id}, |
2382
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
142 |
'key_name') |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
143 |
allowed_to_edit = True |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
144 |
except: |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
145 |
pass |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
146 |
|
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
147 |
if allowed_to_edit: |
2386
a518ea56f6b5
Fixed an issue where some access checks would fail due to missing arguments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2382
diff
changeset
|
148 |
# add the document edit redirect to the context |
2382
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
149 |
context['edit_redirect'] = redirects.getEditRedirect( |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
150 |
entity, {'url_name': 'document'}) |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
151 |
|
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
152 |
return super(View, self)._public(request, entity, context) |
3a6302dd346b
Added link to edit the Document on the Document's public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
153 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
154 |
def _editPost(self, request, entity, fields): |
402
021e86368600
Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents:
400
diff
changeset
|
155 |
"""See base.View._editPost(). |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
156 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
157 |
|
1181
6fb4134e1dfc
Calling getForCurrentAccount where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1145
diff
changeset
|
158 |
user = user_logic.getForCurrentAccount() |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
159 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
160 |
if not entity: |
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
161 |
fields['author'] = user |
588
d6ae9dd215fb
Fixes an error that occurs when moving the document by setting another link ID or Scope path. This is due to the fact that author is a required property in the Work model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
584
diff
changeset
|
162 |
else: |
d6ae9dd215fb
Fixes an error that occurs when moving the document by setting another link ID or Scope path. This is due to the fact that author is a required property in the Work model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
584
diff
changeset
|
163 |
fields['author'] = entity.author |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
164 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
165 |
fields['modified_by'] = user |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
166 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
167 |
super(View, self)._editPost(request, entity, fields) |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
168 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
169 |
def _editGet(self, request, entity, form): |
402
021e86368600
Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents:
400
diff
changeset
|
170 |
"""See base.View._editGet(). |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
171 |
""" |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
172 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
173 |
form.fields['created_by'].initial = entity.author.name |
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
174 |
form.fields['last_modified_by'].initial = entity.modified_by.name |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2076
diff
changeset
|
175 |
form.fields['doc_key_name'].initial = entity.key().id_or_name() |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
176 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
177 |
super(View, self)._editGet(request, entity, form) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
178 |
|
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
179 |
def getMenusForScope(self, entity, params): |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
180 |
"""Returns the featured menu items for one specifc entity. |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
181 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
182 |
A link to the home page of the specified entity is also included. |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
183 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
184 |
Args: |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
185 |
entity: the entity for which the entry should be constructed |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
186 |
params: a dict with params for this View. |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
187 |
""" |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
188 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
189 |
filter = { |
1262
e2e5b7798746
Changed document to also filter on the prefix when getting the documents for a scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1241
diff
changeset
|
190 |
'prefix' : params['url_name'], |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2076
diff
changeset
|
191 |
'scope_path': entity.key().id_or_name(), |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
192 |
'is_featured': True, |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
193 |
} |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
194 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
195 |
entities = self._logic.getForFields(filter) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
196 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
197 |
submenus = [] |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
198 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
199 |
# add a link to the home page |
923
5a10f6db154b
Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
200 |
submenu = (redirects.getHomeRedirect(entity, params), "Home", 'show') |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
201 |
submenus.append(submenu) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
202 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
203 |
# add a link to all featured documents |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
204 |
for entity in entities: |
1265
cecb2b35f805
Added allowsidebar to checkIsDocumentReadable.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1262
diff
changeset
|
205 |
#TODO only if a document is readable it might be added |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
206 |
submenu = (redirects.getPublicRedirect(entity, self._params), |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
705
diff
changeset
|
207 |
entity.short_name, 'show') |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
208 |
submenus.append(submenu) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
209 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
210 |
return submenus |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
211 |
|
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
212 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
213 |
view = View() |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
214 |
|
1584
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
215 |
admin = decorators.view(view.admin) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
216 |
create = decorators.view(view.create) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
217 |
edit = decorators.view(view.edit) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
218 |
delete = decorators.view(view.delete) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
219 |
list = decorators.view(view.list) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
220 |
public = decorators.view(view.public) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
221 |
export = decorators.view(view.export) |
d8ba8c917f37
Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1583
diff
changeset
|
222 |
pick = decorators.view(view.pick) |