Skip to content

Commit

Permalink
add cubi templates to list view (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 23, 2024
1 parent 0b1f6c9 commit 54171c1
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 11 deletions.
7 changes: 7 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,13 @@ def set_logging(level=None):
ONTOLOGYACCESS_QUERY_LIMIT = env.int('ONTOLOGYACCESS_QUERY_LIMIT', 250)


# Isatemplates settings
# Enable templates from cubi-isa-templates
ISATEMPLATES_ENABLE_CUBI_TEMPLATES = env.bool(
'ISATEMPLATES_ENABLE_CUBI_TEMPLATES', True
)


# Settings for HTTP AuthBasic
BASICAUTH_REALM = env.str(
'BASICAUTH_REALM', 'Log in with your SODAR user name and password.'
Expand Down
3 changes: 3 additions & 0 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
'bih_proteomics_smb',
]

# Isatemplates app settings
ISATEMPLATES_ENABLE_CUBI_TEMPLATES = True

# UI test settings
PROJECTROLES_TEST_UI_CHROME_OPTIONS = [
'headless',
Expand Down
8 changes: 8 additions & 0 deletions docs_manual/source/admin_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ Ontology Access Settings
``ONTOLOGYACCESS_QUERY_LIMIT``
Term query limit (integer).

ISA Templates Settings
----------------------

``ISATEMPLATES_ENABLE_CUBI_TEMPLATES``
Enable templates from the
`cubi-isa-templates <https://github.com/bihealth/cubi-isa-templates/>`_
repository (boolean).


SODAR Docker Compose Settings
=============================
Expand Down
2 changes: 1 addition & 1 deletion isatemplates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CookiecutterISATemplate(models.Model):
default=True, help_text='Display template for users in UI'
)

# ; User who last edited the template
#: User who last edited the template
user = models.ForeignKey(
AUTH_USER_MODEL,
related_name='cookiecutter_templates',
Expand Down
57 changes: 48 additions & 9 deletions isatemplates/templates/isatemplates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
{% block css %}
{{ block.super }}
<style type="text/css">
table#sodar-it-list-table thead tr th:nth-child(2),
table#sodar-it-list-table tbody tr td:nth-child(2) {
white-space: nowrap;
}
table#sodar-it-list-table thead tr th:nth-child(4),
table#sodar-it-list-table tbody tr td:nth-child(4) {
width: 170px;
Expand Down Expand Up @@ -44,6 +40,12 @@
display: none;
}
}
@media screen and (max-width: 900px) {
table#sodar-it-cubi-table thead tr th:nth-child(2),
table#sodar-it-cubi-table tbody tr td:nth-child(2) {
display: none;
}
}
</style>
{% endblock css %}

Expand Down Expand Up @@ -81,7 +83,7 @@ <h4>
{% for t in templates %}
<tr class="sodar-it-list-item">
<td>{{ t.description }}</td>
<td class="text-monospace">{{ t.name }}</td>
<td class="text-monospace text-nowrap">{{ t.name }}</td>
{% if t.user %}
<td>
{% get_user_html t.user as t_user %}
Expand Down Expand Up @@ -126,10 +128,47 @@ <h4>
</tr>
{% endfor %}
{% if templates.count == 0 %}
<td class="bg-faded font-italic text-center"
id="sodar-it-list-empty" colspan="6">
No custom ISA-Tab templates imported.
</td>
<tr id="sodar-it-list-empty">
<td class="bg-faded font-italic text-center" colspan="6">
No custom ISA-Tab templates imported.
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>

