Skip to content

Commit acf6398

Browse files
authored
Sample add form tal:expressions refactored (#1775)
* Refactored tal:expressions to use `python` * Changelog updated
1 parent 979e2bf commit acf6398

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.0.0 (unreleased)
55
------------------
66

7+
- #1775 Sample add form tal:expressions refactored
78
- #1773 Integrated upgrade step notification events
89
- #1772 Sample dispatch workflow
910
- #1771 Fix RecordsWidget does not store hidden fields in Add form

src/bika/lims/browser/analysisrequest/templates/ar_add2.pt

+50-50
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@
309309
<!-- All edit fields with fields with add=visible -->
310310
<tal:field tal:repeat="field python:view.get_fields_with_visibility('edit')">
311311
<tal:def define="fieldName python:field.getName();
312-
required field/required;
312+
required python:bool(field.required);
313313
widget python:field.widget;
314314
errors python:{};
315-
mode string:edit;">
316-
<tr tal:attributes="fieldName fieldName;">
315+
mode python:'edit';">
316+
<tr tal:attributes="fieldName python:fieldName;">
317317
<td>
318318
<label class="formQuestion">
319319
<span
@@ -358,14 +358,14 @@
358358
<tal:columns tal:repeat="arnum python:range(view.ar_count)">
359359
<td tal:define="newFieldName python:view.get_fieldname(field, arnum);
360360
val python:view.fieldvalues.get(newFieldName)"
361-
tal:attributes="arnum arnum; fieldName newFieldName">
361+
tal:attributes="arnum python:arnum; fieldName python:newFieldName">
362362

363363
<input type="hidden"
364364
tal:attributes="value val/Title|nothing;
365365
name newFieldName;"/>
366366
<input type="hidden"
367367
tal:attributes="value val/UID|nothing;
368-
name string:${newFieldName}_uid;"/>
368+
name python:'{}_uid'.format(newFieldName);"/>
369369
</td>
370370
</tal:columns>
371371
</tr>
@@ -403,10 +403,10 @@
403403
category_title python:category.Title;">
404404
<tr title="Click to expand this category"
405405
i18n:attributes="title"
406-
tal:attributes="data-category category_id;
407-
poc poc;
408-
category string:field;
409-
class string:${poc} category;">
406+
tal:attributes="data-category python:category_id;
407+
poc python:poc;
408+
category python:'field';
409+
class python:'{} category'.format(poc);">
410410
<td class="services-category-header">
411411
<span class="services-category-title"
412412
tal:content="category_title"
@@ -419,18 +419,18 @@
419419
class="btn btn-default btn-xs service-category-toggle">+</button>
420420
</td>
421421
<!-- span over all sample columns -->
422-
<td tal:attributes="colspan ar_count"></td>
422+
<td tal:attributes="colspan python:ar_count"></td>
423423
</tr>
424424

425425
<tal:services tal:repeat="service python:services[category_title];">
426-
<tr tal:define="service_uid service/UID;
427-
service_id service/getId;
428-
service_keyword service/getKeyword;
429-
service_title service/Title;"
430-
tal:attributes="id string:${service_id};
431-
class string:${category_id} ${poc} service;
432-
poc poc;
433-
fieldname string:Analyses;">
426+
<tr tal:define="service_uid python:service.UID;
427+
service_id python:service.getId;
428+
service_keyword python:service.getKeyword;
429+
service_title python:service.Title;"
430+
tal:attributes="id python:service_id;
431+
class python:'{} {} service'.format(category_id, poc);
432+
poc python:poc;
433+
fieldname python:'Analyses';">
434434
<td class="service-header">
435435
<div class="service-title small"
436436
i18n:translate=""
@@ -442,53 +442,53 @@
442442
<img class="copybutton btn-link"
443443
width="16"
444444
tal:condition="python:view.ar_count > 1"
445-
tal:attributes="src senaite_theme/icon_url/copy;"/>
445+
tal:attributes="src python:senaite_theme.icon_url('copy');"/>
446446
</td>
447447

448448
<tal:columns tal:repeat="arnum python:range(ar_count)">
449-
<td tal:define="fieldname string:Analyses-${arnum};
449+
<td tal:define="fieldname python:'Analyses-{}'.format(arnum);
450450
analyses python:view.fieldvalues.get(fieldname) or [];
451451
service_uids python:map(view.get_service_uid_from, analyses);
452452
checked python:service_uid in service_uids;"
453-
tal:attributes="fieldname string:Analyses-${arnum};
454-
uid service_uid;
455-
class string:${service_uid}-column service-column;
456-
arnum arnum;">
453+
tal:attributes="fieldname python:'Analyses-{}'.format(arnum);
454+
uid python:service_uid;
455+
class python:'{}-column service-column'.format(service_uid);
456+
arnum python:arnum;">
457457

458458
<!-- Service locked button -->
459-
<div tal:attributes="uid service_uid;
460-
arnum arnum;
461-
id string:${service_uid}-${arnum}-lockbtn;
462-
class string:service-lockbtn ${service_uid}-lockbtn;"
459+
<div tal:attributes="uid python:service_uid;
460+
arnum python:arnum;
461+
id python:'{}-{}-lockbtn'.format(service_uid, arnum);
462+
class python:'service-lockbtn {}-lockbtn'.format(service_uid);"
463463
title="Service cannot be deselected. Please click the info button for further details"
464464
i18n:attributes="title">
465465
&#128274;
466466
</div>
467467

468468
<!-- Service checkbox -->
469-
<div tal:attributes="id string:${service_uid}-${arnum}-analysisservice;
470-
class string:analysisservice ${service_uid}-analysisservice;">
469+
<div tal:attributes="id python:'{}-{}-analysisservice'.format(service_uid, arnum);
470+
class python:'analysisservice {}-analysisservice'.format(service_uid);">
471471
<input type="checkbox"
472472
style="height:auto;"
473-
tal:attributes="name string:${fieldname}:list;
474-
value string:${service_uid};
475-
class string:analysisservice-cb analysisservice-cb-${arnum};
476-
id string:cb_${arnum}_${service_uid};
477-
alt service_title;
473+
tal:attributes="name python:'{}:list'.format(fieldname);
474+
value python:service_uid;
475+
class python:'analysisservice-cb analysisservice-cb-{}'.format(arnum);
476+
id python:'cb_{}_{}'.format(arnum, service_uid);
477+
alt python:service_title;
478478
checked python:checked and 'checked' or '';"/>
479479
</div>
480480

481481
<!-- Service info button -->
482-
<div tal:attributes="uid service_uid;
483-
arnum arnum;
484-
id string:${service_uid}-infobtn;
485-
class string:service-infobtn ${service_uid}-infobtn;">
482+
<div tal:attributes="uid python:service_uid;
483+
arnum python:arnum;
484+
id python:'{}-infobtn'.format(service_uid);
485+
class python:'service-infobtn {}-infobtn'.format(service_uid);">
486486
&#9432;
487487
</div>
488488

489489
<!-- Service Info Box -->
490-
<div tal:attributes="id string:${service_uid}-info;
491-
class string:${service_uid}-info service-info;">
490+
<div tal:attributes="id python:'{}-info'.format(service_uid);
491+
class python:'{}-info service-info'.format(service_uid);">
492492
</div>
493493

494494
</td>
@@ -503,19 +503,19 @@
503503
<!-- /POCs -->
504504

505505
<!-- Prices -->
506-
<tal:prices tal:condition="view/ShowPrices">
507-
<tr tal:condition="view/getMemberDiscountApplies">
506+
<tal:prices tal:condition="python:view.ShowPrices">
507+
<tr tal:condition="python:view.getMemberDiscountApplies()">
508508
<td>
509509
<span class="pricelabel discount" i18n:translate="">Discount</span>
510-
<span class="discreet">(<tal:i content="here/bika_setup/getMemberDiscount"/>%)</span>
510+
<span class="discreet">(<tal:i content="python:context.bika_setup.getMemberDiscount()"/>%)</span>
511511
</td>
512512
<td>
513513
<span tal:replace="currency_symbol"/>
514514
</td>
515515
<tal:columns repeat="arnum python:range(view.ar_count)">
516-
<td tal:attributes="arnum arnum">
516+
<td tal:attributes="arnum python:arnum">
517517
<span class="price discount noborder"
518-
tal:attributes="id string:discount-${arnum}">0.00</span>
518+
tal:attributes="id python:'discount-{}'.format(arnum)">0.00</span>
519519
</td>
520520
</tal:columns>
521521
</tr>
@@ -527,9 +527,9 @@
527527
<span tal:replace="currency_symbol"/>
528528
</td>
529529
<tal:columns repeat="arnum python:range(view.ar_count)">
530-
<td tal:attributes="arnum arnum">
530+
<td tal:attributes="arnum python:arnum">
531531
<span class="price subtotal noborder"
532-
tal:attributes="id string:subtotal-${arnum}">0.00</span>
532+
tal:attributes="id python:'subtotal-{}'.format(arnum)">0.00</span>
533533
</td>
534534
</tal:columns>
535535
</tr>
@@ -543,7 +543,7 @@
543543
<tal:columns repeat="arnum python:range(view.ar_count)">
544544
<td tal:attributes="arnum arnum">
545545
<span class="price vat noborder"
546-
tal:attributes="id string:vat-${arnum}">0.00</span>
546+
tal:attributes="id python:'vat-{}'.format(arnum)">0.00</span>
547547
</td>
548548
</tal:columns>
549549
</tr>
@@ -557,7 +557,7 @@
557557
<tal:columns repeat="arnum python:range(view.ar_count)">
558558
<td tal:attributes="arnum arnum">
559559
<span class="price total noborder"
560-
tal:attributes="id string:total-${arnum}">0.00</span>
560+
tal:attributes="id python:'total-{}'.format(arnum)">0.00</span>
561561
</td>
562562
</tal:columns>
563563
</tr>

0 commit comments

Comments
 (0)