Skip to content

Commit 0593704

Browse files
committed
Change flash update html export
1 parent 636bae1 commit 0593704

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

flash_update/templatetags/tags.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django import template
2+
from django.conf import settings
3+
from django.core.files.storage import FileSystemStorage, get_storage_class
4+
5+
register = template.Library()
6+
7+
StorageClass = get_storage_class()
8+
9+
10+
@register.filter(is_safe=True)
11+
def media_full_path(path):
12+
# TODO: Refactor http and https
13+
if StorageClass == FileSystemStorage:
14+
if settings.DEBUG:
15+
return f"http://serve:8000{path}" # Don't use this in production
16+
return f"https://{settings.BASE_URL}{path}"
17+
return path

flash_update/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ def get_email_context(instance):
5959
"actions_taken": actions_taken,
6060
"resources": resources,
6161
}
62-
email_context = {key: value for key, value in email_context.items() if value is not None}
6362
return email_context

main/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137

138138
ALLOWED_HOSTS = [
139139
"localhost",
140+
"serve",
140141
"0.0.0.0",
141142
GO_API_FQDN,
142143
*env("DJANGO_ADDITIONAL_ALLOWED_HOSTS"),

notifications/templates/email/flash_update/flash_pdf.html

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% load static %}
2+
{% load tags %}
3+
14
<!DOCTYPE html>
25
<html>
36
<style>
@@ -54,53 +57,68 @@ <h1 class="title-heading-main">{{title}}</h1>
5457
<h2 class="heading">Situational Overview</h2>
5558
<div id="situational_overview"><p> {{situational_overview|safe}}</p></div>
5659

57-
<h2 class="heading">Graphics and Maps</h2>
58-
5960
{% if not map_list|length == 0 %}
60-
<table>
61-
<tr>
61+
<h2 class="heading">Graphics and Maps</h2>
6262
{% for map in map_list %}
63-
<td><img style='width:100%; height:100%;' src="{{map.image}}" alt="image"><br><p class='caption'>{{map.caption}}</p></td>
63+
<div style='width:600px; height: 400px;'>
64+
<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">
65+
<br>
66+
{% if map.caption %}
67+
<div class='caption'>{{map.caption}}</div>
68+
{% endif %}
69+
</div>
6470
{% endfor %}
65-
</tr>
66-
</table>
6771
{% endif %}
6872

69-
{% if not graphic_list|length == 0 %}
70-
<table>
71-
<tr>
73+
{% if graphic_list|length > 0 %}
7274
{% for graphic in graphic_list %}
73-
<td><img style='width:100%; height:100%;' src="{{graphic.image}}" alt="image"><br><p class='caption'>{{graphic.caption}}</p></td>
75+
<div style='width:600px; height: 400px;'>
76+
<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">
77+
<br>
78+
{% if graphic.caption %}
79+
<div class='caption'>{{graphic.caption}}</div>
80+
{% endif %}
81+
</div>
7482
{% endfor %}
75-
</tr>
76-
</table>
7783
{% endif %}
7884

79-
<h2 class="heading">Actions Taken</h2>
80-
81-
{% for act_taken in actions_taken %}
82-
<p class="sub-heading">Actions Taken by {{act_taken.organization_display}}</p>
85+
{% if not actions_taken|length == 0 %}
86+
<h2 class="heading">Actions Taken</h2>
87+
{% for act_taken in actions_taken %}
88+
{% if not act_taken.action_details|length == 0 or act_taken.summary %}
89+
<p class="sub-heading">Actions Taken by {{act_taken.organization_display}}</p>
8390

84-
<p class="sub-heading">Descriptions</p>
85-
<span class='desc'>{{act_taken.summary|linebreaks}}</span>
91+
{% if act_taken.summary %}
92+
<p class="sub-heading">Descriptions</p>
93+
<span class='desc'>{{act_taken.summary|linebreaks}}</span>
94+
{% endif %}
8695

87-
<p class="sub-heading">Actions</p>
88-
{% for action in act_taken.action_details %}
89-
<p class="actions">{{action.name}}</p>
90-
{%endfor%}
96+
{% if not act_taken.action_details|length == 0 %}
97+
<p class="sub-heading">Actions</p>
98+
{% for action in act_taken.action_details %}
99+
<p class="actions">{{action.name}}</p>
100+
{%endfor%}
101+
{% endif %}
102+
{% endif %}
91103
{% endfor %}
92104

105+
{% endif %}
106+
107+
{% if not resources|length == 0 %}
93108
<h2 class="heading">Resources</h2>
94109
{% for resource in resources %}
95110
<p class="desc">{{resource.date}} <br>
96-
{{resource.source_description}} <br>
111+
{% if resource.source_description %}
112+
{{resource.source_description}} <br>
113+
{% endif %}
97114
{% if resource.url %}
98115
<a class="actions">{{resource.url}}</a><br>
99116
{% endif %}
100117
{% if resource.flash_file %}
101118
<a class="actions" href={{resource.flash_file}}> Download document</a>
102119
{% endif %}
103120
</p>
104-
{%endfor%}
121+
{% endfor %}
122+
{% endif %}
105123
</body>
106124
</html>

0 commit comments

Comments
 (0)