Skip to content

Commit

Permalink
Created an HTML table-based "package releases" view. (#157)
Browse files Browse the repository at this point in the history
* Created an HTML table-based "package releases" view.

* Adapted test to prior changes.
  • Loading branch information
AngeloD2022 authored Dec 4, 2023
1 parent 517c2ae commit 6f2a5e1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
14 changes: 8 additions & 6 deletions inspector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def versions(project_name):
if resp.status_code != 200:
return redirect(pypi_project_url, 307)

version_urls = [
"." + "/" + str(version)
for version in sorted(resp.json()["releases"].keys(), key=parse, reverse=True)
]
releases = resp.json()["releases"]
sorted_releases = {
version: releases[version]
for version in sorted(releases.keys(), key=parse, reverse=True)
}

return render_template(
"links.html",
links=version_urls,
"releases.html",
releases=sorted_releases,
h2=project_name,
h2_link=f"/project/{project_name}",
h2_paren="View this project on PyPI",
Expand Down
10 changes: 10 additions & 0 deletions inspector/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
display: block;
color: red;
}

table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 4px;
}

.no-entries {
color: grey;
}
45 changes: 45 additions & 0 deletions inspector/templates/releases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'base.html' %}

{% block head %}
<link rel="stylesheet" type="text/css" href="/static/style.css">
{% endblock %}

{% block body %}
{% if releases|length != 1 %}
<p>Retrieved {{ releases|length }} versions.</p>
{% else %}
<p>Retrieved 1 version.</p>
{% endif %}

<table>
<colgroup>
<col style="width: 160px">
<col style="width: 160px">
<col style="width: 160px">
</colgroup>
<thead>
<tr>
<th>Version</th>
<th>Upload Timestamp</th>
<th>Artifacts</th>
</tr>
</thead>
{% for key, value in releases.items() %}
<tr>
{% if value|length > 0 %}
<td><a href="./{{ key }}">{{ key }}</a></td>
<td>{{ value[0]['upload_time'] }}</td>
<td>{{ value|length }}</td>
{% else %}
<td>{{ key }}</td>
<td><span class="no-entries"><i>Not Available</i></span></td>
<td><span class="no-entries"><i>Not Available</i></span></td>
{% endif %}
</tr>
{% endfor %}
<tbody>
</tbody>

</table>

{% endblock %}
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_versions(monkeypatch):
assert get.calls == [pretend.call("https://pypi.org/pypi/foo/json")]
assert render_template.calls == [
pretend.call(
"links.html",
links=["./0.5.1e"],
"releases.html",
releases={"0.5.1e": None},
h2="foo",
h2_link="/project/foo",
h2_paren="View this project on PyPI",
Expand Down

0 comments on commit 6f2a5e1

Please sign in to comment.