Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visit import string encode fix #158

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions commcare_connect/opportunity/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from django.conf import settings
from django.core.files.base import ContentFile
from django.core.files.storage import storages
from django.core.files.storage import default_storage
from django.utils.timezone import now

from commcare_connect.opportunity.app_xml import get_connect_blocks_for_app
Expand Down Expand Up @@ -53,7 +53,9 @@ def generate_visit_export(opportunity_id: int, date_range: str, status: list[str
dataset = export_user_visit_data(opportunity, DateRanges(date_range), [VisitValidationStatus(s) for s in status])
content = dataset.export(export_format)
export_tmp_name = f"{now().isoformat()}_{opportunity.name}_visit_export.{export_format}"
storages["default"].save(export_tmp_name, ContentFile(content))
if isinstance(content, str):
content = content.encode()
default_storage.save(export_tmp_name, ContentFile(content))
return export_tmp_name


Expand All @@ -63,5 +65,5 @@ def generate_payment_export(opportunity_id: int, export_format: str):
dataset = export_empty_payment_table(opportunity)
content = dataset.export(export_format)
export_tmp_name = f"{now().isoformat()}_{opportunity.name}_payment_export.{export_format}"
storages["default"].save(export_tmp_name, ContentFile(content))
default_storage.save(export_tmp_name, ContentFile(content))
return export_tmp_name
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h1 class="modal-title fs-5">{% translate "Import Verified Visits" %}</h1>
<div class="modal-body">
<div class="mb-3">
{% csrf_token %}
<input class="form-control" type="file" id="importFile" name="visits">
<input class="form-control" type="file" id="importFile" name="visits" required>
<div class="col-auto">
<span id="importFileHelp" class="form-text">
{% blocktrans %}
Expand Down