Skip to content

Commit 43123a1

Browse files
Merge pull request #1488 from IFRCGo/fix/flash-update-export-issue-for-empty-graphics
Solve issue for pdf export for empty graphics
2 parents 5d796f3 + 0c15477 commit 43123a1

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

flash_update/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FlashCountryDistrictAdminInline(admin.TabularInline):
7171
class FlashUpdateAdmin(TranslationAdmin):
7272
inlines = [FlashCountryDistrictAdminInline, FlashActionTakenAdminInline]
7373
search_fields = ('title',)
74-
list_filter = ('hazard_type', 'share_with', 'flashcountrydistrict__country',)
74+
list_filter = ('hazard_type', 'share_with', 'flash_country_district__country')
7575

7676

7777
admin.site.register(FlashAction, FlashActionAdmin)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 2.2.28 on 2022-08-05 10:47
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('flash_update', '0010_auto_20220607_1157'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='flashcountrydistrict',
16+
name='flash_update',
17+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='flash_country_district', to='flash_update.FlashUpdate', verbose_name='Flash update'),
18+
),
19+
]

flash_update/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def __str__(self):
138138
class FlashCountryDistrict(models.Model):
139139
flash_update = models.ForeignKey(
140140
FlashUpdate, on_delete=models.CASCADE,
141-
verbose_name=_('Flash update')
141+
verbose_name=_('Flash update'),
142+
related_name='flash_country_district'
142143
)
143144
country = models.ForeignKey(
144145
Country, verbose_name=_('country'), on_delete=models.CASCADE,

flash_update/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class FlashUpdateSerializer(
114114
NestedCreateMixin,
115115
serializers.ModelSerializer
116116
):
117-
country_district = FlashCountryDistrictSerializer(source='flashcountrydistrict_set', many=True, required=False)
117+
country_district = FlashCountryDistrictSerializer(source='flash_country_district', many=True, required=False)
118118
references = FlashReferencesSerializer(many=True, required=False)
119119
actions_taken = FlashActionsTakenSerializer(source='actions_taken_flash', many=True, required=False)
120120
created_by_details = UserNameSerializer(source='created_by', read_only=True)

flash_update/views.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,23 @@ class FlashUpdateViewSet(viewsets.ModelViewSet):
3939
filterset_class = FlashUpdateFilter
4040

4141
def get_queryset(self):
42-
return FlashUpdate.objects.all().order_by('-created_at').distinct()
42+
return FlashUpdate.objects.all().select_related(
43+
'hazard_type',
44+
'created_by',
45+
'modified_by',
46+
).prefetch_related(
47+
'references',
48+
'references__document',
49+
'map',
50+
'map__created_by',
51+
'graphics',
52+
'graphics__created_by',
53+
'actions_taken_flash__flash_update',
54+
'actions_taken_flash__actions',
55+
'flash_country_district__flash_update',
56+
'flash_country_district__country',
57+
'flash_country_district__district'
58+
).order_by('-created_at').distinct()
4359

4460

4561
class FlashUpdateFileViewSet(
@@ -51,7 +67,7 @@ class FlashUpdateFileViewSet(
5167
serializer_class = FlashGraphicMapSerializer
5268

5369
def get_queryset(self):
54-
return FlashGraphicMap.objects.all()
70+
return FlashGraphicMap.objects.all().select_related('created_by')
5571

5672
@action(
5773
detail=False,

notifications/templates/email/flash_update/flash_pdf.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,25 @@ <h2 class="heading">Situational Overview</h2>
5656

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

59+
{% if not map_list|length == 0 %}
5960
<table>
6061
<tr>
6162
{% for map in map_list %}
6263
<td><img style='width:100%; height:100%;' src="{{map.image}}" alt="image"><br><p class='caption'>{{map.caption}}</p></td>
6364
{% endfor %}
6465
</tr>
6566
</table>
67+
{% endif %}
6668

69+
{% if not graphic_list|length == 0 %}
6770
<table>
6871
<tr>
6972
{% for graphic in graphic_list %}
7073
<td><img style='width:100%; height:100%;' src="{{graphic.image}}" alt="image"><br><p class='caption'>{{graphic.caption}}</p></td>
7174
{% endfor %}
7275
</tr>
7376
</table>
77+
{% endif %}
7478

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

0 commit comments

Comments
 (0)