Skip to content

Commit

Permalink
fix(subscription): activation function
Browse files Browse the repository at this point in the history
  • Loading branch information
djs0109 committed Jul 26, 2024
1 parent d041d85 commit 684dcc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
27 changes: 17 additions & 10 deletions app/Entirety/subscriptions/templates/subscriptions/panel.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<div id="div_subscription_{{ subscription.uuid }}" class="col-6 col-xl-3 pe-3">
<div class="card">
<div class="card-header d-flex justify-content-center align-items-center">
<a type="button"
hx-post="{% url "projects:subscriptions:status" project_id=project.uuid pk=subscription.uuid %}"
hx-target="#div_subscription_{{ subscription.uuid }}"
hx-swap="outerHTML"
data-bs-toggle="tooltip" data-bs-placement="bottom"
title="{{ subscription.status.value }}" {% if view_only %}
class="pe-none" {% endif %}>
<i class="bi bi-power h3 mb-0 {{ subscription.status.value }}">
</i>
</a>
<form action="{% url 'projects:subscriptions:status' project_id=project.uuid pk=subscription.uuid %}"
method="post">
{% csrf_token %}
<button type="submit"
style="background: none; border: none; padding: 0;
{% if subscription.status.value == 'active' %}
color: green;
{% else %}color: red;
{% endif %}"
data-bs-toggle="tooltip" data-bs-placement="bottom"
title="{{ subscription.status.value }}" {% if view_only %}
class="pe-none" {% endif %}>
<span class="icon-wrapper">
<i class="bi bi-power h3 mb-0 {{ subscription.status.value }}"></i>
</span>
</button>
</form>
</div>
<div class="card-body d-flex flex-column">
<span class="h5" data-bs-toggle="tooltip" title="{{ subscription.description }}">
Expand Down
1 change: 0 additions & 1 deletion app/Entirety/subscriptions/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def get_queryset(self):
sub.description = sub_cb.description
sub.status = sub_cb.status
sub.project = self.project
# TODO now only support/display one entity
if sub_cb.subject.entities[0].id:
sub.entity_id = sub_cb.subject.entities[0].id
if sub_cb.subject.entities[0].idPattern:
Expand Down
22 changes: 6 additions & 16 deletions app/Entirety/subscriptions/views/status.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.conf import settings
from django.shortcuts import render
from django.shortcuts import redirect
from django.views.generic import View

from filip.clients.ngsi_v2.cb import ContextBrokerClient
from filip.models import FiwareHeader
from filip.models.ngsi_v2.base import Status as CBStatus

from projects.mixins import ProjectContextMixin
from subscriptions.models import Subscription

Expand All @@ -25,19 +23,11 @@ def post(self, request, *args, **kwargs):
service_path=self.project.fiware_service_path,
),
) as cb_client:
cb_sub = cb_client.get_subscription(uuid)
cb_sub.status = (
sub_cb = cb_client.get_subscription(uuid)
sub_cb.status = (
CBStatus.INACTIVE
if cb_sub.status is CBStatus.ACTIVE
if sub_cb.status is CBStatus.ACTIVE
else CBStatus.ACTIVE
)
cb_client.update_subscription(cb_sub)

sub.description = cb_sub.description
sub.status = cb_sub.status

return render(
request,
"subscriptions/panel.html",
{"project": self.project, "subscription": sub},
)
cb_client.update_subscription(sub_cb)
return redirect("projects:subscriptions:list", project_id=self.project.uuid)

0 comments on commit 684dcc9

Please sign in to comment.