Skip to content

Commit

Permalink
add prompt support in sheet templates (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Aug 4, 2023
1 parent ee88cd1 commit eecb669
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Added
- ``IrodsDataRequest`` REST API views (#1588, #1706, #1734, #1735, #1736)
- Davrods links in iRODS delete request list (#1339)
- Batch accepting and rejecting for iRODS delete requests (#1340)
- Cookiecutter prompt support in sheet templates (#1726)
- **Taskflowbackend**
- ``BatchCalculateChecksumTask`` iRODS task (#1634)
- Automated generation of missing checksums in ``zone_move`` flow (#1634)
Expand Down
14 changes: 11 additions & 3 deletions samplesheets/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ERROR_MSG_INVALID_PATH = 'Not a valid iRODS path for this project'
ERROR_MSG_EXISTING = 'An active request already exists for this path'
TPL_DIR_FIELD = '__output_dir'
TPL_DIR_LABEL = 'Output directory'


# Mixins and Helpers -----------------------------------------------------------
Expand Down Expand Up @@ -246,14 +247,21 @@ def __init__(
self.current_user = current_user
self.sheet_tpl = sheet_tpl
self.json_fields = []
prompts = sheet_tpl.configuration.get('__prompts__')

for k, v in sheet_tpl.configuration.items():
# Skip fields generated by cookiecutter
if isinstance(v, str) and ('{{' in v or '{%' in v):
continue
field_kwargs = {
'label': k if k != TPL_DIR_FIELD else 'Output Directory'
}
# Get label
if k == TPL_DIR_FIELD:
label = TPL_DIR_LABEL
elif prompts and k in prompts:
label = prompts[k]
else:
label = k
field_kwargs = {'label': label}
# Set field and initial value
if k == TPL_DIR_FIELD:
field_kwargs[
'help_text'
Expand Down
28 changes: 27 additions & 1 deletion samplesheets/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from projectroles.plugins import get_backend_api
from projectroles.tests.test_ui import TestUIBase

from samplesheets.forms import TPL_DIR_FIELD
from samplesheets.forms import TPL_DIR_FIELD, TPL_DIR_LABEL
from samplesheets.models import (
ISATab,
Investigation,
Expand Down Expand Up @@ -233,6 +233,32 @@ def test_render_field_visibility(self):
e.get_attribute('type'), 'hidden', msg=msg
)

def test_render_labels(self):
"""Test label rendering"""
for t in ISA_TEMPLATES:
prompts = t.configuration.get('__prompts__')
url = (
reverse(
'samplesheets:template_create',
kwargs={'project': self.project.sodar_uuid},
)
+ '?sheet_tpl='
+ t.name
)
self.login_and_redirect(self.superuser, url)
label_elems = self.selenium.find_elements(By.TAG_NAME, 'label')
for e in label_elems:
e_name = e.get_attribute('for')[3:] # Strip "id_"
label_text = e.text
msg = '{}/{}'.format(t.name, e_name)
if e_name == TPL_DIR_FIELD:
self.assertEqual(label_text, TPL_DIR_LABEL + '*')
# Need to use assertIn() because of extra label characters
elif prompts and e_name in prompts:
self.assertIn(prompts[e_name], label_text, msg=msg)
else:
self.assertIn(e_name, label_text, msg=msg)


class TestSheetVersionListView(TestProjectSheetsUIBase):
"""Tests for the sheet version list view UI"""
Expand Down

0 comments on commit eecb669

Please sign in to comment.