From dae974660d525d88992f8c2a11aebc85c39dd1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sat, 13 Jan 2024 21:37:45 +0100 Subject: [PATCH] Display the services. --- src/project/static/css/style.css | 2 +- src/project/templates/base.html | 2 - src/project/templates/services_overview.html | 48 ++++++-------------- src/project/views.py | 31 +++++++++++-- src/services/registry.py | 4 ++ src/services/services.py | 18 ++++++++ 6 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/project/static/css/style.css b/src/project/static/css/style.css index d71a430..8f91fe4 100644 --- a/src/project/static/css/style.css +++ b/src/project/static/css/style.css @@ -256,7 +256,7 @@ div.content-view>h2 { div.services { display: flex; - justify-content: space-between; + justify-content: start; gap: var(--double-space); flex-wrap: wrap; } diff --git a/src/project/templates/base.html b/src/project/templates/base.html index 485fbdf..3dd07c4 100644 --- a/src/project/templates/base.html +++ b/src/project/templates/base.html @@ -78,13 +78,11 @@ - {% comment %}
  • Services
  • - {% endcomment %}
  • diff --git a/src/project/templates/services_overview.html b/src/project/templates/services_overview.html index 139165e..4678c4c 100644 --- a/src/project/templates/services_overview.html +++ b/src/project/templates/services_overview.html @@ -2,61 +2,39 @@ {% block content %} -
    - Coming soon! -
    - - {% comment %}

    Available services

    + {% for service in non_active_services %}
    -

    Forgejo

    -

    Forgejo is a service that blabla

    - Read more … -
    - Subscribe -
    -
    -
    -

    Mastodon

    -

    Mastodon is a service where you can write things to people around the world.

    - Read more … -
    - Subscribe -
    -
    -
    -

    Matrix

    -

    Matrix is a service that blabla

    - Read more … -
    - Subscribe -
    -
    -
    -

    NextCloud

    -

    NextCloud is a service that blabla

    - Read more … +

    {{ service.name }}

    +

    {{ service.description }}

    + + Visit +
    Subscribe
    + {% endfor %}
    - {% endcomment %} {% endblock %} diff --git a/src/project/views.py b/src/project/views.py index 7fbde77..22f4c8c 100644 --- a/src/project/views.py +++ b/src/project/views.py @@ -1,11 +1,12 @@ """Project views.""" - from __future__ import annotations +from membership.models import ServiceAccess +from services.registry import ServiceRegistry +from utils.view_utils import render from typing import TYPE_CHECKING from django_view_decorator import view -from utils.view_utils import render if TYPE_CHECKING: from django.http import HttpRequest @@ -29,4 +30,28 @@ def index(request: HttpRequest) -> HttpResponse: ) def services_overview(request: HttpRequest) -> HttpResponse: """View to show the services overview.""" - return render(request, "services_overview.html") + active_services = [ + access.service_implementation + for access in ServiceAccess.objects.filter( + user=request.user, + ) + ] + + active_service_classes = [service.__class__ for service in active_services] + + services = [ + service + for _, service in ServiceRegistry.get_items() + if service not in active_service_classes + ] + + context = { + "non_active_services": services, + "active_services": active_services, + } + + return render( + request=request, + template_name="services_overview.html", + context=context, + ) diff --git a/src/services/registry.py b/src/services/registry.py index 8fc430e..f80926d 100644 --- a/src/services/registry.py +++ b/src/services/registry.py @@ -13,6 +13,10 @@ class ServiceInterface(Interface): registry = ServiceRegistry + name: str + description: str + url: str + public: bool = False # TODO: add a way to add a something which defines the required fields for a service diff --git a/src/services/services.py b/src/services/services.py index e5580ac..f5e4998 100644 --- a/src/services/services.py +++ b/src/services/services.py @@ -3,25 +3,43 @@ from .registry import ServiceInterface class MailService(ServiceInterface): slug = "mail" + name = "Mail" + url = "https://mail.data.coop" + description = "Mail service for data.coop" class MatrixService(ServiceInterface): slug = "matrix" + name = "Matrix" + url = "https://matrix.data.coop" + description = "Matrix service for data.coop" class MastodonService(ServiceInterface): slug = "mastodon" + name = "Mastodon" + url = "https://social.data.coop" + description = "Mastodon service for data.coop" class NextcloudService(ServiceInterface): slug = "nextcloud" + name = "Nextcloud" + url = "https://cloud.data.coop" + description = "Nextcloud service for data.coop" class HedgeDocService(ServiceInterface): slug = "hedgedoc" + name = "HedgeDoc" + url = "https://pad.data.coop" public = True + description = "HedgeDoc service for data.coop" class RalllyService(ServiceInterface): slug = "rallly" + name = "Rallly" + url = "https://when.data.coop" public = True + description = "Rallly service for data.coop"