mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-19 07:08:54 +01:00
feat(export): export and restore on the page, with progress and messages
The export and restore forms now sit on the Export and Restore page instead of an offcanvas. Exporting shows a progress line and a toast when the download starts; restoring splits ZIP and CSV uploads into tabs and shows errors in the form. - An empty export warns instead of downloading the message as a file - Export errors show a message instead of a stuck spinner - The download link is kept long enough for Safari to save the file - Non-superusers get a 403 instead of a redirect loop with the login - The asset classes CSV can be uploaded on its own - Drop the export form's unknown investment_classes layout field
This commit is contained in:
1 parent
b345f24533
commit
16a142afd5
7 files changed
+235
-235
No files matched your search
@@ -7,6 +7,7 @@ from decimal import Decimal
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.messages import get_messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test import TestCase
|
||||
@@ -879,7 +880,10 @@ class ExportRestoreTests(TestCase):
|
||||
response = self.client.post(
|
||||
reverse("restore_form"), {"zip_file": upload}, HTTP_HX_REQUEST="true"
|
||||
)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
self.assertIn(
|
||||
"Data restored successfully",
|
||||
[m.message for m in get_messages(response.wsgi_request)],
|
||||
)
|
||||
|
||||
service = BankSyncService._base_manager.get()
|
||||
self.assertEqual(service.owner, self.other)
|
||||
|
||||
@@ -1,139 +1,107 @@
|
||||
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||
from crispy_forms.bootstrap import FormActions
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import HTML, Layout
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class ExportForm(forms.Form):
|
||||
# Rendered by export_app/fragments/export.html, in declaration order
|
||||
users = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Users"),
|
||||
initial=True,
|
||||
)
|
||||
accounts = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Accounts"),
|
||||
initial=True,
|
||||
)
|
||||
currencies = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Currencies"),
|
||||
initial=True,
|
||||
)
|
||||
transactions = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Transactions"),
|
||||
initial=True,
|
||||
)
|
||||
categories = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Categories"),
|
||||
initial=True,
|
||||
)
|
||||
tags = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
label=_("Tags"),
|
||||
initial=False,
|
||||
)
|
||||
entities = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Entities"),
|
||||
initial=False,
|
||||
)
|
||||
recurring_transactions = forms.BooleanField(
|
||||
tags = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
label=_("Recurring Transactions"),
|
||||
initial=True,
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Tags"),
|
||||
initial=False,
|
||||
)
|
||||
installment_plans = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Installment Plans"),
|
||||
initial=True,
|
||||
)
|
||||
recurring_transactions = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Recurring Transactions"),
|
||||
initial=True,
|
||||
)
|
||||
quick_transactions = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Quick Transactions"),
|
||||
initial=True,
|
||||
)
|
||||
exchange_rates = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
label=_("Exchange Rates"),
|
||||
initial=False,
|
||||
)
|
||||
exchange_rates_services = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Automatic Exchange Rates"),
|
||||
initial=False,
|
||||
)
|
||||
exchange_rates = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Exchange Rates"),
|
||||
initial=False,
|
||||
)
|
||||
bank_sync = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Bank Sync"),
|
||||
help_text=_("Includes the providers' API keys"),
|
||||
initial=False,
|
||||
)
|
||||
rules = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Rules"),
|
||||
initial=True,
|
||||
)
|
||||
dca = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("DCA"),
|
||||
initial=False,
|
||||
)
|
||||
import_profiles = forms.BooleanField(
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
widget=forms.CheckboxInput(attrs={"class": "checkbox"}),
|
||||
label=_("Import Profiles"),
|
||||
initial=True,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_tag = False
|
||||
self.helper.form_method = "post"
|
||||
self.helper.layout = Layout(
|
||||
"users",
|
||||
"accounts",
|
||||
"investment_classes",
|
||||
"currencies",
|
||||
"transactions",
|
||||
"categories",
|
||||
"entities",
|
||||
"tags",
|
||||
"installment_plans",
|
||||
"recurring_transactions",
|
||||
"quick_transactions",
|
||||
"exchange_rates_services",
|
||||
"exchange_rates",
|
||||
"bank_sync",
|
||||
"rules",
|
||||
"dca",
|
||||
"import_profiles",
|
||||
FormActions(
|
||||
NoClassSubmit("submit", _("Export"), css_class="btn btn-primary"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class RestoreForm(forms.Form):
|
||||
zip_file = forms.FileField(
|
||||
@@ -178,38 +146,11 @@ class RestoreForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_tag = False
|
||||
self.helper.form_method = "post"
|
||||
self.helper.layout = Layout(
|
||||
"zip_file",
|
||||
HTML('<hr class="hr my-3"/>'),
|
||||
"users",
|
||||
"accounts",
|
||||
"currencies",
|
||||
"transactions",
|
||||
"sub_transactions",
|
||||
"transactions_categories",
|
||||
"transactions_entities",
|
||||
"transactions_tags",
|
||||
"installment_plans",
|
||||
"recurring_transactions",
|
||||
"quick_transactions",
|
||||
"automatic_exchange_rates",
|
||||
"exchange_rates",
|
||||
"bank_sync_services",
|
||||
"bank_sync_accounts",
|
||||
"transaction_rules",
|
||||
"transaction_rules_actions",
|
||||
"transaction_rules_update_or_create",
|
||||
"dca_strategies",
|
||||
"dca_entries",
|
||||
"import_profiles",
|
||||
FormActions(
|
||||
NoClassSubmit("submit", _("Restore"), css_class="btn btn-primary"),
|
||||
),
|
||||
)
|
||||
# Rendered by export_app/fragments/restore.html
|
||||
for name, field in self.fields.items():
|
||||
field.widget.attrs.update(
|
||||
{"class": "file-input w-full", "accept": ".zip" if name == "zip_file" else ".csv"}
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
+107
-96
@@ -3,7 +3,7 @@ import zipfile
|
||||
from io import BytesIO
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
@@ -51,21 +51,26 @@ from apps.export_app.resources.transactions import (
|
||||
)
|
||||
from apps.export_app.resources.users import UserResource
|
||||
from apps.common.decorators.demo import disabled_on_demo
|
||||
from apps.common.decorators.user import is_superuser
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
@login_required
|
||||
@disabled_on_demo
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
@is_superuser
|
||||
@require_http_methods(["GET"])
|
||||
def export_index(request):
|
||||
return render(request, "export_app/pages/index.html")
|
||||
return render(
|
||||
request,
|
||||
"export_app/pages/index.html",
|
||||
{"form": ExportForm(), "restore_form": RestoreForm()},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@disabled_on_demo
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
@is_superuser
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def export_form(request):
|
||||
timestamp = timezone.localtime(timezone.now()).strftime("%Y-%m-%dT%H-%M-%S")
|
||||
@@ -98,93 +103,104 @@ def export_form(request):
|
||||
export_dca = form.cleaned_data.get("dca", False)
|
||||
export_import_profiles = form.cleaned_data.get("import_profiles", False)
|
||||
|
||||
exports = []
|
||||
if export_users:
|
||||
exports.append((UserResource().export(), "users"))
|
||||
if export_accounts:
|
||||
exports.append((AccountResource().export(), "accounts"))
|
||||
exports.append(
|
||||
(InvestmentClassResource().export(), "investment_classes")
|
||||
)
|
||||
if export_currencies:
|
||||
exports.append((CurrencyResource().export(), "currencies"))
|
||||
if export_transactions:
|
||||
exports.append((TransactionResource().export(), "transactions"))
|
||||
if export_categories:
|
||||
exports.append(
|
||||
(TransactionCategoyResource().export(), "transactions_categories")
|
||||
)
|
||||
if export_tags:
|
||||
exports.append((TransactionTagResource().export(), "transactions_tags"))
|
||||
if export_entities:
|
||||
exports.append(
|
||||
(TransactionEntityResource().export(), "transactions_entities")
|
||||
)
|
||||
if export_installment_plans:
|
||||
exports.append(
|
||||
(InstallmentPlanResource().export(), "installment_plans")
|
||||
)
|
||||
if export_recurring_transactions:
|
||||
exports.append(
|
||||
(RecurringTransactionResource().export(), "recurring_transactions")
|
||||
)
|
||||
if export_quick_transactions:
|
||||
exports.append(
|
||||
(QuickTransactionResource().export(), "quick_transactions")
|
||||
)
|
||||
sub_transaction_parents = [
|
||||
parent
|
||||
for parent, exported in (
|
||||
("transaction", export_transactions),
|
||||
("installment_plan", export_installment_plans),
|
||||
("recurring_transaction", export_recurring_transactions),
|
||||
("quick_transaction", export_quick_transactions),
|
||||
)
|
||||
if exported
|
||||
]
|
||||
if sub_transaction_parents:
|
||||
exports.append(
|
||||
(
|
||||
SubTransactionResource(parents=sub_transaction_parents).export(),
|
||||
"sub_transactions",
|
||||
try:
|
||||
exports = []
|
||||
if export_users:
|
||||
exports.append((UserResource().export(), "users"))
|
||||
if export_accounts:
|
||||
exports.append((AccountResource().export(), "accounts"))
|
||||
exports.append(
|
||||
(InvestmentClassResource().export(), "investment_classes")
|
||||
)
|
||||
)
|
||||
if export_exchange_rates_services:
|
||||
exports.append(
|
||||
(ExchangeRateServiceResource().export(), "automatic_exchange_rates")
|
||||
)
|
||||
if export_exchange_rates:
|
||||
exports.append((ExchangeRateResource().export(), "exchange_rates"))
|
||||
if form.cleaned_data.get("bank_sync"):
|
||||
exports.append((BankSyncServiceResource().export(), "bank_sync_services"))
|
||||
exports.append((BankSyncAccountResource().export(), "bank_sync_accounts"))
|
||||
if export_rules:
|
||||
exports.append(
|
||||
(TransactionRuleResource().export(), "transaction_rules")
|
||||
)
|
||||
exports.append(
|
||||
(
|
||||
TransactionRuleActionResource().export(),
|
||||
"transaction_rules_actions",
|
||||
if export_currencies:
|
||||
exports.append((CurrencyResource().export(), "currencies"))
|
||||
if export_transactions:
|
||||
exports.append((TransactionResource().export(), "transactions"))
|
||||
if export_categories:
|
||||
exports.append(
|
||||
(TransactionCategoyResource().export(), "transactions_categories")
|
||||
)
|
||||
)
|
||||
exports.append(
|
||||
(
|
||||
UpdateOrCreateTransactionRuleResource().export(),
|
||||
"transaction_rules_update_or_create",
|
||||
if export_tags:
|
||||
exports.append((TransactionTagResource().export(), "transactions_tags"))
|
||||
if export_entities:
|
||||
exports.append(
|
||||
(TransactionEntityResource().export(), "transactions_entities")
|
||||
)
|
||||
)
|
||||
if export_dca:
|
||||
exports.append((DCAStrategyResource().export(), "dca_strategies"))
|
||||
exports.append(
|
||||
(
|
||||
DCAEntryResource().export(),
|
||||
"dca_entries",
|
||||
if export_installment_plans:
|
||||
exports.append(
|
||||
(InstallmentPlanResource().export(), "installment_plans")
|
||||
)
|
||||
)
|
||||
if export_import_profiles:
|
||||
exports.append((ImportProfileResource().export(), "import_profiles"))
|
||||
if export_recurring_transactions:
|
||||
exports.append(
|
||||
(RecurringTransactionResource().export(), "recurring_transactions")
|
||||
)
|
||||
if export_quick_transactions:
|
||||
exports.append(
|
||||
(QuickTransactionResource().export(), "quick_transactions")
|
||||
)
|
||||
sub_transaction_parents = [
|
||||
parent
|
||||
for parent, exported in (
|
||||
("transaction", export_transactions),
|
||||
("installment_plan", export_installment_plans),
|
||||
("recurring_transaction", export_recurring_transactions),
|
||||
("quick_transaction", export_quick_transactions),
|
||||
)
|
||||
if exported
|
||||
]
|
||||
if sub_transaction_parents:
|
||||
exports.append(
|
||||
(
|
||||
SubTransactionResource(parents=sub_transaction_parents).export(),
|
||||
"sub_transactions",
|
||||
)
|
||||
)
|
||||
if export_exchange_rates_services:
|
||||
exports.append(
|
||||
(ExchangeRateServiceResource().export(), "automatic_exchange_rates")
|
||||
)
|
||||
if export_exchange_rates:
|
||||
exports.append((ExchangeRateResource().export(), "exchange_rates"))
|
||||
if form.cleaned_data.get("bank_sync"):
|
||||
exports.append((BankSyncServiceResource().export(), "bank_sync_services"))
|
||||
exports.append((BankSyncAccountResource().export(), "bank_sync_accounts"))
|
||||
if export_rules:
|
||||
exports.append(
|
||||
(TransactionRuleResource().export(), "transaction_rules")
|
||||
)
|
||||
exports.append(
|
||||
(
|
||||
TransactionRuleActionResource().export(),
|
||||
"transaction_rules_actions",
|
||||
)
|
||||
)
|
||||
exports.append(
|
||||
(
|
||||
UpdateOrCreateTransactionRuleResource().export(),
|
||||
"transaction_rules_update_or_create",
|
||||
)
|
||||
)
|
||||
if export_dca:
|
||||
exports.append((DCAStrategyResource().export(), "dca_strategies"))
|
||||
exports.append(
|
||||
(
|
||||
DCAEntryResource().export(),
|
||||
"dca_entries",
|
||||
)
|
||||
)
|
||||
if export_import_profiles:
|
||||
exports.append((ImportProfileResource().export(), "import_profiles"))
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error exporting", exc_info=e)
|
||||
messages.error(
|
||||
request,
|
||||
_("There was an error exporting your data. Check the logs for more details."),
|
||||
)
|
||||
return HttpResponse(status=204, headers={"HX-Trigger": "updated"})
|
||||
|
||||
if exports:
|
||||
messages.success(request, _("Export ready, your download has started"))
|
||||
if len(exports) >= 2:
|
||||
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
||||
for dataset, name in exports:
|
||||
@@ -212,9 +228,9 @@ def export_form(request):
|
||||
)
|
||||
return response
|
||||
else:
|
||||
return HttpResponse(
|
||||
_("You have to select at least one export"),
|
||||
)
|
||||
# 204, or the download extension would save this message as a file
|
||||
messages.warning(request, _("You have to select at least one export"))
|
||||
return HttpResponse(status=204, headers={"HX-Trigger": "updated"})
|
||||
|
||||
else:
|
||||
form = ExportForm()
|
||||
@@ -225,7 +241,7 @@ def export_form(request):
|
||||
@only_htmx
|
||||
@login_required
|
||||
@disabled_on_demo
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
@is_superuser
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def import_form(request):
|
||||
if request.method == "POST":
|
||||
@@ -234,12 +250,7 @@ def import_form(request):
|
||||
try:
|
||||
process_imports(request, form.cleaned_data)
|
||||
messages.success(request, _("Data restored successfully"))
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={
|
||||
"HX-Trigger": "hide_offcanvas, updated",
|
||||
},
|
||||
)
|
||||
form = RestoreForm() # a fresh form clears the chosen files and old errors
|
||||
except Exception as e:
|
||||
logger.error("Error importing", exc_info=e)
|
||||
messages.error(
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
{% extends "extends/offcanvas.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% translate 'Export' %}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<form hx-post="{% url 'export_form' %}" hx-ext="htmx-download" hx-swap="none" id="export-form" class="show-loading px-1" target="_blank">
|
||||
{% crispy form %}
|
||||
</form>
|
||||
<form hx-post="{% url 'export_form' %}"
|
||||
hx-ext="htmx-download"
|
||||
hx-swap="none"
|
||||
hx-disabled-elt="find [type=submit]"
|
||||
hx-indicator="#export-progress"
|
||||
id="export-form"
|
||||
class="flex flex-col gap-4">
|
||||
{% csrf_token %}
|
||||
<div class="grid gap-1 sm:grid-cols-2">
|
||||
{% for field in form %}
|
||||
<label class="flex items-start gap-3 px-3 py-2 rounded-box cursor-pointer hover:bg-base-200 transition-colors">
|
||||
{{ field }}
|
||||
<span class="flex flex-col gap-1 leading-6">
|
||||
<span>{{ field.label }}</span>
|
||||
{% if field.help_text %}
|
||||
<span id="{{ field.auto_id }}_helptext" class="flex items-baseline gap-1.5 text-sm leading-5 text-warning">
|
||||
<i class="fa-solid fa-triangle-exclamation" aria-hidden="true"></i>{{ field.help_text }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
<button type="submit" class="btn btn-primary">{% translate 'Export' %}</button>
|
||||
<p id="export-progress" role="status" class="hidden [&.htmx-request]:flex items-center gap-2 text-sm text-base-content/70">
|
||||
<span class="loading loading-spinner loading-sm"></span>
|
||||
{% translate 'Preparing your export. The download starts on its own when it is ready.' %}
|
||||
</p>
|
||||
</form>
|
||||
@@ -1,17 +1,44 @@
|
||||
{% extends "extends/offcanvas.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% translate 'Restore' %}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<form hx-post="{% url 'restore_form' %}"
|
||||
hx-target="#generic-offcanvas"
|
||||
id="restore-form"
|
||||
enctype="multipart/form-data"
|
||||
class="show-loading px-1">
|
||||
{% crispy form %}
|
||||
</form>
|
||||
<form hx-post="{% url 'restore_form' %}"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
hx-encoding="multipart/form-data"
|
||||
hx-disabled-elt="find [type=submit]"
|
||||
hx-indicator="#restore-progress"
|
||||
id="restore-form"
|
||||
class="flex flex-col gap-4">
|
||||
{% csrf_token %}
|
||||
{% for error in form.non_field_errors %}
|
||||
<div role="alert" class="alert alert-error alert-soft">
|
||||
<i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i>{{ error }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="tabs tabs-border">
|
||||
<input type="radio" name="restore_source" class="tab" aria-label="{% translate 'ZIP file' %}" checked>
|
||||
<div class="tab-content pt-4">
|
||||
<label class="flex flex-col gap-2">
|
||||
<span class="text-base-content/70">{{ form.zip_file.help_text }}</span>
|
||||
{{ form.zip_file }}
|
||||
</label>
|
||||
</div>
|
||||
<input type="radio" name="restore_source" class="tab" aria-label="{% translate 'Individual CSV files' %}">
|
||||
<div class="tab-content pt-4">
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
{% for field in form %}
|
||||
{% if field.name != "zip_file" %}
|
||||
<label class="flex flex-col gap-1.5">
|
||||
<span class="text-sm">{{ field.label }}</span>
|
||||
{{ field }}
|
||||
</label>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
<button type="submit" class="btn btn-primary">{% translate 'Restore' %}</button>
|
||||
<p id="restore-progress" role="status" class="hidden [&.htmx-request]:flex items-center gap-2 text-sm text-base-content/70">
|
||||
<span class="loading loading-spinner loading-sm"></span>
|
||||
{% translate 'Restoring your data. This can take a while for large backups.' %}
|
||||
</p>
|
||||
</form>
|
||||
@@ -4,20 +4,21 @@
|
||||
{% block title %}{% translate 'Export and Restore' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="flex items-center justify-center min-h-[90dvh]">
|
||||
<div class="flex gap-4">
|
||||
<button class="btn btn-error btn-square w-24 h-24 flex flex-col items-center justify-center"
|
||||
hx-get="{% url 'export_form' %}"
|
||||
hx-target="#generic-offcanvas">
|
||||
<i class="fa-solid fa-download mb-1"></i>
|
||||
<span class="text-sm">{% trans 'Export' %}</span>
|
||||
</button>
|
||||
<button class="btn btn-success btn-square w-24 h-24 flex flex-col items-center justify-center"
|
||||
hx-get="{% url 'restore_form' %}"
|
||||
hx-target="#generic-offcanvas">
|
||||
<i class="fa-solid fa-upload mb-1"></i>
|
||||
<span class="text-sm">{% trans 'Restore' %}</span>
|
||||
</button>
|
||||
<div class="container">
|
||||
<div class="text-3xl font-bold font-mono w-full mb-3">{% translate 'Export and Restore' %}</div>
|
||||
<div class="grid gap-4 lg:grid-cols-2 items-start">
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body gap-4 p-6 sm:p-8">
|
||||
<h2 class="card-title"><i class="fa-solid fa-download"></i>{% translate 'Export' %}</h2>
|
||||
{% include "export_app/fragments/export.html" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body gap-4 p-6 sm:p-8">
|
||||
<h2 class="card-title"><i class="fa-solid fa-upload"></i>{% translate 'Restore' %}</h2>
|
||||
{% include "export_app/fragments/restore.html" with form=restore_form %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -49,13 +49,11 @@ htmx.defineExtension('htmx-download', {
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
// Cleanup
|
||||
setTimeout(() => {
|
||||
URL.revokeObjectURL(url);
|
||||
link.remove();
|
||||
}, 100);
|
||||
// Cleanup. Safari still reads the blob after click(), revoking early truncates the file
|
||||
link.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
|
||||
} else {
|
||||
} else if (xhr.status !== 204) {
|
||||
console.warn(`[htmx-download] Unexpected response status: ${xhr.status}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user