From 5529aed3042010af24df26a1c81fba5a0532de2d Mon Sep 17 00:00:00 2001 From: Rieven Date: Tue, 7 Jan 2025 13:38:38 +0100 Subject: [PATCH] Make dashboards done --- rocky/Makefile | 2 +- rocky/crisis_room/management/commands/__init__.py | 0 .../management/commands/dashboard.py | 15 +++++++++------ .../{ => management/commands}/recipe_seeder.json | 0 rocky/crisis_room/views.py | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 rocky/crisis_room/management/commands/__init__.py rename rocky/{tools => crisis_room}/management/commands/dashboard.py (90%) rename rocky/crisis_room/{ => management/commands}/recipe_seeder.json (100%) diff --git a/rocky/Makefile b/rocky/Makefile index 783333c17aa..3fcf1cf020e 100644 --- a/rocky/Makefile +++ b/rocky/Makefile @@ -15,7 +15,7 @@ build-rocky: docker compose run --rm -e DATABASE_MIGRATION=false rocky make build-rocky-native dashboards: - python3 manage.py dashboard + docker compose run --rm rocky python3 manage.py dashboard build-rocky-native: while ! nc -vz $$ROCKY_DB_HOST $$ROCKY_DB_PORT; do sleep 0.1; done diff --git a/rocky/crisis_room/management/commands/__init__.py b/rocky/crisis_room/management/commands/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/rocky/tools/management/commands/dashboard.py b/rocky/crisis_room/management/commands/dashboard.py similarity index 90% rename from rocky/tools/management/commands/dashboard.py rename to rocky/crisis_room/management/commands/dashboard.py index cdd3055a527..a7354defce7 100644 --- a/rocky/tools/management/commands/dashboard.py +++ b/rocky/crisis_room/management/commands/dashboard.py @@ -8,18 +8,19 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.core.management import BaseCommand +from tools.models import Organization, OrganizationMember +from tools.ooi_helpers import create_ooi from octopoes.connector.octopoes import OctopoesAPIConnector from octopoes.models.ooi.reports import ReportRecipe from rocky.bytes_client import get_bytes_client from rocky.scheduler import ReportTask, ScheduleRequest, scheduler_client -from tools.models import Organization, OrganizationMember -from tools.ooi_helpers import create_ooi FINDINGS_DASHBOARD_NAME = "Crisis Room Findings Dashboard" +User = get_user_model() -def update_or_create_default_dashboard(organization: Organization): +def get_or_create_default_dashboard(organization: Organization): valid_time = datetime.now(timezone.utc) is_scheduler_ready_for_schedule = is_scheduler_enabled(organization) @@ -33,7 +34,7 @@ def update_or_create_default_dashboard(organization: Organization): dashboard_data, created = DashboardData.objects.get_or_create(dashboard=dashboard) if created: recipe = create_organization_recipe(valid_time, organization, recipe_default) - dashboard_data.recipe = recipe.pk + dashboard_data.recipe = recipe.recipe_id schedule_request = create_schedule_request(valid_time, organization, recipe) scheduler_client(organization.code).post_schedule(schedule=schedule_request) @@ -77,6 +78,8 @@ def create_schedule_request( class Command(BaseCommand): def handle(self, *args, **options): - organizations = [member.organization for member in OrganizationMember.objects.filter(user=get_user_model())] + superusers = User.objects.filter(is_superuser=True) + + organizations = [member.organization for member in OrganizationMember.objects.filter(user=superusers[0].pk)] for organization in organizations: - update_or_create_default_dashboard(organization) + get_or_create_default_dashboard(organization) diff --git a/rocky/crisis_room/recipe_seeder.json b/rocky/crisis_room/management/commands/recipe_seeder.json similarity index 100% rename from rocky/crisis_room/recipe_seeder.json rename to rocky/crisis_room/management/commands/recipe_seeder.json diff --git a/rocky/crisis_room/views.py b/rocky/crisis_room/views.py index 6028a8857c3..1dba5f92222 100644 --- a/rocky/crisis_room/views.py +++ b/rocky/crisis_room/views.py @@ -15,10 +15,10 @@ from pydantic import TypeAdapter from reports.report_types.findings_report.report import SEVERITY_OPTIONS from tools.forms.base import ObservedAtForm -from tools.management.commands.dashboard import FINDINGS_DASHBOARD_NAME from tools.models import Organization, OrganizationMember from tools.view_helpers import BreadcrumbsMixin +from crisis_room.management.commands.dashboard import FINDINGS_DASHBOARD_NAME from crisis_room.models import DashboardData from octopoes.connector import ConnectorException from octopoes.connector.octopoes import OctopoesAPIConnector