Skip to content

Commit

Permalink
[svn] updating docs/reqs for recent MultiDict changes
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
pjenvey committed Jul 25, 2006
1 parent dc054d8 commit 83eac7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions docs/quick_wiki.txt
Expand Up @@ -396,18 +396,14 @@ Add the ``save()`` action::
if not page:
page = model.Page()
page.title = title
page.content = request.params['content'][0]
page.content = request.params['content']
c.title = page.title
c.content = page.get_wiki_content()
c.message = 'Successfully saved'
return render_response('/page.myt')

.. Note::
``request.params`` has a number of methods such as ``getone()`` and ``getall()`` which return parameters as a
single item or list respectively. Accessing ``request.params`` as a dictionary returns strings for single
values and a list of strings for multiple values.

# XXX THIS DOESN'T WORK AT THE MOMENT!
``request.params`` is a MultiDict object; an ordered dictionary that may contain multiple values for each key. The MultiDict will always return one value for any existing key via the normal dict accessors (params[key], ``params.get()`` and ``params.setdefault()``). When multiple values are expected, use the ``getall()`` method to return all values in a list.

In order for the ``page.myt`` template to display the ``Successfully saved`` message after the page is saved we need to update the ``templates/page.myt`` file. After ``<h1 class="main"><% c.title %></h1>`` add these lines making sure there is no whitespace before the lines that start with a ``%`` character::

Expand Down Expand Up @@ -483,10 +479,11 @@ Now for the AJAX! We want all the titles in the titles list to be draggable so w

with this::

<span id="page-<% title %>"><% title %></span>&nbsp;[<% h.link_to('visit', h.url_for(title=title, action="index")) %>]
<span id="page-<% title %>"><% title %></span>
&nbsp;[<% h.link_to('visit', h.url_for(title=title, action="index")) %>]
<% h.draggable_element("page-"+ str(title), revert=True) %>

This marks each of the titles as a draggable element that reverts to its original position if it isn't dropped over a drop target. If we want to be able to delete the pages we better add a drop target. Try it out at http://127.0.0.1:5000/page/list by dragging the titles themselves around the screen. Notice how much functionality we got with just the one helper ``h.draggable_element()``.
This marks each of the titles as a draggable element that reverts to its original position if it isn't dropped over a drop target. If we want to be able to delete the pages we better add a drop target. Try it out at http://127.0.0.1:5000/page/list by dragging the titles themselves around the screen. Notice how much functionality we get with just the one helper ``h.draggable_element()``.

We better have somewhere to drop the titles to delete them so add this before the ``<ul id="titles">`` line in ``templates/titles.myt`` ::

Expand All @@ -510,7 +507,7 @@ We will also need to add the style for the trash box to the end of ``public/quic
When a title is dropped on the ``trash`` box an AJAX request will be made to the ``delete()`` action posting an ``id`` parameter with the id of the element that was dropped. The element with id ``titles`` will be replaced with whatever is returned from the action so we better add a ``delete()`` action that returns the new list of titles excluding the one that has been deleted::

def delete(self):
title = request.params['id'][0][5:] # XXX This is wrong!
title = request.params['id'][5:]
page = self.query.get_by(title=title)
objectstore.delete(page)
objectstore.flush()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -66,7 +66,7 @@
zip_safe=False,
include_package_data=True,
install_requires=[
"Routes>=1.4", "Myghty>=1.0.2", "Paste==dev,>=0.9.6dev-r5483",
"Routes>=1.4", "Myghty>=1.0.2", "Paste==dev,>=0.9.6dev-r5488",
"PasteDeploy==dev,>=0.5dev-r5480", "PasteScript==dev,>=0.9.1dev-r5481", "FormEncode>=0.4",
"simplejson>=1.3", "WSGIUtils==0.7", "WebHelpers>=0.1.3",
"nose>=0.8.7", "Beaker>=0.6",
Expand Down

0 comments on commit 83eac7b

Please sign in to comment.