Thanks! I'll update and check it out.
Get Outlook for Androidhttps://aka.ms/ghei36
________________________________
From: Jonathan Pyle
Sent: Saturday, September 2, 2017 5:27:24 PM
To: Steenhuis, Quinten
Cc: docassemble@python.org
Subject: Re: [Docassemble] Filtering a DADict/set of checkboxes to display in the Docx template
Hi Quinten,
That's a very good point. In version 0.1.46, which I just pushed to GitHub and PyPI, I added methods .true_values() and .false_values() to checkbox objects (DADict objects) so that you can instead write:
The protected classes are {{ protected_classes.true_values() }}.
or
{%p for key in protected_classes.true_values() %}
{{ key }} is a protected class.
{%p endfor %}
For documentation, see https://docassemble.org/docs/objects.html#DADict.true_values
Thanks!
On Sat, Sep 2, 2017 at 4:43 PM, Steenhuis, Quinten mailto:QSteenhuis@gbls.org> wrote:
Hi Jonathan,
We ran into what I think is probably a pretty common scenario: in a Docx template, displaying only the “checked” options in a checklist. I figured out a syntax that works, but I wonder if there’s a better solution.
Here’s what we did for the interview:
---
question: What protected class do you fall under?
fields:
- Select the protected class(es) that match you or a family member: protected_classes
datatype: checkboxes
choices:
- Family Status
- Age
- Receipt of public or rental assistance
- Gender Identity
…
And here’s what I put in the docx template:
{%p for key, value in protected_classes.iteritems() if value %}
{{ key }}
{%p endfor %}
Is there a better way to do this? It seemed more complicated than I expected.
Quinten
_______________________________________________
Docassemble mailing list
docassemble@python.orgmailto:docassemble@python.org
https://mail.python.org/mm3/mailman3/lists/docassemble.python.org/