Skip to content

Commit

Permalink
Change flash update html export
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed Nov 28, 2024
1 parent 636bae1 commit 0593704
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 26 deletions.
17 changes: 17 additions & 0 deletions flash_update/templatetags/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import template
from django.conf import settings
from django.core.files.storage import FileSystemStorage, get_storage_class

register = template.Library()

StorageClass = get_storage_class()


@register.filter(is_safe=True)
def media_full_path(path):
# TODO: Refactor http and https
if StorageClass == FileSystemStorage:
if settings.DEBUG:
return f"http://serve:8000{path}" # Don't use this in production
return f"https://{settings.BASE_URL}{path}"
return path
1 change: 0 additions & 1 deletion flash_update/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ def get_email_context(instance):
"actions_taken": actions_taken,
"resources": resources,
}
email_context = {key: value for key, value in email_context.items() if value is not None}
return email_context
1 change: 1 addition & 0 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@

ALLOWED_HOSTS = [
"localhost",
"serve",
"0.0.0.0",
GO_API_FQDN,
*env("DJANGO_ADDITIONAL_ALLOWED_HOSTS"),
Expand Down
68 changes: 43 additions & 25 deletions notifications/templates/email/flash_update/flash_pdf.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% load static %}
{% load tags %}

<!DOCTYPE html>
<html>
<style>
Expand Down Expand Up @@ -54,53 +57,68 @@ <h1 class="title-heading-main">{{title}}</h1>
<h2 class="heading">Situational Overview</h2>
<div id="situational_overview"><p> {{situational_overview|safe}}</p></div>

<h2 class="heading">Graphics and Maps</h2>

{% if not map_list|length == 0 %}
<table>
<tr>
<h2 class="heading">Graphics and Maps</h2>
{% for map in map_list %}
<td><img style='width:100%; height:100%;' src="{{map.image}}" alt="image"><br><p class='caption'>{{map.caption}}</p></td>
<div style='width:600px; height: 400px;'>
<img style='width:auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; object-position: center center;' src="{{ map.image | media_full_path}}" alt="image">
<br>
{% if map.caption %}
<div class='caption'>{{map.caption}}</div>
{% endif %}
</div>
{% endfor %}
</tr>
</table>
{% endif %}

{% if not graphic_list|length == 0 %}
<table>
<tr>
{% if graphic_list|length > 0 %}
{% for graphic in graphic_list %}
<td><img style='width:100%; height:100%;' src="{{graphic.image}}" alt="image"><br><p class='caption'>{{graphic.caption}}</p></td>
<div style='width:600px; height: 400px;'>
<img style='width:auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; object-position: center center;' src="{{ graphic.image | media_full_path}}" alt="image">
<br>
{% if graphic.caption %}
<div class='caption'>{{graphic.caption}}</div>
{% endif %}
</div>
{% endfor %}
</tr>
</table>
{% endif %}

<h2 class="heading">Actions Taken</h2>

{% for act_taken in actions_taken %}
<p class="sub-heading">Actions Taken by {{act_taken.organization_display}}</p>
{% if not actions_taken|length == 0 %}
<h2 class="heading">Actions Taken</h2>
{% for act_taken in actions_taken %}
{% if not act_taken.action_details|length == 0 or act_taken.summary %}
<p class="sub-heading">Actions Taken by {{act_taken.organization_display}}</p>

<p class="sub-heading">Descriptions</p>
<span class='desc'>{{act_taken.summary|linebreaks}}</span>
{% if act_taken.summary %}
<p class="sub-heading">Descriptions</p>
<span class='desc'>{{act_taken.summary|linebreaks}}</span>
{% endif %}

<p class="sub-heading">Actions</p>
{% for action in act_taken.action_details %}
<p class="actions">{{action.name}}</p>
{%endfor%}
{% if not act_taken.action_details|length == 0 %}
<p class="sub-heading">Actions</p>
{% for action in act_taken.action_details %}
<p class="actions">{{action.name}}</p>
{%endfor%}
{% endif %}
{% endif %}
{% endfor %}

{% endif %}

{% if not resources|length == 0 %}
<h2 class="heading">Resources</h2>
{% for resource in resources %}
<p class="desc">{{resource.date}} <br>
{{resource.source_description}} <br>
{% if resource.source_description %}
{{resource.source_description}} <br>
{% endif %}
{% if resource.url %}
<a class="actions">{{resource.url}}</a><br>
{% endif %}
{% if resource.flash_file %}
<a class="actions" href={{resource.flash_file}}> Download document</a>
{% endif %}
</p>
{%endfor%}
{% endfor %}
{% endif %}
</body>
</html>

0 comments on commit 0593704

Please sign in to comment.