Skip to content

Commit

Permalink
Merge pull request #66 from plone/replace_test_in_templates
Browse files Browse the repository at this point in the history
Drop use of test() in templates
  • Loading branch information
pbauer authored Sep 11, 2020
2 parents 8f0a945 + 57b9a10 commit 0e02278
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
has_text exists:context/aq_explicit/getText;
text python:has_text and here.getText() or ''"
tal:condition="text"
tal:attributes="class python:test(here.Format() in ('text/structured',
'text/x-rst', ), 'stx' + kss_class, 'plain' + kss_class)">
tal:attributes="class python:'stx' + kss_class if here.Format() in ('text/structured', 'text/x-rst', ) else 'plain' + kss_class">
<div metal:define-slot="inside" tal:replace="structure text">The body</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<tal:object tal:define="indexObj python:atct_tool.getIndex(index);
oddrow repeat/index/odd;">

<tr class="" tal:attributes="class python:test(oddrow, 'even', 'odd')">
<tr class="" tal:attributes="class python:'even' if oddrow else 'odd'">
<td class="listingCheckbox">
<input type="hidden"
value=""
Expand All @@ -119,9 +119,9 @@
name=""
id=""
tal:attributes="name string:index.enabled:records;
value python:test(indexObj.enabled, '1', '0');
value python:'1' if indexObj.enabled else '0';
id string:${indexObj/index}_enabled;
checked python:test(indexObj.enabled, 'checked', None)"/>
checked python:'checked' if indexObj.enabled else None"/>
</td>
<td>
<span tal:content="indexObj/index"/>
Expand All @@ -148,7 +148,7 @@
tal:attributes="id string:${indexObj/index}_criteria;">
<option tal:repeat="criterion python:atct_tool.getCriteriaForIndex(indexObj.index, as_dict= True)"
tal:attributes="value criterion/name;
selected python:test(criterion['name'] in indexObj.criteria, 'selected', None);"
selected python:'selected' if criterion['name'] in indexObj.criteria else None;"
tal:content="criterion/description"/>
</select>
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<tal:indexes tal:repeat="index metadata">
<tal:object tal:define="indexObj python:atct_tool.getMetadata(index);
oddrow repeat/index/odd">
<tr class="" tal:attributes="class python:test(oddrow, 'even', 'odd')">
<tr class="" tal:attributes="class python:'even' if oddrow else 'odd'">
<td class="listingCheckbox">
<input type="hidden"
value=""
Expand All @@ -113,8 +113,8 @@
value=""
name=""
tal:attributes="name string:metadata.enabled:records;
value python:test(indexObj.enabled, '1', '0');
checked python:test(indexObj.enabled, 'checked', None)"/>
value python:'1' if indexObj.enabled else '0';
checked python:'checked' if indexObj.enabled else None"/>
</td>
<td>
<span tal:content="indexObj/index"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
item_created item/CreationDate;
item_wf_state item/review_state;
item_creators item/Creators|item/Creator;
item_creators python:test(same_type(item_creators,[]) or same_type(item_creators,()), item_creators, [item_creators]);
item_creators python:item_creators if same_type(item_creators,[]) or same_type(item_creators,()) else [item_creators];
item_start item/start/ISO|item/StartDate|nothing;
item_end item/end/ISO|item/EndDate|nothing;">
<tr>
Expand All @@ -47,7 +47,7 @@
<para style="Table">
<a href="#"
tal:condition="python:item_type != 'Link'"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url+'/');"
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url+'/';"
tal:content="item_title_or_id">
Item Title
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
browserDefaultResult context/browserDefault;
isBrowserDefault python:len(browserDefaultResult[1]) == 1 and item.id == context.browserDefault()[1][0];
item_folderish item/is_folderish|nothing"
tal:attributes="class python:test(oddrow, 'draggable even', 'draggable odd');
tal:attributes="class python:'draggable even' if oddrow else 'draggable odd';
id string:folder-contents-item-${item_id};" >

<td class="notDraggable">
Expand All @@ -108,15 +108,14 @@
value="#"
tal:attributes="value item_path;
id string:cb_$item_id;
checked python:test(request.get('ids_checked', False), 'checked', None);
checked python:'checked' if request.get('ids_checked', False) else None;
alt string:Select $item_title_or_id;
title string:Select $item_title_or_id" />
<input type="hidden" name="obj_paths:list" value="#"
tal:attributes="value item_rel_url" />

</td>
<td tal:define="url python:test(item_use_view, item_url+'/view',
test(item_folderish, item_url+'/folder_contents', item_url+'/'));">
<td tal:define="url python:item_url+'/view' if item_use_view else item_url+'/folder_contents' if item_folderish else item_url+'/';">
<span tal:attributes="class item_type_class">
<img tal:replace="structure item_icon/html_tag" />
<a href="#" tal:attributes="href url;
Expand Down Expand Up @@ -178,7 +177,7 @@
i18n:attributes="value"
tal:attributes="value button/title;
name button/url;
class python:test((button['id'] == 'paste'), 'standalone', 'context')" />
class python:'standalone' if button['id'] == 'paste' else 'context'" />
</tal:buttons>
</metal:buttons>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
templateId=templateId, macro='text-field-view');
text here/getText|nothing"
tal:condition="text"
tal:attributes="class python:test(here.Format() in ('text/structured',
'text/x-rst', ), 'stx' + kss_class, 'plain' + kss_class)">
tal:attributes="class python:'stx' + kss_class if here.Format() in ('text/structured', 'text/x-rst', ) else 'plain' + kss_class">
<div metal:define-slot="inside" tal:replace="structure text">The body</div>
</div>

