Skip to content

Commit

Permalink
Added better templates
Browse files Browse the repository at this point in the history
  • Loading branch information
srugano committed Jul 15, 2024
1 parent 6f9ca27 commit 427f172
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/hope_country_report/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Meta:

@cached_property
def selected_office(self) -> CountryOffice:
co_slug: str = self.context["view"].kwargs[self.co_key]
co_slug: str = self.context["view"].kwargs.get(self.co_key)
if not co_slug:
print(f"Key '{self.co_key}' not found in view kwargs: {self.context['view'].kwargs}")
raise serializers.ValidationError("Country office slug is required.")
return CountryOffice.objects.get(slug=co_slug)

def get_office(self, obj: "Model"):
Expand Down Expand Up @@ -58,7 +61,7 @@ class Meta:
class DatasetSerializer(serializers.ModelSerializer):
class Meta:
model = Dataset
fields = ["hash", "last_run"]
fields = ["hash", "last_run", "size"]


class ReportConfigurationSerializer(SelectedOfficeSerializer):
Expand Down
6 changes: 4 additions & 2 deletions src/hope_country_report/apps/power_query/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from strategy_field.registry import Registry
from strategy_field.utils import fqn

from hope_country_report.apps.power_query.storage import HopeStorage
from hope_country_report.apps.power_query.storage import DataSetStorage
from hope_country_report.apps.power_query.utils import (
convert_pdf_to_image_pdf,
get_field_rect,
Expand Down Expand Up @@ -259,6 +259,7 @@ def insert_images_and_qr_codes(
font_size: int,
font_color: str,
):

for field_name, text in special_values.items():
insert_special_image(document, field_name, text, int(font_size), font_color)
for field_name, (rect, image_path) in images.items():
Expand All @@ -276,6 +277,7 @@ def insert_external_image(self, document: fitz.Document, field_name: str, image_
logger.error(f"No valid rectangle or page index found for field {field_name}. Cannot insert image.")
return
page = document[page_index]
logger.info(f"Inserting image {image_path} into field {field_name} on page {page_index}")
try:
image_stream = self.load_image_from_blob_storage(image_path)
image = Image.open(image_stream).rotate(-90, expand=True)
Expand Down Expand Up @@ -318,7 +320,7 @@ def is_special_language_field(self, field_name: str) -> Optional[str]:
return None

def load_image_from_blob_storage(self, image_path: str) -> BytesIO:
with HopeStorage().open(image_path, "rb") as img_file:
with DataSetStorage().open(image_path, "rb") as img_file:
return BytesIO(img_file.read())


Expand Down
2 changes: 2 additions & 0 deletions src/hope_country_report/middleware/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, get_response: "Callable[[HttpRequest],HttpResponse]") -> None
self.get_response = get_response

def process_exception(self, request: "AuthHttpRequest", exception: BaseException) -> HttpResponse:
# import ipdb
# ipdb.set_trace()
if isinstance(exception, (PermissionDenied,)):
return HttpResponseForbidden()
if isinstance(exception, (RequestablePermissionDenied,)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
</span>
<ul class="nav navbar-nav pull-right">
{% block userlinks %}
{% csrf_token %}
{% if user.is_authenticated %}
{% optional_logout request user %}
{% optional_logout request user csrf_token %}
{% else %}
{% optional_login request %}
{% endif %}
Expand Down

0 comments on commit 427f172

Please sign in to comment.