Skip to content

Commit

Permalink
Make dashboards done
Browse files Browse the repository at this point in the history
  • Loading branch information
Rieven committed Jan 7, 2025
1 parent c4c1d1b commit 5529aed
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rocky/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
File renamed without changes.
2 changes: 1 addition & 1 deletion rocky/crisis_room/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5529aed

Please sign in to comment.