Skip to content

Commit 4e2d637

Browse files
Solve issue for rendering html tag in email
1 parent b4a1183 commit 4e2d637

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

flash_update/factories.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515
DonorGroup,
1616
)
1717

18+
from django.core.files.base import ContentFile
19+
1820

1921
class FlashGraphicMapFactory(factory.django.DjangoModelFactory):
2022
class Meta:
2123
model = FlashGraphicMap
2224

25+
file = factory.LazyAttribute(
26+
lambda _: ContentFile(
27+
factory.django.ImageField()._make_data(
28+
{'width': 1024, 'height': 768}
29+
), 'flash_update.jpg'
30+
)
31+
)
32+
2333

2434
class FlashActionFactory(factory.django.DjangoModelFactory):
2535
class Meta:

flash_update/tasks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from celery import shared_task
22

33
from django.utils import timezone
4-
from django.conf import settings
54
from django.core.files.base import ContentFile
65
from django.template.loader import render_to_string
76
from django.contrib.auth.models import User
@@ -26,7 +25,7 @@ def share_flash_update(flash_update_share_id):
2625

2726
# create url for pdf in email
2827
email_context = {
29-
'document_url': settings.BASE_URL + flash_update.extracted_file.url
28+
'document_url': flash_update.extracted_file.url
3029
}
3130
donors_emails = instance.donors.all().values_list('email', flat=True)
3231
donor_groups_emails = Donors.objects.filter(

flash_update/utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import logging
22
from io import BytesIO
33

4-
from django.conf import settings
54
from django.template.loader import render_to_string
65

76
from xhtml2pdf import pisa
87

98
from main.frontend import get_project_url
109

10+
from flash_update.models import FlashGraphicMap
11+
1112
logger = logging.getLogger(__name__)
1213

1314

@@ -30,8 +31,8 @@ def render_to_pdf(template_src, context_dict={}):
3031
def generate_file_data(data):
3132
return [
3233
{
33-
'image': item.get('file') and (settings.BASE_URL + item['file']),
34-
'caption': item['caption'],
34+
'image': item.file.url,
35+
'caption': item.caption,
3536
}
3637
for item in data
3738
]
@@ -41,8 +42,10 @@ def get_email_context(instance):
4142
from flash_update.serializers import FlashUpdateSerializer
4243

4344
flash_update_data = FlashUpdateSerializer(instance).data
44-
map_list = generate_file_data(flash_update_data['map_files'])
45-
graphics_list = generate_file_data(flash_update_data['graphics_files'])
45+
map_data = FlashGraphicMap.objects.filter(flash_map=instance)
46+
graphics_data = FlashGraphicMap.objects.filter(flash_graphics=instance)
47+
map_list = generate_file_data(map_data)
48+
graphics_list = generate_file_data(graphics_data)
4649
actions_taken = [dict(action_taken) for action_taken in flash_update_data['actions_taken']]
4750
resources = [dict(refrence) for refrence in flash_update_data['references']]
4851
email_context = {
@@ -53,6 +56,5 @@ def get_email_context(instance):
5356
'graphic_list': graphics_list,
5457
'actions_taken': actions_taken,
5558
'resources': resources,
56-
'document_url': flash_update_data['extracted_file']
5759
}
5860
return email_context

notifications/templates/email/flash_update/flash_pdf.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@
4040
</div>
4141
<h1 class="title-heading-main">{{title}}</h1>
4242
<h2 class="heading">Situational Overview</h2>
43-
<p class="desc"> {{situational_overview}}</p>
43+
<p class="desc"> {{situational_overview|safe}}</p>
4444

4545
<h2 class="heading">Graphics</h2>
4646
<div class="d-flex p-2">
4747
{% for map in map_list %}
48-
<img class = 'img-flash' src="http://{{map.image}}" alt="image">
48+
<img class = 'img-flash' src="{{map.image}}" alt="image">
4949
{% endfor %}
5050
</div><br>
5151
<div class="d-flex p-2">
5252
{% for graphic in graphic_list %}
53-
<img class = 'img-flash' src="http://{{graphic.image}}" alt="image">
53+
<img class = 'img-flash' src="{{graphic.image}}" alt="image">
5454
{% endfor %}
5555
</div>
5656

notifications/templates/email/flash_update/flash_update.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</tr>
1818
<tr>
1919
<td class="text-default text-light pb-40" style="padding-bottom: 40px;font-weight: 300;">
20-
{{situational_overview}}
20+
{{situational_overview|safe}}
2121
</td>
2222
</tr>
2323
<tr>
@@ -26,11 +26,11 @@
2626
<tr>
2727
<td class="text-default text-light pb-40" style="padding-bottom: 40px;font-weight: 300;">
2828
{% for map in map_list %}
29-
<img class = 'img-flash' src="http://{{map.image}}" alt="image">
29+
<img class = 'img-flash' src="{{map.image}}" alt="image">
3030
{% endfor %}
3131

3232
{% for graphic in graphic_list %}
33-
<img class = 'img-flash' src="http://{{graphic.image}}" alt="image">
33+
<img class = 'img-flash' src="{{graphic.image}}" alt="image">
3434
{% endfor %}
3535
</td>
3636
</tr>

0 commit comments

Comments
 (0)