Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1487 (closed defect: fixed)

Opened 12 years ago

Last modified 11 years ago

Empty DIV element when there's no hidden fields in TableForm/ListForm

Reported by: guest Owned by: alberto
Priority: normal Milestone:
Component: ToscaWidgets Version: trunk
Severity: minor Keywords: templates
Cc: nadako@…

Description

Currently, in default twForms templates (mako and genshi) if there is no hidden fields defined, an empty DIV is rendered. There should be some check before rendering it or we could just don't add a div element for hidden fields. I don't know how to check ihidden_fields iterator. May be it's normal to just do % if list(ihidden_fields): (for mako) check?

Change History

comment:1 follow-up: ↓ 3 Changed 12 years ago by roger.demetrescu

From turbogears/view/base.py :

def ipeek(it):
    """Lets you look at the first item in an iterator. This is a good way
    to verify that the iterator actually contains something. This is useful
    for cases where you will choose not to display a list or table if there
    is no data present.
    """
    it = iter(it)
    try:
        item = it.next()
        return chain([item], it)
    except StopIteration:
        return None

We could borrow this function to TW... What do you think Alberto ?

Regarding Mako templates, it would be pretty easy... just inject it into mako_util.py and make use of it.

But talking about Genshi templates... I didn't take a deep look at how/what function/variables are exported to local namespace.

Is there something like stdvars from Turbogears in TW ?

Roger

comment:2 Changed 12 years ago by roger.demetrescu

Just to complement... Both Mako and Genshi would do something like that (respecting their own way of doing attributions and comparisons)

# pseudo-code

ihidden_fields = ipeek(ihidden_fields)

if ihidden_fields:
    print "<div>"
    for field in ihidden_fields:
        print "..." # DIV's inner content
    print "</div>"

comment:3 in reply to: ↑ 1 Changed 12 years ago by alberto

  • Status changed from new to assigned

Replying to roger.demetrescu:

We could borrow this function to TW... What do you think Alberto ?

Sounds like a good idea and would solve this issue by putting a <div py:if="ipeek(ihidden_fields)> in the Genshi templates (and the equivalent in the Mako ones).

Regarding Mako templates, it would be pretty easy... just inject it into mako_util.py and make use of it.

But talking about Genshi templates... I didn't take a deep look at how/what function/variables are exported to local namespace.

Is there something like stdvars from Turbogears in TW ?

It is possible but not implemented (the extra_vars_func argument to view.EngineManager. However, that possibility is there so frameworks/apps can make use of it to provide framework-dependent helpers, I've never considered the possibility of TW providing its own helpers this way because it might make (even more) difficult to know where each var. reaching the template is coming from.

So, we could add the ipeek function as an attribute to ContainerMixin and list it at params or, maybe easier, deprecate {{ihidden_fields}}} and ifields and add provide "sans-i" versions that returned a list instead of iterators, or...?

Alberto

Roger

comment:4 Changed 11 years ago by roger.demetrescu

  • Status changed from assigned to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.