Skip to content

Commit b900b5f

Browse files
Merge pull request #79 from unicef/feature/send-bulk-update-xlsx-by-email
Send bulk update xlsx file by email
2 parents 8cf3f8c + 32dde4f commit b900b5f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/country_workspace/workspaces/admin/cleaners/actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def bulk_update_export(
155155
"pks": list(queryset.values_list("pk", flat=True)),
156156
"model_name": opts.label,
157157
"columns": columns,
158+
"send_to": request.user.email,
158159
},
159160
)
160161
job.queue()

src/country_workspace/workspaces/admin/cleaners/bulk_update.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from constance import config as constance_config
77
from django import forms
88
from django.apps import apps
9+
from django.conf import settings
910
from django.core.exceptions import ObjectDoesNotExist
11+
from django.core.mail import EmailMessage
1012
from hope_flex_fields.models import DataChecker, FlexField
1113
from hope_flex_fields.xlsx import get_format_for_field
1214
from hope_smart_import.readers import open_xls
@@ -174,6 +176,9 @@ def bulk_update_export_template(job: AsyncJob) -> bytes:
174176
filename = "bulk_update_export_template/%s/%s/%s.xlsx" % (job.program.pk, job.owner.pk, job.config["model_name"])
175177
out, __ = create_xls_importer(queryset, job.program, job.config["columns"])
176178
path = MEDIA_STORAGE.save(filename, out)
179+
mail = EmailMessage("Bulk update export", "", settings.DEFAULT_FROM_EMAIL, [job.config["send_to"]])
180+
mail.attach(filename, out, "application/vnd.ms-excel")
181+
mail.send()
177182
job.file = path
178183
job.save()
179184
return path

0 commit comments

Comments
 (0)