From 0e651db5bc22dcee660253561986d7a1d9c87748 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Thu, 7 Nov 2024 13:38:20 +0100 Subject: [PATCH] Refactor tap examples and use defer="defer" to be xhtml complient --- daiquiri/auth/templates/auth/users.html | 2 +- .../contact/templates/contact/messages.html | 2 +- daiquiri/core/templates/core/base.html | 2 +- .../templates/metadata/management.html | 2 +- daiquiri/query/models.py | 12 +++---- daiquiri/query/templates/query/query.html | 2 +- daiquiri/query/utils.py | 8 +++++ daiquiri/serve/templates/serve/table.html | 2 +- daiquiri/tap/templates/tap/examples.html | 23 ++++++++---- daiquiri/tap/templates/tap/examples.xhtml | 36 ------------------- daiquiri/tap/views.py | 6 +--- 11 files changed, 38 insertions(+), 59 deletions(-) delete mode 100644 daiquiri/tap/templates/tap/examples.xhtml diff --git a/daiquiri/auth/templates/auth/users.html b/daiquiri/auth/templates/auth/users.html index 8b9e567c..83632052 100644 --- a/daiquiri/auth/templates/auth/users.html +++ b/daiquiri/auth/templates/auth/users.html @@ -3,7 +3,7 @@ {% block js %} - + {% endblock %} {% block wide %} diff --git a/daiquiri/contact/templates/contact/messages.html b/daiquiri/contact/templates/contact/messages.html index 4320ea86..c6f73b1f 100644 --- a/daiquiri/contact/templates/contact/messages.html +++ b/daiquiri/contact/templates/contact/messages.html @@ -3,7 +3,7 @@ {% block js %} - + {% endblock %} {% block wide %} diff --git a/daiquiri/core/templates/core/base.html b/daiquiri/core/templates/core/base.html index d9edfaf6..760e298a 100644 --- a/daiquiri/core/templates/core/base.html +++ b/daiquiri/core/templates/core/base.html @@ -12,7 +12,7 @@ {% endblock %} {% block js %} - + {% endblock %} diff --git a/daiquiri/metadata/templates/metadata/management.html b/daiquiri/metadata/templates/metadata/management.html index 9e5be8de..01d61ff7 100644 --- a/daiquiri/metadata/templates/metadata/management.html +++ b/daiquiri/metadata/templates/metadata/management.html @@ -10,7 +10,7 @@ {% block js %} - + {% endblock %} {% block wide %} diff --git a/daiquiri/query/models.py b/daiquiri/query/models.py index 7520aa0d..49ebf17d 100644 --- a/daiquiri/query/models.py +++ b/daiquiri/query/models.py @@ -44,7 +44,7 @@ run_database_ingest_task, run_database_query_task, ) -from .utils import get_format_config, get_job_columns +from .utils import get_format_config, get_job_columns, get_query_language_label logger = logging.getLogger(__name__) query_logger = logging.getLogger('query') @@ -84,11 +84,7 @@ def phase_label(self): @property def query_language_label(self): - return next(iter( - query_language['label'] - for query_language in settings.QUERY_LANGUAGES - if '{key}-{version}'.format(**query_language) == self.query_language - ), None) + return get_query_language_label(self.query_language) @property def creation_time_label(self): @@ -658,3 +654,7 @@ class Meta: def __str__(self): return self.name + + @property + def query_language_label(self): + return get_query_language_label(self.query_language) diff --git a/daiquiri/query/templates/query/query.html b/daiquiri/query/templates/query/query.html index 7a307d83..641ae724 100644 --- a/daiquiri/query/templates/query/query.html +++ b/daiquiri/query/templates/query/query.html @@ -10,7 +10,7 @@ {% block js %} - + {% endblock %} {% block wide %} diff --git a/daiquiri/query/utils.py b/daiquiri/query/utils.py index 787d1118..cefcb041 100644 --- a/daiquiri/query/utils.py +++ b/daiquiri/query/utils.py @@ -368,6 +368,14 @@ def get_query_language_choices(): ] +def get_query_language_label(query_language): + return next(iter( + ql['label'] + for ql in settings.QUERY_LANGUAGES + if '{key}-{version}'.format(**ql) == query_language + ), None) + + def get_queue_choices(): return [ (queue['key'], queue['label']) for queue in settings.QUERY_QUEUES diff --git a/daiquiri/serve/templates/serve/table.html b/daiquiri/serve/templates/serve/table.html index 701a4d11..5a92c654 100644 --- a/daiquiri/serve/templates/serve/table.html +++ b/daiquiri/serve/templates/serve/table.html @@ -3,7 +3,7 @@ {% block js %} - + {% endblock %} {% block wide %} diff --git a/daiquiri/tap/templates/tap/examples.html b/daiquiri/tap/templates/tap/examples.html index 7fffac0b..340aef7a 100644 --- a/daiquiri/tap/templates/tap/examples.html +++ b/daiquiri/tap/templates/tap/examples.html @@ -10,12 +10,23 @@

{% trans 'Examples' %}

- {% for example in examples %} -
-

{{ example.name }}

-

{{ example.description }}

-
{{ example.query_string }}
+
+ {% for example in examples %} +
+
+ {{ example.name }} + {% if example.query_language_label %} + {{ example.query_language_label }} + {% endif %} +
+
+ {% if example.description %} +

{{ example.description }}

+ {% endif %} +
{{ example.query_string }}
+
+
+ {% endfor %}
- {% endfor %} {% endblock %} diff --git a/daiquiri/tap/templates/tap/examples.xhtml b/daiquiri/tap/templates/tap/examples.xhtml deleted file mode 100644 index aeeda120..00000000 --- a/daiquiri/tap/templates/tap/examples.xhtml +++ /dev/null @@ -1,36 +0,0 @@ - - - - -{% load static %} - -{{ request.site.name }} - - - - - - - - - - - - - - -
- {% for example in examples %} -
-

{{ example.name }}

- {% if example.description %} -

{{ example.description }}

- {% endif %} -
{{ example.query_string }}
-
- {% endfor %} -
- - - - diff --git a/daiquiri/tap/views.py b/daiquiri/tap/views.py index 36228b1f..bb22a083 100644 --- a/daiquiri/tap/views.py +++ b/daiquiri/tap/views.py @@ -25,10 +25,6 @@ def tables(request): def examples(request): - template = 'tap/examples.html' - user_agent = request.headers.get("User-Agent", "").lower() - if "topcat" in user_agent or "curl" in user_agent: - template = 'tap/examples.xhtml' - return render(request, template, { + return render(request, 'tap/examples.html', { 'examples': Example.objects.filter_by_access_level(request.user) })