Discussion:
[pylons-discuss] Rendering a deform form with a template, but placing nodes inside of HTML tags
Tom Andrews
2018-07-17 11:17:10 UTC
Permalink
Hello,

I'm trying to construct a treeview-like structure with checkbox widgets
from deform and have all of the checkboxes as part of one form. If I just
render the form normally and pass the generated html to my template, I'll
obviosuly not get the structure I want.
So far I've tried to pass the whole form object to the template and then
rendering the individual checkboxes on demand with the templating language,
but then I'm missing a submit button and the whole form element, along with
a few other things. What are my options here? I'm certain that this must be
possible to do, but I can't seem to find a practical way to do it.

Here is the relevant excerpt from my template (jinja2):

<div class="treeview">
<ul>
{% for label_name, sublabels in view.gitlab_data.items() %}
<li class="tierone">
<span class="noselect"><i class="glyphicon glyphicon-plus"></i>{{ label_name }}</span>
<ul>
{% for sublabel_name, issues in sublabels.items() %}
<li class="tiertwo">
<span class="noselect"><i class="glyphicon glyphicon-plus"></i>{{ sublabel_name }}</span>
<ul>
{% for issue_id, issue in issues.items() %}
<li class="issue">
{# Insert Checkbox Nodes here#}
<a href={{ issue_id }}>
{{ issue.title }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>



Thanks.
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/1649b593-adad-45bb-a6c0-aac1bf1e56bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Steve Piercy
2018-07-17 11:52:02 UTC
Permalink
I'm not sure I follow your current approach.

Have you looked at Writing Your Own Widget?
https://docs.pylonsproject.org/projects/deform/en/master/widget.html#writing-your-own-widget

Do you want to use a checkbox or a checkboxchoice?
http://deformdemo.repoze.org/checkbox/
http://deformdemo.repoze.org/checkboxchoice/

The templates for such widgets use Chameleon for templating.
I'm not fluent in Chameleon, so hopefully someone else can fill
in the blanks.

--steve
Post by Tom Andrews
Hello,
I'm trying to construct a treeview-like structure with checkbox
widgets from deform and have all of the checkboxes as part of
one form. If I just render the form normally and pass the
generated html to my template, I'll obviosuly not get the
structure I want. So far I've tried to pass the whole form
object to the template and then rendering the individual
checkboxes on demand with the templating language, but then I'm
missing a submit button and the whole form element, along with
a few other things. What are my options here? I'm certain that
this must be possible to do, but I can't seem to find a
practical way to do it.
<div class="treeview">
<ul>
{% for label_name, sublabels in view.gitlab_data.items() %}
<li class="tierone">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ label_name }}</span>
<ul>
{% for sublabel_name, issues in sublabels.items() %}
<li class="tiertwo">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ sublabel_name }}</span>
<ul>
{% for issue_id, issue in issues.items() %}
<li class="issue">
{# Insert Checkbox Nodes here#}
<a href={{ issue_id }}>
{{ issue.title }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
Thanks.
------------------------
Steve Piercy, Eugene, OR
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/r480Ps-10126i-122CC13C714340A2A40374750577E496%40Steves-iMac.local.
For more options, visit https://groups.google.com/d/optout.
Tom Andrews
2018-07-17 12:46:17 UTC
Permalink
Yes, I have looked at the retail form documentation. I think it's possible
to do what I want with it, but it doesn't seem very practical. Writing my
own widget might be the the best approach if I understand things correctly.

Just in case, the issue I had with the retail form approach was that I
didn't know how to put my html structure complete with the checkboxes
contained within, into the form element. Even if I can render the form
element by itself, it would just be empty, wouldn't it? How would I put my
treeview into it? Does the form render method have some sort of argument,
where I could pass my treeview-html to, all from within my template?
Maybe a retail form is ill-suited for my specific application, but I can't
help the feeling that I'm missing something obvious.
Post by Steve Piercy
I'm not sure I follow your current approach.
Have you looked at Writing Your Own Widget?
https://docs.pylonsproject.org/projects/deform/en/master/widget.html#writing-your-own-widget
Do you want to use a checkbox or a checkboxchoice?
http://deformdemo.repoze.org/checkbox/
http://deformdemo.repoze.org/checkboxchoice/
The templates for such widgets use Chameleon for templating.
I'm not fluent in Chameleon, so hopefully someone else can fill
in the blanks.
--steve
Post by Tom Andrews
Hello,
I'm trying to construct a treeview-like structure with checkbox
widgets from deform and have all of the checkboxes as part of
one form. If I just render the form normally and pass the
generated html to my template, I'll obviosuly not get the
structure I want. So far I've tried to pass the whole form
object to the template and then rendering the individual
checkboxes on demand with the templating language, but then I'm
missing a submit button and the whole form element, along with
a few other things. What are my options here? I'm certain that
this must be possible to do, but I can't seem to find a
practical way to do it.
<div class="treeview">
<ul>
{% for label_name, sublabels in view.gitlab_data.items() %}
<li class="tierone">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ label_name }}</span>
<ul>
{% for sublabel_name, issues in sublabels.items() %}
<li class="tiertwo">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ sublabel_name }}</span>
<ul>
{% for issue_id, issue in issues.items() %}
<li class="issue">
{# Insert Checkbox Nodes here#}
<a href={{ issue_id }}>
{{ issue.title }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
Thanks.
------------------------
Steve Piercy, Eugene, OR
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/a0a93dca-213a-4ce1-ba9e-35f5507e0048%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andreas Kaiser
2018-07-17 12:07:36 UTC
Permalink
https://docs.pylonsproject.org/projects/deform/en/master/retail.html
might be what you're looking for.

IIRC the button is also just an ordinary field of the form, which can be
rendered the same way.


HTH,
Andreas
Post by Tom Andrews
I'm trying to construct a treeview-like structure with checkbox widgets
from deform and have all of the checkboxes as part of one form. If I just
render the form normally and pass the generated html to my template, I'll
obviosuly not get the structure I want.
So far I've tried to pass the whole form object to the template and then
rendering the individual checkboxes on demand with the templating language,
but then I'm missing a submit button and the whole form element, along with
a few other things. What are my options here? I'm certain that this must be
possible to do, but I can't seem to find a practical way to do it.
<div class="treeview">
<ul>
{% for label_name, sublabels in view.gitlab_data.items() %}
<li class="tierone">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ label_name }}</span>
<ul>
{% for sublabel_name, issues in sublabels.items() %}
<li class="tiertwo">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ sublabel_name }}</span>
<ul>
{% for issue_id, issue in
issues.items() %}
<li class="issue">
{# Insert Checkbox Nodes here#}
<a href={{ issue_id }}>
{{ issue.title }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/285865F4-EB03-4170-AF2C-7615B4BE0E50%40binary-punks.com.
For more options, visit https://groups.google.com/d/optout.
Tom Andrews
2018-07-17 12:51:47 UTC
Permalink
Thanks for your recommendation. I have outlined my issues with the retail
form approach in the previous response to Steve Piercy, but I would
appreciate if you could point me to an example of some sort for rendering
the submit button (possibly even the form element itself) separately. I was
having issues accessing anything that wasn't declared as a colander
SchemaNode (the button is just passed as an argument to deform.Form).
Post by Andreas Kaiser
https://docs.pylonsproject.org/projects/deform/en/master/retail.html
might be what you're looking for.
IIRC the button is also just an ordinary field of the form, which can be
rendered the same way.
HTH,
Andreas
Post by Tom Andrews
I'm trying to construct a treeview-like structure with checkbox widgets
from deform and have all of the checkboxes as part of one form. If I just
render the form normally and pass the generated html to my template, I'll
obviosuly not get the structure I want.
So far I've tried to pass the whole form object to the template and then
rendering the individual checkboxes on demand with the templating language,
but then I'm missing a submit button and the whole form element, along with
a few other things. What are my options here? I'm certain that this must be
possible to do, but I can't seem to find a practical way to do it.
<div class="treeview">
<ul>
{% for label_name, sublabels in view.gitlab_data.items() %}
<li class="tierone">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ label_name }}</span>
<ul>
{% for sublabel_name, issues in sublabels.items() %}
<li class="tiertwo">
<span class="noselect"><i class="glyphicon
glyphicon-plus"></i>{{ sublabel_name }}</span>
<ul>
{% for issue_id, issue in
issues.items() %}
<li class="issue">
{# Insert Checkbox Nodes here#}
<a href={{ issue_id }}>
{{ issue.title }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/8c860c84-9d69-48a5-8130-d1c6e8e3ddb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...