aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/fatcat_web/routes.py42
-rw-r--r--python/fatcat_web/search.py29
-rw-r--r--python/fatcat_web/templates/container_view_browse.html74
3 files changed, 94 insertions, 51 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 6e3e9b57..2f29b9e6 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -60,7 +60,7 @@ from fatcat_web.search import (
ReleaseQuery,
do_container_search,
do_release_search,
- get_elastic_container_browse_year_volume,
+ get_elastic_container_browse_year_volume_issue,
get_elastic_container_histogram_legacy,
get_elastic_container_preservation_by_volume,
get_elastic_container_random_releases,
@@ -357,11 +357,11 @@ def container_view_browse(ident: str) -> AnyResponse:
return render_template("deleted_entity.html", entity_type="container", entity=entity)
query_sort: Optional[List[str]]
- if request.args.get('year') and 'volume' in request.args and 'issue' in request.args:
+ if request.args.get("year") and "volume" in request.args and "issue" in request.args:
# year, volume, issue specified; browse-by-page
- year = int(request.args.get('year'))
- volume = request.args.get('volume', '')
- issue = request.args.get('issue', '')
+ year = int(request.args.get("year"))
+ volume = request.args.get("volume", "")
+ issue = request.args.get("issue", "")
if volume:
volume = f'volume:"{volume}"'
else:
@@ -370,27 +370,33 @@ def container_view_browse(ident: str) -> AnyResponse:
issue = f'issue:"{issue}"'
else:
issue = "!issue:*"
- query_string = f'year:{year} {volume} {issue}'
+ query_string = f"year:{year} {volume} {issue}"
query_sort = ["first_page", "release_date"]
- elif request.args.get('year') and 'volume' in request.args:
+ elif request.args.get("year") and "volume" in request.args:
# year, volume specified (no issue); browse-by-page
- year = int(request.args.get('year'))
- volume = request.args.get('volume', '')
+ year = int(request.args.get("year"))
+ volume = request.args.get("volume", "")
if volume:
volume = f'volume:"{volume}"'
else:
volume = "!volume:*"
- query_string = f'year:{year} {volume}'
+ query_string = f"year:{year} {volume}"
query_sort = ["issue", "first_page", "release_date"]
- elif request.args.get('year'):
+ elif request.args.get("year"):
# year specified, not anything else; browse-by-date
- year = int(request.args.get('year'))
+ year = int(request.args.get("year"))
query_string = f"year:{year}"
query_sort = ["release_date"]
else:
- entity._browse_volume_year = get_elastic_container_browse_year_volume(entity.ident)
+ entity._browse_volume_year = get_elastic_container_browse_year_volume_issue(
+ entity.ident
+ )
+ print(entity._browse_volume_year)
return render_template(
- "container_view_browse.html", entity_type="container", entity=entity, editgroup_id=None
+ "container_view_browse.html",
+ entity_type="container",
+ entity=entity,
+ editgroup_id=None,
)
print(query_string)
@@ -421,11 +427,11 @@ def container_view_browse(ident: str) -> AnyResponse:
)
# HACK: re-sort by first page *numerically*
- if found.results and query_sort and 'first_page' in query_sort:
+ if found.results and query_sort and "first_page" in query_sort:
for doc in found.results:
- if doc.get('first_page') and doc['first_page'].isdigit():
- doc['first_page'] = int(doc['first_page'])
- found.results = sorted(found.results, key=lambda d: d.get('first_page') or 99999999)
+ if doc.get("first_page") and doc["first_page"].isdigit():
+ doc["first_page"] = int(doc["first_page"])
+ found.results = sorted(found.results, key=lambda d: d.get("first_page") or 99999999)
return render_template(
"container_view_browse.html",
diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py
index 3f4a216c..e79fcd8d 100644
--- a/python/fatcat_web/search.py
+++ b/python/fatcat_web/search.py
@@ -247,13 +247,9 @@ def get_elastic_container_random_releases(ident: str, limit: int = 5) -> List[Di
return results
-def get_elastic_container_browse_year_volume(ident: str) -> Dict[int, Dict[str, Any]]:
+def get_elastic_container_browse_year_volume_issue(ident: str) -> Dict[int, Dict[str, Any]]:
"""
- Returns a set of histogram buckets:
-
- container_ident: str
- years{}
- volumes{}
+ Returns a set of histogram buckets, by year (int), volume (str), issue (str)
"""
search = Search(using=app.es_client, index=app.config["ELASTICSEARCH_RELEASE_INDEX"])
@@ -284,9 +280,14 @@ def get_elastic_container_browse_year_volume(ident: str) -> Dict[int, Dict[str,
"terms": {
"field": "volume",
"missing_bucket": True,
- # TODO: es-public-proxy support?
- # "order": "asc",
- # "missing_order": "last",
+ },
+ }
+ },
+ {
+ "issue": {
+ "terms": {
+ "field": "issue",
+ "missing_bucket": True,
},
}
},
@@ -304,10 +305,12 @@ def get_elastic_container_browse_year_volume(ident: str) -> Dict[int, Dict[str,
for year in year_nums:
year_dicts[year] = {}
for row in buckets:
- year_dicts[int(row["key"]["year"])][row["key"]["volume"] or "000_unknown"] = int(
- row["doc_count"]
- )
- # return sorted(year_dicts.values(), key=lambda x: x["year"])
+ year = int(row["key"]["year"])
+ volume = row["key"]["volume"] or "000_unknown"
+ issue = row["key"]["issue"] or "000_unknown"
+ if not volume in year_dicts[year]:
+ year_dicts[year][volume] = {}
+ year_dicts[year][volume][issue] = int(row["doc_count"])
return year_dicts
diff --git a/python/fatcat_web/templates/container_view_browse.html b/python/fatcat_web/templates/container_view_browse.html
index aa88b666..f6a74a2d 100644
--- a/python/fatcat_web/templates/container_view_browse.html
+++ b/python/fatcat_web/templates/container_view_browse.html
@@ -4,25 +4,50 @@
{% import "entity_macros.html" as entity_macros %}
{% extends "entity_base.html" %}
-{% macro browse_year_volume_table(entity, data) %}
+{% macro browse_year_volume_issue_table(entity, data) %}
<table class="ui basic compact structured table">
+ <thead>
+ <tr>
+ <th>Year
+ <th>Volume
+ <th>Issue
+ <th class="right aligned">Indexed Content
+ </tr>
+ </thead>
<tbody>
{% for year in data.keys()|sort|reverse %}
+ {% set year_loop = loop %}
{% for volume in data[year].keys()|sort|reverse %}
- <tr>
- {% if loop.first %}
- <td rowspan="{{ data[year]|length }}" class="top aligned">
- <a href="/container/{{ entity.ident }}/browse?year={{ year }}">{{ year }}</a>
- </td>
- {% endif %}
- {% if volume == '000_unknown' %}
- <td>{% if data[year]|length > 1 %}<i>n/a</i>{% endif %}</td>
- <td><a href="/container/{{ entity.ident }}/browse?year={{ year }}&volume=">{{ data[year][volume] }} releases</a>
- {% else %}
- <td><a href="/container/{{ entity.ident }}/browse?volume={{ volume }}">Vol. {{ volume }}</a></td>
- <td><a href="/container/{{ entity.ident }}/browse?year={{ year }}&volume={{ volume }}">{{ data[year][volume] }} releases</a>
- {% endif %}
- </tr>
+ {% set volume_loop = loop %}
+ {% for issue in data[year][volume].keys()|sort|reverse %}
+ {% set issue_loop = loop %}
+ <tr>
+ {% if volume_loop.first and issue_loop.first %}
+ {% set year_rowspan = data[year].values()|map('length')|sum %}
+ <td rowspan="{{ year_rowspan }}" class="top aligned">
+ <a href="/container/{{ entity.ident }}/browse?year={{ year }}">{{ year }}</a>
+ </td>
+ {% endif %}
+
+ {% if issue_loop.first %}
+ <td rowspan="{{ data[year][volume]|length }}" class="top aligned">
+ {% if volume != '000_unknown' %}
+ <a href="/container/{{ entity.ident }}/browse?volume={{ volume }}">Vol. {{ volume }}</a>
+ {% endif %}
+ </td>
+ {% endif %}
+
+ <td>
+ {% if issue != '000_unknown' %}
+ <a href="/container/{{ entity.ident }}/browse?year={{ year }}&volume={{ volume }}&issue={{ issue }}">Issue {{ issue }}</a>
+ {% endif %}
+ </td>
+
+ <td class="right aligned">
+ <a href="/container/{{ entity.ident }}/browse?year={{ year }}&volume={{ volume }}&issue={{ issue }}">{{ data[year][volume][issue] }} releases</a>
+ </td>
+ </tr>
+ {% endfor %}
{% endfor %}
{% endfor %}
</tbody>
@@ -30,15 +55,24 @@
{% endmacro %}
{% macro browse_releases(found) %}
+ <h2>
+ Browsing:
+ {% if request.args.volume %}Volume {{ request.args.volume }} &nbsp;{% endif %}
+ {% if request.args.issue %}Issue {{ request.args.issue }} &nbsp;{% endif %}
+ {% if request.args.year %}Year {{ request.args.year }} &nbsp;{% endif %}
+ </h2>
+ <br>
{% for release_doc in found.results %}
<div class="ui grid">
<div class="two wide center aligned column">
- {% if release_doc.pages %}
- {{ release_doc.pages }}
- {#
+ {% if request.args.volume %}
+ {% if release_doc.pages %}
+ {{ release_doc.pages }}
+ {% else %}
+ {# blank #}
+ {% endif %}
{% elif release_doc.release_date %}
{{ release_doc.release_date }}
- #}
{% endif %}
</div>
<div class="fourteen wide column">
@@ -55,7 +89,7 @@
{% elif entity._browse_volume_year %}
<div class="ui container text">
<h3>Contents by Year and Volume</h3>
- {{ browse_year_volume_table(entity, entity._browse_volume_year) }}
+ {{ browse_year_volume_issue_table(entity, entity._browse_volume_year) }}
</div>
{% endif %}