-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/edit-report-recipe
- Loading branch information
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework import serializers | ||
|
||
from rocky.views.mixins import HydratedReport | ||
|
||
|
||
class ReportSerializer(serializers.BaseSerializer): | ||
def to_representation(self, instance): | ||
if isinstance(instance, HydratedReport): | ||
report = instance.parent_report | ||
else: | ||
report = instance | ||
return { | ||
"id": report.report_id, | ||
"valid_time": report.observed_at, | ||
"name": report.name, | ||
"report_type": report.report_type, | ||
"generated_at": report.date_generated, | ||
"intput_oois": report.input_oois, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from account.mixins import OrganizationAPIMixin | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse | ||
from rest_framework import viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.permissions import IsAuthenticated | ||
from structlog import get_logger | ||
from tools.view_helpers import url_with_querystring | ||
|
||
from octopoes.models import Reference | ||
from reports.serializers import ReportSerializer | ||
from rocky.views.mixins import ReportList | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class ReportViewSet(OrganizationAPIMixin, viewsets.ModelViewSet): | ||
# There are no extra permissions needed to view reports, so IsAuthenticated | ||
# is enough for list/retrieve. OrganizationAPIMixin will check if the user | ||
# is a member of the requested organization. | ||
permission_classes = [IsAuthenticated] | ||
serializer_class = ReportSerializer | ||
|
||
def get_queryset(self): | ||
return ReportList(self.octopoes_api_connector, self.valid_time) | ||
|
||
def get_object(self): | ||
pk = self.kwargs["pk"] | ||
|
||
return self.octopoes_api_connector.get(Reference.from_str(f"Report|{pk}"), valid_time=self.valid_time) | ||
|
||
@action(detail=True) | ||
def pdf(self, request, pk): | ||
report_ooi_id = f"Report|{pk}" | ||
|
||
url = url_with_querystring( | ||
reverse("view_report_pdf", kwargs={"organization_code": self.organization.code}), | ||
True, | ||
report_id=report_ooi_id, | ||
observed_at=self.valid_time.isoformat(), | ||
) | ||
|
||
return HttpResponseRedirect(redirect_to=url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters