app/soc/views/models/document.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 07 Feb 2009 20:40:48 +0000
changeset 1241 5e25cd6abe09
parent 1181 6fb4134e1dfc
child 1262 e2e5b7798746
permissions -rw-r--r--
Pimp TinyMCE widget. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    31
from soc.logic import cleaning
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.logic import validate
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
    34
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
    35
from soc.logic.models.user import logic as user_logic
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    36
from soc.models import linkable
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.views import helper
699
4e8eefe95748 Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
    38
from soc.views.helper import access
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
    39
from soc.views.helper import params as params_helper
705
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
    40
from soc.views.helper import redirects
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
from soc.views.models import base
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
import soc.models.document
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
import soc.logic.models.document
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
import soc.logic.dicts
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
import soc.views.helper
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
import soc.views.helper.widgets
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
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
    49
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
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
    51
  """View methods for the Document model.
400
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
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    54
  def __init__(self, params=None):
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
    """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
    56
    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
    57
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    59
      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
    60
    """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 934
diff changeset
    62
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 934
diff changeset
    63
    rights['any_access'] = ['allow']
1135
24d695060863 Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1095
diff changeset
    64
    rights['show'] = ['checkIsDocumentReadable']
24d695060863 Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1095
diff changeset
    65
    rights['create'] = ['checkIsUser']
24d695060863 Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1095
diff changeset
    66
    rights['edit'] = ['checkIsDocumentWritable']
24d695060863 Hook up the ACL system for documents.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1095
diff changeset
    67
    rights['delete'] = ['checkIsDocumentWritable']
699
4e8eefe95748 Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
    68
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    69
    new_params = {}
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    70
    new_params['logic'] = document_logic
699
4e8eefe95748 Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
    71
    new_params['rights'] = rights
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    73
    new_params['name'] = "Document"
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    74
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    75
    new_params['export_content_type'] = 'text/text'
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    76
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    77
    names = [i for i in document_logic.getKeyFieldNames() if i != 'link_id']
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    78
    create_pattern = params_helper.getPattern(names, linkable.SCOPE_PATH_ARG_PATTERN)
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    79
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    80
    new_params['extra_django_patterns'] = [
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    81
        (r'^document/(?P<access_type>create)/%s$' % create_pattern,
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    82
        'soc.views.models.%(module_name)s.create', 'Create %(name_short)s')]
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    83
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    84
    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
    85
    new_params['no_create_with_key_fields'] = True
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    87
    new_params['create_extra_dynafields'] = {
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    88
        'content': forms.fields.CharField(
1241
5e25cd6abe09 Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1181
diff changeset
    89
            widget=helper.widgets.TinyMCE(attrs={'rows': 25, 'cols': 100})),
1095
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    90
        '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
    91
                                             required=True),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    92
        'prefix': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    93
                                        required=True),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    94
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    95
        '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
    96
        'clean_scope_path': cleaning.clean_scope_path('scope_path'),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    97
        }
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    98
    new_params['extra_dynaexclude'] = ['author', 'created',
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    99
                                       'modified_by', 'modified']
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   100
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   101
    new_params['edit_extra_dynafields'] = {
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   102
        'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   103
        'created_by': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   104
                                             required=False),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   105
        'last_modified_by': forms.fields.CharField(
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   106
            widget=helper.widgets.ReadOnlyInput(), required=False),
0122dc66e5d2 Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   107
        }
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   109
    params = dicts.merge(params, new_params)
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   111
    super(View, self).__init__(params=params)
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
  def _editPost(self, request, entity, fields):
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 400
diff changeset
   114
    """See base.View._editPost().
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
    """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
1181
6fb4134e1dfc Calling getForCurrentAccount where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1145
diff changeset
   117
    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
   118
584
ba8a624506e5 Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   119
    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
   120
      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
   121
    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
   122
      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
   123
584
ba8a624506e5 Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
   124
    fields['modified_by'] = user
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   126
    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
   127
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
  def _editGet(self, request, entity, form):
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 400
diff changeset
   129
    """See base.View._editGet().
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
    """
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
    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
   133
    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
   134
    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
   135
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   136
    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
   137
705
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   138
  def getMenusForScope(self, entity, params):
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   139
    """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
   140
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   141
    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
   142
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   143
    Args:
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   144
      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
   145
      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
   146
    """
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   147
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   148
    filter = {
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   149
        'scope_path': entity.key().name(),
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   150
        'is_featured': True,
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   151
        }
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   152
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   153
    entities = self._logic.getForFields(filter)
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
    submenus = []
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   156
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   157
    # 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
   158
    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
   159
    submenus.append(submenu)
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
    # 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
   162
    for entity in entities:
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   163
      submenu = (redirects.getPublicRedirect(entity, self._params),
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 705
diff changeset
   164
                 entity.short_name, 'show')
705
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   165
      submenus.append(submenu)
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   166
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   167
    return submenus
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 699
diff changeset
   168
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   169
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   170
view = View()
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   171
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   172
create = view.create
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   173
edit = view.edit
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   174
delete = view.delete
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
list = view.list
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   177
export = view.export
934
9fcc08971efe Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 923
diff changeset
   178
pick = view.pick