Skip template expansion when html control does not have any chameleon tokens

This commit is contained in:
Brian Read 2024-11-17 14:28:59 +00:00
parent f4fc0394f7
commit b33af4042e
5 changed files with 50 additions and 31 deletions

View File

@ -90,9 +90,8 @@ sub main {
} }
# and table control fields # and table control fields
<tal:block tal:repeat="tablecontrol tablecontrols"> <tal:block tal:repeat="tablecontrol tablecontrols">$c->stash(${tablecontrol[0]}=>$c->get_${tablecontrol[0]}());
$c->stash(${tablecontrol}=>$c->get_${tablecontrol}()); </tal:block>
</tal:block>
$c->stash( $c->stash(
title => $title, title => $title,
@ -262,9 +261,8 @@ sub do_display {
</tal:block> </tal:block>
# and table control fields # and table control fields
<tal:block tal:repeat="tablecontrol tablecontrols"> <tal:block tal:repeat="tablecontrol tablecontrols">$c->stash(${tablecontrol[0]}=>$c->get_${tablecontrol[0]}());
$c->stash(${tablecontrol}=>$c->get_${tablecontrol}()); </tal:block>
</tal:block>
# Data for panel # Data for panel
$c->stash( $c->stash(

View File

@ -224,7 +224,7 @@
</tr> </tr>
</thead> </thead>
<tbody class='${classname}'> <tbody class='${classname}'>
% my $control_data = $self->stash('${TableControl}'); % my $control_data = $c->stash('${TableControl}');
% foreach my $row (@$control_data) { % foreach my $row (@$control_data) {
<tr class='table-row'><tal:block tal:repeat="ColContent Columns"> <tr class='table-row'><tal:block tal:repeat="ColContent Columns">
<td class='sme-border table-col table-col-${ColContent}'><%=$c->render_to_string(inline=>$row->{'${ColContent}'})%></td></tal:block> <td class='sme-border table-col table-col-${ColContent}'><%=$c->render_to_string(inline=>$row->{'${ColContent}'})%></td></tal:block>
@ -243,12 +243,18 @@
</Preformatted> </Preformatted>
<Link><![CDATA[ <Link><![CDATA[
%= link_to l('${title}'), '${structure:href}' , class=>'link link${type_serial}' <a href='${structure:href}' class='link link${type_serial}'>
%= l('${title}')
</a>
%#= link_to l('${title}'), '${structure:href}' , class=>'link link${type_serial}'
]]> ]]>
</Link> </Link>
<ButtonLink><![CDATA[ <ButtonLink><![CDATA[
%= button_to l('${title}'), '${structure:href}' , class=>'buttonlink buttonlink${type_serial}' <button href='${structure:href}' class='buttonlink buttonlink${type_serial}'>
%= l('${title}')
</button>
%#= button_to l('${title}'), '${structure:href}' , class=>'buttonlink buttonlink${type_serial}'
]]> ]]>
</ButtonLink> </ButtonLink>
@ -265,7 +271,7 @@
</Group> </Group>
<Endgroup><![CDATA[ <Endgroup><![CDATA[
<div></div> </div>
]]> ]]>
</Endgroup> </Endgroup>

View File

@ -8,9 +8,10 @@
<div id="module" class="module ${PackageName}-panel"> <div id="module" class="module ${PackageName}-panel">
% if ($config->{debug} == 1) { % if ($config->{debug} == 1) {
<p> <pre>
%= dumper $c->current_route %= dumper $c->current_route
</p> %= dumper $$${prefix}_data->{trt}
</pre>
% } % }
<h1><%=$title%></h1> <h1><%=$title%></h1>

View File

@ -26,8 +26,8 @@
}, },
'Link4': { 'Link4': {
'Type': 'Link', 'Type': 'Link',
'href': 'letsencryptd?trt=CHECKENABLEDDOMAINS', 'href': 'letsencryptd?trt=CHECKALLENABLEDDOMAINS',
'title': 'CHECK_ENABLED_DOMAINS' 'title': 'CHECK_ALL_ENABLED_DOMAINS'
}, },
'Endgroup': '', 'Endgroup': '',
SubHeader2: 'For this Server', SubHeader2: 'For this Server',

View File

@ -483,6 +483,10 @@ def extract_input_fields(json_data, value_type):
# Note: Empty lists are not removed, so all panels will be present in the result # Note: Empty lists are not removed, so all panels will be present in the result
return result return result
def contains_chameleon_code(template: str) -> bool:
# Check for common Chameleon code indicators
return "${" in template or "tal:" in template or "metal:" in template
if __name__ == "__main__": if __name__ == "__main__":
strVersion = assemble_version_string() strVersion = assemble_version_string()
@ -738,28 +742,38 @@ if __name__ == "__main__":
) )
else: else:
# just a simple entry - name less numerics is type # just a simple entry - name less numerics is type
# If the html does not include any Chameleon / TAL symbols, then do not run the Template extraction, just
# insert the result of the html directly. This avoids Chameleon aborting things when a closing tag is on its own
# such as the "Endgroup" token.
html_Type = "".join(char for char in html_control if not char.isdigit()) html_Type = "".join(char for char in html_control if not char.isdigit())
type_serial = "".join(char for char in html_control if char.isdigit()) type_serial = "".join(char for char in html_control if char.isdigit())
class_name = html_Type.lower()[:4]+type_serial class_name = html_Type.lower()[:4]+type_serial
acc_css_entries += f".{class_name} {{}}\n" acc_css_entries += f".{class_name} {{}}\n"
simple_control_html = ""
logger.debug(f"Partial ep generation html type:{html_Type}")
if not type_serial == "": if not type_serial == "":
logger.debug(f"{html_control},{html_Type},{type_serial}") logger.debug(f"{html_control},{html_Type},{type_serial}")
try: if html_Type in html_controls:
simple_control_template = PageTemplate(html_controls[html_Type]) if contains_chameleon_code(html_controls[html_Type]):
try: try:
simple_control_html = simple_control_template.render( simple_control_template = PageTemplate(html_controls[html_Type])
version=strVersion, Value=inner_html, prefix=prefix_is, try:
type_serial=type_serial simple_control_html = simple_control_template.render(
) version=strVersion, Value=inner_html, prefix=prefix_is,
all_controls_html = all_controls_html + simple_control_html type_serial=type_serial
except Exception as e: )
logger.warning( except Exception as e:
f"A Chameleon render on partial file control {html_control} error occurred: {e}" logger.warning(
) f"A Chameleon render on partial file control {html_control} error occurred: {e}"
except Exception as e: )
logger.warning( except Exception as e:
f"A Chameleon template partial file control {html_control} error occurred: {e}" logger.warning(
) f"A Chameleon template partial file control {html_control} error occurred: {e}"
)
else:
logger.debug(f"Skipping Chameleon expansion for {html_control}")
simple_control_html = html_controls[html_Type]
all_controls_html = all_controls_html + simple_control_html
# Now insert it into the partial file in the correct place. # Now insert it into the partial file in the correct place.
# Read in the text file and split at "%# Inputs etc in here." # Read in the text file and split at "%# Inputs etc in here."