WIP: Services #25
|
@ -79,7 +79,7 @@
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<a href="/services" class="{% active_path "services" "current" %}">
|
<a href="{% url "services:list" %}" class="{% active_path "services:list" "current" %}">
|
||||||
Services
|
Services
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -21,37 +21,3 @@ if TYPE_CHECKING:
|
||||||
def index(request: HttpRequest) -> HttpResponse:
|
def index(request: HttpRequest) -> HttpResponse:
|
||||||
"""View to show the index page."""
|
"""View to show the index page."""
|
||||||
return render(request, "index.html")
|
return render(request, "index.html")
|
||||||
|
|
||||||
|
|
||||||
@view(
|
|
||||||
paths="services/",
|
|
||||||
name="services",
|
|
||||||
login_required=True,
|
|
||||||
)
|
|
||||||
def services_overview(request: HttpRequest) -> HttpResponse:
|
|
||||||
"""View to show the services overview."""
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django import forms
|
||||||
from django_registries.registry import Interface
|
from django_registries.registry import Interface
|
||||||
from django_registries.registry import Registry
|
from django_registries.registry import Registry
|
||||||
|
|
||||||
|
@ -23,3 +24,17 @@ class ServiceInterface(Interface):
|
||||||
# - maybe a list of tuples with the field name and the type of the field
|
# - maybe a list of tuples with the field name and the type of the field
|
||||||
# this could be used to generate a form for the service, and also to validate
|
# this could be used to generate a form for the service, and also to validate
|
||||||
# the data saved in a JSONField on the ServiceAccess model
|
# the data saved in a JSONField on the ServiceAccess model
|
||||||
|
|
||||||
|
subscribe_fields: list[tuple[str, forms.Field]] = []
|
||||||
|
|
||||||
|
def get_form(self) -> type:
|
||||||
|
"""Get the form for the service"""
|
||||||
|
print(self.subscribe_fields)
|
||||||
|
return type(
|
||||||
|
"ServiceForm",
|
||||||
|
(forms.Form,),
|
||||||
|
{
|
||||||
|
field_name: field_type
|
||||||
|
for field_name, field_type in self.subscribe_fields
|
||||||
|
},
|
||||||
|
)()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
from .registry import ServiceInterface
|
from .registry import ServiceInterface
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +16,10 @@ class MatrixService(ServiceInterface):
|
||||||
url = "https://matrix.data.coop"
|
url = "https://matrix.data.coop"
|
||||||
description = "Matrix service for data.coop"
|
description = "Matrix service for data.coop"
|
||||||
|
|
||||||
|
subscribe_fields = [
|
||||||
|
("username", forms.CharField()),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class MastodonService(ServiceInterface):
|
class MastodonService(ServiceInterface):
|
||||||
slug = "mastodon"
|
slug = "mastodon"
|
||||||
|
|
9
src/services/templates/services/service_detail.html
Normal file
9
src/services/templates/services/service_detail.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="content-view">
|
||||||
|
<h2>{{ service.name }}</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
18
src/services/templates/services/service_subscribe.html
Normal file
18
src/services/templates/services/service_subscribe.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="content-view">
|
||||||
|
<h2>Subscribe to {{ service.name }}</h2>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
{{ form }}
|
||||||
|
|
||||||
|
<button type="submit">
|
||||||
|
Subscribe
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -28,11 +28,16 @@
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<h3>{{ service.name }}</h3>
|
<h3>{{ service.name }}</h3>
|
||||||
<p>{{ service.description }}</p>
|
<p>{{ service.description }}</p>
|
||||||
|
|
||||||
|
<a href="{% url "services:detail" service_slug=service.slug %}">
|
||||||
|
Read more
|
||||||
|
</a>
|
||||||
|
|
|
||||||
<a href="{{ service.url }}" target="_blank">
|
<a href="{{ service.url }}" target="_blank">
|
||||||
Visit
|
Visit
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<a>Subscribe</a>
|
<a href="{% url "services:subscribe" service_slug=service.slug %}">Subscribe</a>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
|
@ -1 +1,86 @@
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from django_view_decorator import namespaced_decorator_factory
|
||||||
|
|
||||||
|
from membership.models import ServiceAccess
|
||||||
|
from services.registry import ServiceRegistry
|
||||||
|
from utils.view_utils import render
|
||||||
|
|
||||||
|
|
||||||
|
services_view = namespaced_decorator_factory(
|
||||||
|
namespace="services",
|
||||||
|
base_path="services",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@services_view(
|
||||||
|
paths="",
|
||||||
|
name="list",
|
||||||
|
login_required=True,
|
||||||
|
)
|
||||||
|
def services_overview(request):
|
||||||
|
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/services_overview.html",
|
||||||
|
context=context,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@services_view(
|
||||||
|
paths="<str:service_slug>/",
|
||||||
|
name="detail",
|
||||||
|
login_required=True,
|
||||||
|
)
|
||||||
|
def service_detail(request, service_slug):
|
||||||
|
service = ServiceRegistry.get(slug=service_slug)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"service": service,
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request=request,
|
||||||
|
template_name="services/service_detail.html",
|
||||||
|
context=context,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@services_view(
|
||||||
|
paths="<str:service_slug>/subscribe/",
|
||||||
|
name="subscribe",
|
||||||
|
login_required=True,
|
||||||
|
)
|
||||||
|
def service_subscribe(request, service_slug):
|
||||||
|
service = ServiceRegistry.get(slug=service_slug)
|
||||||
|
|
||||||
|
# TODO: add a form to subscribe to the service
|
||||||
|
context = {
|
||||||
|
"service": service,
|
||||||
|
"base_path": "services:list",
|
||||||
|
"form": service.get_form(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request=request,
|
||||||
|
template_name="services/service_subscribe.html",
|
||||||
|
context=context,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue