--- a/svv/items.py Mon Jan 10 18:30:58 2011 +0200
+++ b/svv/items.py Mon Jan 10 18:33:15 2011 +0200
@@ -177,45 +177,58 @@
visible - display list of items in addition the rendering the <input>'s
"""
- def render_items (items, visible) :
+
+ def render_items (items, with_list, with_input) :
+ """ Item <ul> or <input>s """
+
if not items :
# blank
return None
- elif visible :
+ elif with_list :
# nested list
return html.ul(
- render_item(item, True) for item in items
+ render_item(item, True, with_input) for item in items
)
else :
# just the controls
- return [render_item(item, False) for item in items]
+ return [render_item(item, False, with_input) for item in items]
- def render_item (item, visible) :
- # the form field
- field = html.input(type='hidden', name='items', value=item.id),
- if visible :
+ def render_item (item, with_list, with_input) :
+ """ Item <li> or <input> """
+
+ if with_input :
+ # the form field
+ input = html.input(type='hidden', name='items', value=item.id),
+ else :
+ # no field
+ input = None
+
+ if with_list :
return html.li(
- field,
+ input,
item.name if visible else None,
-
- render_items(item.children, visible),
+
+ # don't recurse inputs
+ render_items(item.children, with_list, with_input=False),
)
else :
# just the input
- return field
-
+ return input
+
+ ## Render <div> or <input>s
if visible :
- # div with nested <li>s
+ # <div> with nested <li>s
return html.div(class_='value')(
- render_items(items, True),
+ render_items(items, with_list=True, with_input=True),
)
+
else :
# just the <input>s
- return render_items(items, False)
+ return render_items(items, with_list=False, with_input=True)
def render (self, legend=None, delete_action=None, confirm_action=None, return_url=None, item_listing=None) :
"""
@@ -236,18 +249,14 @@
html.fieldset(
html.legend(legend),
+ # raw field with just the <input>s
+ (self.render_items_list('items', self.items, visible=False)) if not item_listing else None,
+
html.ol(
- (
- # full UI field
- (self.render_form_field('items', u"Poistettavat laitteet", u"Kaikki listatut laitteet poistetaan inventaarista", (
- self.render_items_list('items', self.items, visible=True)
- )))
-
- if item_listing else
-
- # raw field with just the <input>s
- (self.render_items_list('items', self.items, visible=False))
- ),
+ # full UI field
+ (self.render_form_field('items', u"Poistettavat laitteet", u"Kaikki listatut laitteet poistetaan inventaarista", (
+ self.render_items_list('items', self.items, visible=True)
+ )) if item_listing else None),
html.li(
self.render_submit_button(u"Poista") if delete_action else None,
@@ -481,6 +490,8 @@
items = form.items
for item in items :
+ # XXX: we shouldn't actually DELETE these; rather, mark them as removed
+ # messes up existing orders like this...
self.session.delete(item)
# ok
@@ -568,7 +579,7 @@
html.tbody(
html.tr(id=('item-%d' % item.id))(
html.td(
- html.a(href=self.url_for(ItemView, id=item.id))(
+ html.a(href=self.url_for(InventoryView, fragment=('item-%d' % item.id)))(
u'#%d' % item.id
)
),