Skip to content

Commit ff243d6

Browse files
committed
Refactor identifiers page
1 parent 6a31837 commit ff243d6

File tree

5 files changed

+67
-23
lines changed

5 files changed

+67
-23
lines changed

config/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from isimip_data.metadata.views import (
2222
dataset,
2323
file,
24+
identifier,
2425
identifiers,
2526
metadata,
2627
resource,
@@ -99,6 +100,7 @@ def location(self, item):
99100
re_path(r'^(?P<doi>\d{2}\.\d+\/[A-Za-z0-9_.\-\/]+)', resource, name='resource'),
100101

101102
path('identifiers/', identifiers, name='identifiers'),
103+
path('identifiers/<str:identifier>', identifier, name='identifier'),
102104

103105
path('search/', search, name='search'),
104106
path('search/<path:path>/', search, name='search'),

isimip_data/metadata/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ class Meta:
427427
def __str__(self):
428428
return self.identifier
429429

430+
def get_absolute_url(self):
431+
return reverse('identifier', kwargs={'identifier': self.identifier})
432+
430433

431434
class Specifier(models.Model):
432435

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends 'core/base.html' %}
2+
{% load i18n %}
3+
{% load static %}
4+
5+
{% block style %}
6+
{{ block.super }}
7+
<link rel="stylesheet" href="{% static 'metadata.css' %}" />
8+
{% endblock %}
9+
10+
{% block main %}
11+
12+
<div class="container">
13+
<header>
14+
<h1>{% trans 'Identifier statistics' %}</h1>
15+
</header>
16+
17+
<div class="card identifier">
18+
<div class="card-header">
19+
<strong>{{ identifier.identifier }}</strong>
20+
</div>
21+
<ul class="list-group list-group-flush">
22+
{% for specifier, count in histogram %}
23+
{% if count > 0 %}
24+
<li class="list-group-item">
25+
<div class="d-flex gap-2 align-items-center">
26+
<strong>{{ specifier }}</strong>
27+
<div class="badge rounded-pill text-bg-secondary">
28+
{{ count }}
29+
</div>
30+
</div>
31+
</li>
32+
{% endif %}
33+
{% endfor %}
34+
</div>
35+
</ul>
36+
</div>
37+
</div>
38+
39+
{% endblock %}

isimip_data/metadata/templates/metadata/identifiers.html

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,25 @@
1111

1212
<div class="container">
1313
<header>
14-
<h1>{% trans 'Identifier statistics' %}</h1>
14+
<h1>{% trans 'Identifiers' %}</h1>
1515
</header>
1616

17-
{% for identifier, rows in identifiers %}
1817
<div class="card identifiers">
19-
<div class="card-header">
20-
<strong>{{ identifier }}</strong>
21-
</div>
22-
<div class="card-body">
23-
<div class="d-flex flex-wrap row-gap-1 column-gap-2">
24-
{% for specifier, count in rows %}
25-
{% if count > 0 %}
26-
<div class="d-flex gap-2 align-items-center border border-gray rounded ps-2 pe-2">
27-
<strong>{{ specifier }}</strong>
28-
<div class="badge rounded-pill text-bg-secondary">
29-
{{ count }}
18+
<ul class="list-group list-group-flush">
19+
{% for identifier in identifiers %}
20+
<li class="list-group-item">
21+
<div class="row">
22+
<div class="col-3">
23+
<a href="{{ identifier.get_absolute_url }}">{{ identifier.identifier }}</a>
24+
</div>
25+
<div class="col-9">
26+
<p>{{ identifier.specifiers|join:', ' }}</p>
27+
</div>
3028
</div>
31-
</div>
32-
{% endif %}
29+
</li>
3330
{% endfor %}
34-
</div>
35-
</div>
31+
</ul>
3632
</div>
37-
{% endfor %}
3833
</div>
3934

4035
{% endblock %}

isimip_data/metadata/views.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,16 @@ def resource_json(request, doi=None):
194194

195195

196196
def identifiers(request):
197-
identifiers_list = []
198-
for identifier in Identifier.objects.using('metadata').identifiers():
199-
identifiers_list.append((identifier, Dataset.objects.using('metadata').histogram(identifier)))
200-
201197
return render(request, 'metadata/identifiers.html', {
202198
'title': 'Identifiers',
203-
'identifiers': identifiers_list
199+
'identifiers': Identifier.objects.using('metadata').all()
200+
})
201+
202+
203+
def identifier(request, identifier=None):
204+
identifier_instance = get_object_or_404(Identifier.objects.using('metadata'), identifier=identifier)
205+
return render(request, 'metadata/identifier.html', {
206+
'title': 'Identifiers',
207+
'identifier': identifier_instance,
208+
'histogram': Dataset.objects.using('metadata').histogram(identifier)
204209
})

0 commit comments

Comments
 (0)