author | Sverre Rabbelier <srabbelier@gmail.com> |
Sun, 07 Dec 2008 17:02:10 +0000 | |
changeset 705 | 0ab17e14df95 |
parent 699 | 4e8eefe95748 |
child 710 | edb5dbb1dea7 |
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 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
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 google.appengine.api import users |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from django import forms |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import dicts |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic import validate |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
33 |
from soc.logic.models import user as user_logic |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from soc.views import helper |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
35 |
from soc.views.helper import access |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
36 |
from soc.views.helper import redirects |
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 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
import soc.models.document |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
import soc.logic.models.document |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
import soc.logic.dicts |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
import soc.views.helper |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
import soc.views.helper.widgets |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
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
|
45 |
|
408
7cd6bdfbf95c
Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
404
diff
changeset
|
46 |
class CreateForm(helper.forms.BaseForm): |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
"""Django form displayed when Developer creates a Document. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
content = forms.fields.CharField(widget=helper.widgets.TinyMCE( |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
attrs={'rows':10, 'cols':40})) |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
class Meta: |
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
|
54 |
"""Inner Meta class that defines some behavior for the form. |
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
|
55 |
""" |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
model = soc.models.document.Document |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
#: list of model fields which will *not* be gathered by the form |
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
59 |
exclude = ['author', 'created', 'modified_by', 'modified', 'scope'] |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
|
513
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
61 |
def clean_scope_path(self): |
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
62 |
scope_path = self.cleaned_data.get('scope_path') |
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
63 |
# TODO(tlarsen): combine path and link_id and check for uniqueness |
513
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
64 |
if not validate.isScopePathFormatValid(scope_path): |
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
65 |
raise forms.ValidationError("This scope path is in wrong format.") |
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
66 |
return scope_path |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
|
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
68 |
def clean_link_id(self): |
650
33b6dcae5615
Changed clean_link_id to convert the input to lower characters for user comfort.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
629
diff
changeset
|
69 |
link_id = self.cleaned_data.get('link_id').lower() |
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
70 |
# TODO(tlarsen): combine path and link_id and check for uniqueness |
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
71 |
if not validate.isLinkIdFormatValid(link_id): |
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
72 |
raise forms.ValidationError("This link ID is in wrong format.") |
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
73 |
return link_id |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
76 |
class EditForm(CreateForm): |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
"""Django form displayed a Document is edited. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
doc_key_name = forms.fields.CharField(widget=forms.HiddenInput) |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
required=False) |
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
|
83 |
last_modified_by = forms.fields.CharField( |
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
|
84 |
widget=helper.widgets.ReadOnlyInput(), required=False) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
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
|
88 |
"""View methods for the Document model. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
91 |
def __init__(self, params=None): |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
92 |
"""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
|
93 |
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
|
94 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
Params: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
96 |
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
|
97 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
98 |
|
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
99 |
rights = {} |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
100 |
rights['any_access'] = [access.allow] |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
101 |
rights['public'] = [access.checkIsDocumentPublic] |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
102 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
103 |
new_params = {} |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
104 |
new_params['logic'] = soc.logic.models.document.logic |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
105 |
new_params['rights'] = rights |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
106 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
107 |
new_params['name'] = "Document" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
108 |
new_params['name_short'] = "Document" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
109 |
new_params['name_plural'] = "Documents" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
110 |
new_params['url_name'] = "document" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
111 |
new_params['module_name'] = "document" |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
112 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
113 |
new_params['edit_form'] = EditForm |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
114 |
new_params['create_form'] = CreateForm |
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 |
params = dicts.merge(params, new_params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
118 |
super(View, self).__init__(params=params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
119 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
def _editPost(self, request, entity, fields): |
402
021e86368600
Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents:
400
diff
changeset
|
121 |
"""See base.View._editPost(). |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
122 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
|
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
477
diff
changeset
|
124 |
account = users.get_current_user() |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
125 |
user = user_logic.logic.getForFields({'account': account}, unique=True) |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
126 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
132 |
fields['modified_by'] = user |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
133 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
134 |
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
|
135 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
136 |
def _editGet(self, request, entity, form): |
402
021e86368600
Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents:
400
diff
changeset
|
137 |
"""See base.View._editGet(). |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
138 |
""" |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
139 |
|
584
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
140 |
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
|
141 |
form.fields['last_modified_by'].initial = entity.modified_by.name |
ba8a624506e5
Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
569
diff
changeset
|
142 |
form.fields['doc_key_name'].initial = entity.key().name() |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
143 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
144 |
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
|
145 |
|
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
146 |
def getMenusForScope(self, entity, params): |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
147 |
"""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
|
148 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
149 |
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
|
150 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
151 |
Args: |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
""" |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
155 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
156 |
filter = { |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
157 |
'scope_path': entity.key().name(), |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
158 |
'is_featured': True, |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
159 |
} |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
160 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
161 |
entities = self._logic.getForFields(filter) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
162 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
163 |
submenus = [] |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
164 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
165 |
# add a link to the home page |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
166 |
submenu = (redirects.getPublicRedirect(entity, params), "Home", 'public') |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
167 |
submenus.append(submenu) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
168 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
169 |
# 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
|
170 |
for entity in entities: |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
171 |
submenu = (redirects.getPublicRedirect(entity, self._params), |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
172 |
entity.short_name, 'public') |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
173 |
submenus.append(submenu) |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
174 |
|
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
175 |
return submenus |
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
176 |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
177 |
view = View() |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
178 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
179 |
create = view.create |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
180 |
edit = view.edit |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
181 |
delete = view.delete |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
182 |
list = view.list |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
183 |
public = view.public |