<div class="card" id="sodar-it-cubi-list">
<div class="card-header">
<h4>
<i class="iconify" data-icon="mdi:file-table-box-multiple-outline"></i>
CUBI Templates
{% get_info_link "Templates from the cubi-isa-templates repository" as info_link %}
{{ info_link | safe }}
</h4>
</div>
<div class="card-body p-0">
<table class="table table-striped sodar-card-table" id="sodar-it-cubi-table">
<thead>
<tr>
<th>Description</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for t in cubi_templates %}
<tr class="sodar-it-cubi-item">
<td>{{ t.description | capfirst }}</td>
<td class="text-monospace text-nowrap">{{ t.name }}</td>
</tr>
{% endfor %}
{% if not cubi_templates %}
<tr id="sodar-it-cubi-empty">
<td class="bg-faded font-italic text-center" colspan="2">
CUBI templates are disabled in the site Django settings.
</td>
</tr>
{% endif %}
</tbody>
</table>
Expand Down
31 changes: 30 additions & 1 deletion isatemplates/tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""UI tests for the isatemplates app"""

from cubi_isa_templates import _TEMPLATES as CUBI_TEMPLATES

from django.test import override_settings
from django.urls import reverse

from selenium.common.exceptions import NoSuchElementException
Expand Down Expand Up @@ -30,9 +33,17 @@ def test_get_no_templates(self):
self.assertIsNotNone(
self.selenium.find_element(By.ID, 'sodar-it-list-empty')
)
self.assertEqual(
len(
self.selenium.find_elements(By.CLASS_NAME, 'sodar-it-cubi-item')
),
len(CUBI_TEMPLATES),
)
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(By.ID, 'sodar-it-cubi-empty')

def test_get_existing_template(self):
"""Test ISATemplateListView GET with existing template"""
"""Test GET with existing template"""
self.template = self.make_isa_template(
name=TEMPLATE_NAME,
description=TEMPLATE_DESC,
Expand All @@ -49,3 +60,21 @@ def test_get_existing_template(self):
)
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(By.ID, 'sodar-it-list-empty')
self.assertEqual(
len(
self.selenium.find_elements(By.CLASS_NAME, 'sodar-it-cubi-item')
),
len(CUBI_TEMPLATES),
)
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(By.ID, 'sodar-it-cubi-empty')

@override_settings(ISATEMPLATES_ENABLE_CUBI_TEMPLATES=False)
def test_get_disable_cubi_templates(self):
"""Test GET with cubi templates disabled"""
self.login_and_redirect(self.superuser, self.url)
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(By.CLASS_NAME, 'sodar-it-cubi-item')
self.assertIsNotNone(
self.selenium.find_element(By.ID, 'sodar-it-cubi-empty')
)
15 changes: 15 additions & 0 deletions isatemplates/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import json

from cubi_isa_templates import _TEMPLATES as CUBI_TEMPLATES

from django.test import override_settings
from django.urls import reverse

from test_plus.test import TestCase
Expand Down Expand Up @@ -46,3 +49,15 @@ def test_get(self):
response.context['templates'][0].sodar_uuid,
self.template.sodar_uuid,
)
self.assertEqual(
len(response.context['cubi_templates']), len(CUBI_TEMPLATES)
)

@override_settings(ISATEMPLATES_ENABLE_CUBI_TEMPLATES=False)
def test_get_disable_cubi_templates(self):
"""Test GET with cubi templates disabled"""
with self.login(self.superuser):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['templates'].count(), 1)
self.assertEqual(response.context['cubi_templates'], None)
8 changes: 8 additions & 0 deletions isatemplates/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""UI views for the isatemplates app"""

from cubi_isa_templates import _TEMPLATES as CUBI_TEMPLATES

from django.conf import settings
from django.views.generic import TemplateView

# Projectroles dependency
Expand All @@ -19,4 +22,9 @@ def get_context_data(self, **kwargs):
context['templates'] = CookiecutterISATemplate.objects.all().order_by(
'name'
)
context['cubi_templates'] = None
if settings.ISATEMPLATES_ENABLE_CUBI_TEMPLATES:
context['cubi_templates'] = sorted(
CUBI_TEMPLATES, key=lambda x: x.description.lower()
)
return context

0 comments on commit 54171c1

Please sign in to comment.