Expand Down Expand Up @@ -64,7 +63,7 @@
<tbody>
<tal:brain tal:repeat="obj topicContents">
<tr tal:define="oddrow repeat/obj/odd;"
tal:attributes="class python:test(oddrow, 'even', 'odd')">
tal:attributes="class python:'even' if oddrow else 'odd'">
<tal:fields repeat="field here/getCustomViewFields"
define="normalizeString nocall:context/@@plone/normalizeString;
url obj/getURL;
Expand All @@ -75,7 +74,7 @@
obj_wf_state obj/review_state|python: wtool.getInfoFor(obj, 'review_state', '');
obj_wf_state_class python:'state-' + normalizeString(obj_wf_state);
obj_ct_class python:'contenttype-' + normalizeString(obj_type);
obj_url python:test(obj_type in use_view_action, url+'/view', url);
obj_url python:url+'/view' if obj_type in use_view_action else url;
title_or_id obj/pretty_title_or_id">
<tal:block define="value python: getattr(obj, field, None)">
<td tal:condition="python: field != 'Title'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $(function() {
<tbody>
<tal:criteria repeat="criterion criteria">
<tr tal:define="oddrow repeat/criterion/odd;"
tal:attributes="class python:test(oddrow, 'even', 'odd')"
tal:attributes="class python:'even' if oddrow else 'odd'"
style="vertical-align: top;">
<td metal:use-macro="context/atct_macros/macros/criterion_edit" />
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<h2 class="headline">
<a href="#" class="summary url" tal:content="context/Title"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);">
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;">
Title or id
</a>
</h2>
Expand Down Expand Up @@ -66,7 +66,7 @@

<p class="more" tal:condition="python:not(item_macro) or rendering_error">
<a href=""
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);">
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;">
<span class="hiddenStructure"><span tal:replace="context/Title" /> - </span>
<span i18n:translate="read_more">Read More&hellip;</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
tal:define="has_text exists:context/aq_explicit/getText;
text python:has_text and here.getText() or ''"
tal:condition="text"
tal:attributes="class python:test(context.Format() in ('text/structured',
'text/x-rst', ), 'stx', 'plain')">
tal:attributes="class python:'stx' if context.Format() in ('text/structured', 'text/x-rst', ) else 'plain'">
<div metal:define-slot="inside" tal:replace="structure text">The body</div>
</div>

Expand Down Expand Up @@ -63,11 +62,11 @@
item_samedate python: (item_end - item_start &lt; 1) if item_type == 'Event' else False">
<metal:block define-slot="entry">
<header metal:define-macro="listitem"
tal:attributes="class python:test(item_type == 'Event', 'vevent', '')">
tal:attributes="class python:'vevent' if item_type == 'Event' else ''">

<span class="summary">
<a href="#"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;
class string:$item_type_class $item_wf_state_class url"
tal:content="item_title_or_id">
Item Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<a href="#"
tal:condition="exists:item_object/image_thumb"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url)">
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url">
<img src="" alt=""
tal:replace="structure python: path('nocall:item_object/tag')(scale='thumb', css_class='tileImage')" />
</a>
Expand All @@ -29,7 +29,7 @@

<a href="#"
class="summary url"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);"
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;"
tal:content="item_title_or_id">
Item Title
</a>
Expand Down Expand Up @@ -100,7 +100,7 @@

<p class="tileFooter">
<a href=""
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);">
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;">
<span class="hiddenStructure"><span tal:replace="item_title_or_id" /> - </span>
<span i18n:translate="read_more">Read More&hellip;</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<tr metal:define-macro="listitem"
tal:define="oddrow repeat/item/odd;"
tal:attributes="class python:test(oddrow, 'even', 'odd')">
tal:attributes="class python:'even' if oddrow else 'odd'">

<td>
<img width="16" height="16"
Expand All @@ -50,7 +50,7 @@
width item_icon/width;
height item_icon/height;" />
<a href="#"
tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url);
tal:attributes="href python:item_url+'/view' if item_type in use_view_action else item_url;
class string:$item_wf_state_class $item_type_class;
title item_description;"
tal:content="item_title_or_id">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
templateId=templateId, macro='text-field-view');
text text|context/getText|nothing"
tal:condition="text"
tal:attributes="class python:test(context.Format() in ('text/structured',
'text/x-rst', ), 'stx' + kss_class, 'plain' + kss_class)">
tal:attributes="class python:'stx' + kss_class if context.Format() in ('text/structured', 'text/x-rst', ) else 'plain' + kss_class">
<div metal:define-slot="inside" tal:replace="structure text">The body</div>
</div>
</metal:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ creation.</p>
<tr tal:repeat="type_name python:context.portal_types.listContentTypes()" >
<td><input type="checkbox"
tal:attributes="name python:type_name;
checked python:test(type_name in factory_types, '1', '')" /></td>
checked python:'1' if type_name in factory_types else ''" /></td>
<td tal:content="type_name" />
</tr>
</table>
Expand Down
1 change: 1 addition & 0 deletions news/24.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop use of test() in templates [pbauer]

0 comments on commit 0e02278

Please sign in to comment.