Skip to content

Commit

Permalink
Refactor tap examples and use defer="defer" to be xhtml complient
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 7, 2024
1 parent 6203824 commit 0e651db
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 59 deletions.
2 changes: 1 addition & 1 deletion daiquiri/auth/templates/auth/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block js %}
<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% static 'auth/js/users.js' %}" defer></script>
<script src="{% static 'auth/js/users.js' %}" defer="defer"></script>
{% endblock %}

{% block wide %}
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/contact/templates/contact/messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block js %}
<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% static 'contact/js/messages.js' %}" defer></script>
<script src="{% static 'contact/js/messages.js' %}" defer="defer"></script>
{% endblock %}

{% block wide %}
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% endblock %}

{% block js %}
<script src="{% static 'core/js/bootstrap.js' %}" defer></script>
<script src="{% static 'core/js/bootstrap.js' %}" defer="defer"></script>
{% endblock %}

</head>
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/metadata/templates/metadata/management.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{% block js %}
<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% static 'metadata/js/management.js' %}" defer></script>
<script src="{% static 'metadata/js/management.js' %}" defer="defer"></script>
{% endblock %}

{% block wide %}
Expand Down
12 changes: 6 additions & 6 deletions daiquiri/query/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion daiquiri/query/templates/query/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{% block js %}
<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% static 'query/js/query.js' %}" defer></script>
<script src="{% static 'query/js/query.js' %}" defer="defer"></script>
{% endblock %}

{% block wide %}
Expand Down
8 changes: 8 additions & 0 deletions daiquiri/query/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/serve/templates/serve/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block js %}
<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% static 'serve/js/table.js' %}" defer></script>
<script src="{% static 'serve/js/table.js' %}" defer="defer"></script>
{% endblock %}

{% block wide %}
Expand Down
23 changes: 17 additions & 6 deletions daiquiri/tap/templates/tap/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@

<h1>{% trans 'Examples' %}</h1>

{% for example in examples %}
<div id="example-{{ example.id }}" resource="#example-{{ example.id }}" typeof="example" class="daiquiri-tap-example">
<h2 property="name">{{ example.name }}</h2>
<p property="description">{{ example.description }}</p>
<pre property="query">{{ example.query_string }}</pre>
<div vocab="http://www.ivoa.net/rdf/examples#">
{% for example in examples %}
<div id="example-{{ example.id }}" resource="#example-{{ example.id }}" typeof="example" class="card mb-3">
<div class="card-header d-flex align-items-center">
<span property="name">{{ example.name }}</span>
{% if example.query_language_label %}
<span class="badge text-bg-secondary ms-auto">{{ example.query_language_label }}</span>
{% endif %}
</div>
<div class="card-body">
{% if example.description %}
<p property="description" class="card-text">{{ example.description }}</p>
{% endif %}
<pre class="mb-0"><code property="query">{{ example.query_string }}</code></pre>
</div>
</div>
{% endfor %}
</div>
{% endfor %}

{% endblock %}
36 changes: 0 additions & 36 deletions daiquiri/tap/templates/tap/examples.xhtml

This file was deleted.

6 changes: 1 addition & 5 deletions daiquiri/tap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 0e651db

Please sign in to comment.