Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show files in release summary table #6520

Merged
merged 5 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions warehouse/manage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pyramid.response import Response
from pyramid.view import view_config, view_defaults
from sqlalchemy import func
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import Load, joinedload
from sqlalchemy.orm.exc import NoResultFound

import warehouse.utils.otp as otp
Expand Down Expand Up @@ -815,7 +815,37 @@ def destroy_project_docs(project, request):
permission="manage:project",
)
def manage_project_releases(project, request):
return {"project": project}
# Get the counts for all the files for this project, grouped by the
# release version and the package types
filecounts = (
request.db.query(Release.version, File.packagetype, func.count(File.id))
.options(Load(Release).load_only("version"))
.outerjoin(File)
.group_by(Release.id)
.group_by(File.packagetype)
.filter(Release.project == project)
.all()
)

# Turn rows like:
# [('0.1', 'bdist_wheel', 2), ('0.1', 'sdist', 1)]
# into:
# {
# '0.1: {
# 'bdist_wheel': 2,
# 'sdist': 1,
# 'total': 3,
# }
# }

version_to_file_counts = {}
for version, packagetype, count in filecounts:
packagetype_to_count = version_to_file_counts.setdefault(version, {})
packagetype_to_count.setdefault("total", 0)
packagetype_to_count[packagetype] = count
packagetype_to_count["total"] += count

return {"project": project, "version_to_file_counts": version_to_file_counts}


@view_defaults(
Expand Down
20 changes: 15 additions & 5 deletions warehouse/templates/manage/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2>Releases ({{ project.releases|length }})</h2>
<tr>
<th scope="col" class="table__version">Version</th>
<th scope="col" class="table__date">Release date</th>
<th scope="col" class="table__summary">Summary</th>
<th scope="col" class="table__summary">Files</th>
<th scope="col" class="table__options"></th>
</tr>
</thead>
Expand All @@ -40,12 +40,22 @@ <h2>Releases ({{ project.releases|length }})</h2>
</th>
<td class="table__date">{{ humanize(release.created) }}</td>
<td class="table__summary">
{% if release.summary %}
{{ release.summary }}
{% set num_files = version_to_file_counts[release.version]['total'] %}
{% if num_files %}
{% trans count=num_files %}
{{ count }} file
{% pluralize %}
{{ count }} files
{% endtrans %}
({% for packagetype, packagetype_count in version_to_file_counts[release.version].items() %}
{%- if packagetype != 'total' -%}
{{ packagetype_count }} {{ packagetype|format_package_type }}{{ ", " if not loop.last }}
{%- endif -%}
{% endfor %})
{% else %}
No Files
nlhkabu marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
</td>
</td>
<td class="table__options">
<nav class="dropdown dropdown--with-icons">
<button type="button" class="button button--primary dropdown__trigger" aria-haspopup="true" aria-expanded="false">
Expand Down