diff --git a/device/templates/details.html b/device/templates/details.html index af877fd..99346c9 100644 --- a/device/templates/details.html +++ b/device/templates/details.html @@ -29,9 +29,11 @@ + {% if dpps %} + {% endif %} @@ -232,7 +234,8 @@ {% endfor %} - + + {% if dpps %}
{% trans 'List of dpps' %}
@@ -249,6 +252,7 @@ {% endfor %}
+ {% endif %} {% endblock %} @@ -257,12 +261,12 @@ document.addEventListener('DOMContentLoaded', function () { // Obtener el hash de la URL (ejemplo: #components) const hash = window.location.hash - + // Verificar si hay un hash en la URL if (hash) { // Buscar el botón o enlace que corresponde al hash y activarlo const tabTrigger = document.querySelector(`[data-bs-target="${hash}"]`) - + if (tabTrigger) { // Crear una instancia de tab de Bootstrap para activar el tab const tab = new bootstrap.Tab(tabTrigger) diff --git a/device/views.py b/device/views.py index c7c2b1f..3baa054 100644 --- a/device/views.py +++ b/device/views.py @@ -1,6 +1,5 @@ from django.http import JsonResponse - -from django.http import Http404 +from django.conf import settings from django.urls import reverse_lazy from django.shortcuts import get_object_or_404, Http404 from django.utils.translation import gettext_lazy as _ @@ -13,10 +12,11 @@ from django.views.generic.base import TemplateView from dashboard.mixins import DashboardView, Http403 from evidence.models import Annotation from lot.models import LotTag -from dpp.models import Proof -from dpp.api_dlt import PROOF_TYPE from device.models import Device from device.forms import DeviceFormSet +if settings.DPP: + from dpp.models import Proof + from dpp.api_dlt import PROOF_TYPE class NewDeviceView(DashboardView, FormView): @@ -104,10 +104,12 @@ class DetailsView(DashboardView, TemplateView): context = super().get_context_data(**kwargs) self.object.initial() lot_tags = LotTag.objects.filter(owner=self.request.user.institution) - dpps = Proof.objects.filter( - uuid__in=self.object.uuids, - type=PROOF_TYPE["IssueDPP"] - ) + dpps = [] + if settings.DPP: + dpps = Proof.objects.filter( + uuid__in=self.object.uuids, + type=PROOF_TYPE["IssueDPP"] + ) context.update({ 'object': self.object, 'snapshot': self.object.get_last_evidence(), diff --git a/dhub/settings.py b/dhub/settings.py index a30ab2b..2aca54e 100644 --- a/dhub/settings.py +++ b/dhub/settings.py @@ -89,10 +89,13 @@ INSTALLED_APPS = [ "dashboard", "admin", "api", - "dpp", - "did", ] +DPP = config("DPP", default=False, cast=bool) + +if DPP: + INSTALLED_APPS.extend(["dpp", "did"]) + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", diff --git a/dhub/urls.py b/dhub/urls.py index d070a15..0b77144 100644 --- a/dhub/urls.py +++ b/dhub/urls.py @@ -14,7 +14,7 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ - +from django.conf import settings from django.urls import path, include urlpatterns = [ @@ -27,6 +27,10 @@ urlpatterns = [ path("user/", include("user.urls")), path("lot/", include("lot.urls")), path('api/', include('api.urls')), - path('dpp/', include('dpp.urls')), - path('did/', include('did.urls')), ] + +if settings.DPP: + urlpatterns.extend([ + path('dpp/', include('dpp.urls')), + path('did/', include('did.urls')), + ]) diff --git a/evidence/parse.py b/evidence/parse.py index 6a78285..3752bf5 100644 --- a/evidence/parse.py +++ b/evidence/parse.py @@ -4,12 +4,14 @@ import logging from dmidecode import DMIParse from json_repair import repair_json +from django.conf import settings from evidence.parse_details import get_lshw_child, ParseSnapshot from evidence.models import Annotation from evidence.xapian import index -from dpp.api_dlt import register_device_dlt, register_passport_dlt from utils.constants import CHASSIS_DH +if settings.DPP: + from dpp.api_dlt import register_device_dlt, register_passport_dlt logger = logging.getLogger('django') @@ -51,7 +53,8 @@ class Build: self.index() self.create_annotations() - self.register_device_dlt() + if settings.DPP: + self.register_device_dlt() def index(self): snap = json.dumps(self.json) diff --git a/evidence/views.py b/evidence/views.py index dabcd9d..c2868b2 100644 --- a/evidence/views.py +++ b/evidence/views.py @@ -137,7 +137,7 @@ class DownloadEvidenceView(DashboardView, TemplateView): evidence.get_doc() data = json.dumps(evidence.doc) response = HttpResponse(data, content_type="application/json") - response['Content-Disposition'] = 'attachment; filename={}'.format("credential.json") + response['Content-Disposition'] = 'attachment; filename={}'.format("evidence.json") return response