From b004f5066abab2570f2bd8d6f60a5d6c4c93ab12 Mon Sep 17 00:00:00 2001 From: Mythic Date: Fri, 30 Aug 2024 20:56:59 +0300 Subject: [PATCH] Add community list view Implement a simple community list view, intended to serve as a fallback for environments where the cyberstorm remix frontend isn't running (such as local development environments) Remove the "other communities" section from the navbar communities dropdown and instead link to the community list page. --- builder/src/scss/navbar.scss | 7 ++- .../templates/community/community_list.html | 46 +++++++++++++++++++ django/thunderstore/community/views.py | 13 ++++++ django/thunderstore/core/urls.py | 2 + .../thunderstore/frontend/templates/base.html | 13 ++---- 5 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 django/thunderstore/community/templates/community/community_list.html diff --git a/builder/src/scss/navbar.scss b/builder/src/scss/navbar.scss index 2b39d6ee7..03ab89dbc 100644 --- a/builder/src/scss/navbar.scss +++ b/builder/src/scss/navbar.scss @@ -6,7 +6,7 @@ padding: 1.5rem 1.75rem; .grid { - column-count: 4; + column-count: 2; @media (max-width: 1500px) { column-count: 3; @@ -43,5 +43,10 @@ opacity: 0.5; margin-bottom: 0.75rem; } + + .link { + padding: 0 0.25rem; + margin-bottom: 0.75rem; + } } } diff --git a/django/thunderstore/community/templates/community/community_list.html b/django/thunderstore/community/templates/community/community_list.html new file mode 100644 index 000000000..c8dfb72e7 --- /dev/null +++ b/django/thunderstore/community/templates/community/community_list.html @@ -0,0 +1,46 @@ +{% extends 'base.html' %} +{% load cache %} +{% load thumbnail %} + +{% block title %}All communities{% endblock %} + +{% block content %} +{% cache 300 templates.community.list %} + +
+

{{ page_title }}

+
+ +{% if object_list %} +
+ {% for object in object_list %} +
+ +
+
{{ object.name }}
+
+
+  {{ object.aggregated_fields.package_count }} +
+
+ {{ object.aggregated_fields.download_count }}  +
+
+
+
+ {% endfor %} +
+{% else %} +
  • No communities available
  • +{% endif %} + +{% endcache %} +{% endblock %} diff --git a/django/thunderstore/community/views.py b/django/thunderstore/community/views.py index 07055be33..e3c8789b1 100644 --- a/django/thunderstore/community/views.py +++ b/django/thunderstore/community/views.py @@ -1,8 +1,21 @@ from django.conf import settings +from django.db.models import QuerySet from django.shortcuts import redirect from django.views import View +from django.views.generic import ListView + +from thunderstore.community.models import Community class FaviconView(View): def get(self, *args, **kwargs): return redirect(f"{settings.STATIC_URL}favicon.ico") + + +class CommunityListView(ListView): + model = Community + + def get_queryset(self) -> QuerySet[Community]: + return Community.objects.listed().order_by( + "-aggregated_fields__package_count", "-datetime_created" + ) diff --git a/django/thunderstore/core/urls.py b/django/thunderstore/core/urls.py index 58a23904f..ee7fa2456 100644 --- a/django/thunderstore/core/urls.py +++ b/django/thunderstore/core/urls.py @@ -8,6 +8,7 @@ from rest_framework import permissions from thunderstore.community.urls import community_urls +from thunderstore.community.views import CommunityListView from thunderstore.frontend.views import ( ManifestV1ValidatorView, MarkdownPreviewView, @@ -37,6 +38,7 @@ path("logout/", LogoutView.as_view(), kwargs={"next_page": "/"}, name="logout"), path("package/", include((legacy_package_urls, "old_urls"), namespace="old_urls")), path("c/", include((community_urls, "communities"), namespace="communities")), + path("communities/", CommunityListView.as_view(), name="communities"), path("settings/", include(settings_urls)), path("moderation/", include(moderation_urls)), path("favicon.ico", FaviconView.as_view()), diff --git a/django/thunderstore/frontend/templates/base.html b/django/thunderstore/frontend/templates/base.html index c27f2b004..a104a6324 100644 --- a/django/thunderstore/frontend/templates/base.html +++ b/django/thunderstore/frontend/templates/base.html @@ -58,16 +58,9 @@
    Popular communities
    {% endfor %} - {% if selectable_communities|length > 6 %} -
    -
    Other communities
    -
    - {% for community in selectable_communities|slice:"8:"|dictsort:"name" %} - {{ community.name }} - {% endfor %} -
    -
    - {% endif %} +
    + View all communities ({{ selectable_communities|length }}) +
    {% endif %}