Skip to content

Commit

Permalink
Merge remote-tracking branch 'Kotti/master'
Browse files Browse the repository at this point in the history
* Kotti/master:
  Added a paragraph in the developer manual about registering views for context
  Also test counter increase when blacklist has names with numbers
  Improve title_to_name handling of numbers in titles
  Added changelog entry for restricting add views
  Added a paragraph in the developer manual about registering views for context
  Added changelog entry for restricting add views
  Allow restricting addview to specific contexts.
  Allow restricting addview to specific contexts.
  • Loading branch information
disko committed Jan 29, 2015
2 parents a849085 + 0258ea6 commit fc3c17e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Change History
1.0.0-alpha.4 - unreleased
--------------------------

- Allow restricting *add views* to specific contexts. This allows third party
developers to register new content types that are addable in specific
type of contexts, by specifying ``context=SomeContentType`` in their
*add view* registration and having ``type_info.addable=['SomeContentType']``
in the type info.

- For documents with duplicate titles that end in a number, append a counter
instead of incrementing their number. Fixes #245

Expand Down
6 changes: 6 additions & 0 deletions docs/developing/basic/developer-manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Document content type serves as an example here:
self.body = body
self.mime_type = mime_type
The ``add_view`` parameter of the ``type_info`` attribute is the name of a view
that can be used to construct a ``Document`` instance. This view has to be
available for all content types specified in ``addable_to`` parameter. See the
section below and the :ref:`adding-forms-and-a-view` section in the tutorial on
how to define a view restricted to a specific context.

You can configure the list of active content types in Kotti by
modifying the :ref:`kotti.available_types` setting.

Expand Down
2 changes: 2 additions & 0 deletions docs/first_steps/tut-2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Notable differences are:

- The ``type_info`` defines the title, the ``add_view`` view, and that choices may only be added *into* ``Poll`` items, with the line ``addable_to=[u'Poll']``.

.. _adding-forms-and-a-view:

Adding Forms and a View
-----------------------

Expand Down
4 changes: 2 additions & 2 deletions kotti/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ def addable(self, context, request):
:rtype: Boolean
"""

if view_permitted(context, request, self.add_view):
return context.type_info.name in self.addable_to
if context.type_info.name in self.addable_to:
return view_permitted(context, request, self.add_view)
else:
return False

Expand Down
22 changes: 22 additions & 0 deletions kotti/tests/test_node_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ def test_view_permitted_no(self, config, root):
request = DummyRequest()
assert Document.type_info.addable(root, request) is False

def test_addable_views_registered_to_some_context(self, config, root):

from kotti.resources import Document, File

_saved = Document.type_info.addable_to
Document.type_info.addable_to = ['File']

config.testing_securitypolicy(permissive=True)
config.add_view(
lambda context, request: {},
name=Document.type_info.add_view,
permission='add',
renderer='kotti:templates/edit/node.pt',
context=File,
)
request = DummyRequest()

assert Document.type_info.addable(Document(), request) is False
assert Document.type_info.addable(File(), request) is True

Document.type_info.addable_to = _saved


class TestNodePaste:
def test_get_non_existing_paste_item(self, root):
Expand Down

0 comments on commit fc3c17e

Please sign in to comment.