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:
Herculino Trotta committed 2026-11-17 13:07:41 -03:00
1 parent b345f24533
commit 16a142afd5
7 files changed
+235 -235

No files matched your search

+35 -94
View File
@@ -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()