Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same python expression in a template line not translated #428

Open
JonDehn opened this issue Sep 28, 2024 · 2 comments
Open

Same python expression in a template line not translated #428

JonDehn opened this issue Sep 28, 2024 · 2 comments

Comments

@JonDehn
Copy link

JonDehn commented Sep 28, 2024

I have this code in a template:

                        <fieldset class="age-group-set">
                            <legend>Age Group:</legend>
                            <div tal:repeat="ag age_groups" tal:omit-tag="True">
                                <input form="entry_form" id="${ag.name}" name="age_group" type="radio"
                                       value="${ag.name}" ${ag.checked} >
                                <label for="${ag.name}">${ag.name}</label>
                            </div>
                        </fieldset>

"age_groups" is a list of Objects with attributes 'name' and 'checked'

Note that python variable "ag.name" appears in 4 places in the template, and the ag.checked variable once.

There are four entries in the "age_groups" list, "(Preschool, ' '), ('Child', ' '), ('Teen', ' ') and ('Adult', 'checked').

On Chrome (I have not tried on other browsers), I get this, where sometimes ${ag.name} is properly translated, and sometimes not (just left as "${ag.name}"

  | Age Group:   |     |   | Preschool   |     |     |   | Child   |     |     |   | Teen   |     |     |   | Adult   |     |   |  

I've tried several work-arounds, but nothing seems to get the proper translation. Is there something I'm missing?

@malthe
Copy link
Owner

malthe commented Sep 28, 2024

I don't think you can have ${ag.checked} just like that, standalone. It should be checked="${ag.checked}".

If you run your app using CHAMELEON_CACHE=./some-dir and perhaps CHAMELEON_DEBUG=1 then you can figure out what's going on in the generated Python code.

@JonDehn
Copy link
Author

JonDehn commented Sep 30, 2024

Thanks for your quick reply.
The "checked" specification is correct as is, from my reading of the HTML documentation. It is a "Boolean Attribute", which I think means the presence of the worded 'checked' is taken to mean true (and it seems to work).

I'm on windows; I tried setting the CHAMLEON_CACHE environment variable to "C:\temp" following your suggestion. This results in an exception on the second time a template is used (which is where the original problem showed up):

File "C:\Users\JonDe\PycharmProjects\TabDataTableTest\fairOps\Lib\site-packages\chameleon\loader.py", line 212, in build
os.rename(fn, name)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'c:\temp\_layout_6d06839ce8755075f5f936d55286068cd2dvtxur.tmp' -> 'c:\temp\_layout_6d06839ce8755075f5f936d55286068c.py'

  • Expression: ""load: ../shared/_layout.htm"
  • Filename: ... jects\fairOps\web_server\templates\entries\entry_form.pt
  • Location: (line 2: col 21)
  • Source: ... iv metal:use-macro="load: ../shared/_layout.html">
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My main HTML template is "../shared/_layout.html", which has a slot for the template "entry_form.pt".
So it appears that the debug code is using the name of the shared_layout.html a second time (but that's just a wild guess on my part)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants