Skip to content

Commit

Permalink
#48 Updated Vocabularies detail template.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaraballo17 committed Dec 11, 2020
1 parent ad25036 commit 4586a50
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'cvinterface/base.html' %}
{% load tools %}

{% block title %}
<title>ODM2 CV term: {{ concept.term }}</title>
Expand All @@ -10,19 +11,19 @@
<h2>
{{ concept.name }}<span class="vocabulary-type">{{ vocabulary_verbose_name }}</span>
<span class="parent-link">
<a href="{% url vocabulary_code %}" class="tooltip" data-tip="Navigate to the {{ vocabulary_verbose_name }} vocabulary list."></a>
<a href="{{ list_url }}" class="tooltip" data-tip="Navigate to the {{ vocabulary_verbose_name }} vocabulary list."></a>
</span>
</h2>
<h4>{{ concept.definition }}</h4>
{% if concept.vocabulary_status == 'Archived' %}
<h4>NOTE: This is an archived version of this term. There is a <a href="{% url detail_url_name concept.revised_version.term concept.revised_version.pk %}">new version</a> available.</h4>
{% if concept.vocabulary_status == ARCHIVED %}
<h4>NOTE: This is an archived version of this term. There is a <a href="{% detail_url concept.revised_version %}">new version</a> available.</h4>
{% endif %}
<div class="vocabulary-links">
{% if concept.vocabulary_status != ARCHIVED %}
<a id="btnEdit" href="{% url create_url_name concept.pk %}" class="button white">Edit</a>
<a id="btnSKOSTerm" target="_blank" href="{# {% url 'api_dispatch_detail' resource_name=vocabulary api_name='v1' term=concept.term %} #}?format=skos" class="button white">View in SKOS</a>
<a id="btnSKOS" download="{{vocabulary_code}}_{{concept.term}}.rdf" href="{# {% url 'api_dispatch_detail' resource_name=vocabulary api_name='v1' term=concept.term %} #}?format=skos" target="_blank" class="button white">Download Term (SKOS)</a>
<a id="btnSKOS" download="{{vocabulary_code}}_{{concept.term}}.csv" href="{# {% url 'api_dispatch_detail' resource_name=vocabulary api_name='v1' term=concept.term %} #}?format=csv" target="_blank" class="button white">Download Term (CSV)</a>
<a id="btnEdit" href="{{ edit_url }}" class="button white">Edit</a>
<a id="btnSKOSTerm" target="_blank" href="{{ api_url }}?format=skos" class="button white">View in SKOS</a>
<a id="btnSKOS" download="{{vocabulary_code}}_{{concept.term}}.rdf" href="{{ api_url }}?format=skos" target="_blank" class="button white">Download Term (SKOS)</a>
<a id="btnSKOS" download="{{vocabulary_code}}_{{concept.term}}.csv" href="{{ api_url }}?format=csv" target="_blank" class="button white">Download Term (CSV)</a>
{% endif %}
</div>
</header>
Expand All @@ -43,7 +44,7 @@ <h4>NOTE: This is an archived version of this term. There is a <a href="{% url d
<div class="column two-columns data-view">
<h4>
{% if concept.previous_version %}
Previous version of this term: <br><a href="{% url detail_url_name concept.previous_version.term concept.previous_version.pk %}">{{ concept.previous_version.term }}</a> {{ concept.previous_version.definition }}
Previous version of this term: <br><a href="{% detail_url concept.previous_version %}">{{ concept.previous_version.term }}</a> {{ concept.previous_version.definition }}
{% endif %}
</h4>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/cvinterface/templatetags/tools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from django import template
from django.urls import reverse

from cvservices.models import ControlledVocabulary

register = template.Library()


@register.simple_tag(name='detail_url', takes_context=True)
def get_detail_url(context, instance):
return reverse(context['detail_url_name'], args=(instance.term,))
def get_detail_url(context, instance: ControlledVocabulary):
if instance.vocabulary_status == instance.CURRENT:
return reverse(context['detail_url_name'], args=(instance.term,))
else:
return reverse(context['detail_url_name'], args=(instance.term, instance.pk))


@register.filter
Expand Down
4 changes: 3 additions & 1 deletion src/cvinterface/views/base_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def get_context_data(self, **kwargs):
if field.name not in self.exclude
)
context['vocabulary_verbose_name'] = self.vocabulary.get('name')
context['create_url_name'] = self.vocabulary.get('request').get('create_url_name')
context['detail_url_name'] = self.vocabulary.get('detail_url_name')
context['edit_url'] = reverse(self.vocabulary.get('request').get('create_url_name'), args=(self.object.pk, ))
context['api_url'] = reverse(self.vocabulary.get('api_detail_url_name'), args=(self.object.term, ))
context['list_url'] = reverse(self.vocabulary.get('list_url_name'))
context['vocabulary_code'] = self.vocabulary_code
context['ARCHIVED'] = self.model.ARCHIVED
return context
Expand Down
2 changes: 1 addition & 1 deletion src/odm2cvs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# cv detail views
urlpatterns += [
path(f'{vocabulary_code}/<slug:term>/', detail_view, name=vocabulary.get('detail_url_name')),
path(f'{vocabulary_code}/<slug:term>/<int:vocabulary_id>', detail_view, name=vocabulary.get('detail_url_name'))
path(f'{vocabulary_code}/<slug:term>/<int:pk>', detail_view, name=vocabulary.get('detail_url_name'))
]

# request list views
Expand Down

0 comments on commit 4586a50

Please sign in to comment.