Skip to content

Commit

Permalink
Update listing templates
Browse files Browse the repository at this point in the history
Add unavailable_versions property to Package
Update PackageListing Detail and Versions pages to show
unavailability information
  • Loading branch information
x753 committed Oct 22, 2024
1 parent b8f56a3 commit 15e16fe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</script>
{% endif %}

{% cache_until "any_package_updated" "mod-detail-header" 300 object.package.pk community_identifier %}
{% cache_until "any_package_updated" "mod-detail-header" 300 object.package.pk community_identifier object.package.latest.pk %}

<nav class="mt-3" aria-label="breadcrumb">
<ol class="breadcrumb">
Expand All @@ -68,6 +68,12 @@

{% endcache %}

{% if show_review_status and object.package.unavailable_versions %}
<div class="alert alert-danger" role="alert">
One or more versions of this package are awaiting approval.
</div>
{% endif %}

{% if show_review_status and object.is_rejected %}
<div class="card text-white bg-danger mt-2">
<div class="card-body">
Expand Down Expand Up @@ -114,7 +120,7 @@ <h4 class="card-title">

<div class="card bg-light mt-2">
{% include "community/includes/package_tabs.html" with tabs=tabs %}
{% cache_until "any_package_updated" "mod-detail-content" 300 object.package.pk community_identifier %}
{% cache_until "any_package_updated" "mod-detail-content" 300 object.package.pk community_identifier object.package.latest.pk %}
{% include "community/includes/package_header.html" with object=object %}
<div class="card-body pb-1">
<table class="table mb-0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endblock %}

{% block content %}
{% cache_until "any_package_updated" "mod-detail-version-history" 300 object.package.pk community_identifier %}
{% cache_until "any_package_updated" "mod-detail-version-history" 300 object.package.pk community_identifier object.package.latest.pk %}

<nav class="mt-3" aria-label="breadcrumb">
<ol class="breadcrumb">
Expand Down Expand Up @@ -51,4 +51,20 @@ <h2 class="mb-0">Available versions</h2>
</div>

{% endcache %}

{% if show_management_panel and object.package.unavailable_versions %}
<div class="card bg-light mt-2 mb-2">
<div class="card-header">
<h2 class="mb-0">Unavailable versions</h2>
</div>
<div class="card-body pb-1">
<p>
The versions below are awaiting approval. If this takes more than 24 hours, please reach out to the moderators in
<a href="https://discord.thunderstore.io/">our Discord server</a>.
</p>
{% include "community/includes/version_table.html" with versions=object.package.unavailable_versions %}
</div>
</div>
{% endif %}

{% endblock %}
25 changes: 25 additions & 0 deletions django/thunderstore/repository/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def display_name(self):
@cached_property
def available_versions(self):
# TODO: Caching
if hasattr(self, "unavailable_versions"):
del self.unavailable_versions
versions = (
self.versions.filter(is_active=True)
.public_list()
Expand All @@ -184,6 +186,29 @@ def available_versions(self):
)
)

@cached_property
def unavailable_versions(self):
# TODO: Caching
versions = self.versions.filter(
is_active=True, review_status__in=["pending", "rejected"]
).values_list("pk", "version_number")
ordered = sorted(versions, key=lambda version: StrictVersion(version[1]))
pk_list = [version[0] for version in reversed(ordered)]
preserved = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(pk_list)])
return (
self.versions.filter(pk__in=pk_list)
.order_by(preserved)
.prefetch_related(
"dependencies",
"dependencies__package",
"dependencies__package__owner",
)
.select_related(
"package",
"package__owner",
)
)

@cached_property
def downloads(self):
# TODO: Caching
Expand Down

0 comments on commit 15e16fe

Please sign in to comment.