Skip to content

Commit

Permalink
Merge pull request #519 from tiberiuichim/custom_request_class
Browse files Browse the repository at this point in the history
Use proper request (the one from kotti.request_factory setting) when rendering slot views
  • Loading branch information
tiberiuichim committed Dec 20, 2016
2 parents c922c57 + 8ce732e commit cf895a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Change History
1.3.1.dev0 - unreleased
-----------------------

- When rendering slot views, use ``request.blank()`` to create the request.
This is the proper behaviour, in tune with customizing
``kotti.request_factory``. Also added ``blank()`` method to
``kotti.testing.DummyRequest``.

- When authenticated, show workflow state in the edit bar. Before it was
shown only if the 'edit' permission was available.

Expand Down
22 changes: 22 additions & 0 deletions kotti/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ def is_response(ob):
return (hasattr(ob, 'app_iter') and hasattr(ob, 'headerlist') and
hasattr(ob, 'status'))

@classmethod
def blank(cls,
path, environ=None, base_url=None, headers=None, POST=None,
**kw):
"""
``request.blank`` is used in Kotti only when assigning slots, where
the POST parameters are faked as a querystring.
"""
import urlparse

def _decode(body):
if not body:
return {}
return dict([(x, y.decode('utf-8'))
for x, y in urlparse.parse_qsl(body)])

if POST and isinstance(POST, basestring):
POST = _decode(POST)
req = testing.DummyRequest(path=path, environ=environ, headers=headers,
cookies=None, post=POST, **kw)
return req


def asset(name):
import kotti
Expand Down
10 changes: 5 additions & 5 deletions kotti/views/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def _render_view_on_slot_event(view_name, event, params):
context = event.object
request = event.request

view_request = Request.blank(
view_request = request.__class__.blank(
"{0}/{1}".format(request.path.rstrip('/'), view_name),
base_url=request.application_url,
POST=_encode(params))
POST=_encode(params)
)

post_items = request.POST.items()
if post_items:
view_request.POST.extend(post_items)
if request.POST:
view_request.POST.update(request.POST)

# This is quite brittle:
for name in REQUEST_ATTRS_TO_COPY:
Expand Down

0 comments on commit cf895a9

Please sign in to comment.