mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-22 08:38:35 +02:00
feat(import): more UI and endpoints
This commit is contained in:
@@ -55,4 +55,11 @@ class ImportRunFileUploadForm(forms.Form):
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_tag = False
|
||||
self.helper.form_method = "post"
|
||||
self.helper.layout = Layout("file")
|
||||
self.helper.layout = Layout(
|
||||
"file",
|
||||
FormActions(
|
||||
NoClassSubmit(
|
||||
"submit", _("Import"), css_class="btn btn-outline-primary w-100"
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -491,7 +491,6 @@ class ImportService:
|
||||
|
||||
for row_number, row in enumerate(reader, start=1):
|
||||
self._process_row(row, row_number)
|
||||
self._increment_totals("processed", value=1)
|
||||
|
||||
def _validate_file_path(self, file_path: str) -> str:
|
||||
"""
|
||||
@@ -518,15 +517,14 @@ class ImportService:
|
||||
if self.settings.file_type == "csv":
|
||||
self._process_csv(file_path)
|
||||
|
||||
if self.import_run.processed_rows == self.import_run.total_rows:
|
||||
self._update_status("FINISHED")
|
||||
self._log(
|
||||
"info",
|
||||
f"Import completed successfully. "
|
||||
f"Successful: {self.import_run.successful_rows}, "
|
||||
f"Failed: {self.import_run.failed_rows}, "
|
||||
f"Skipped: {self.import_run.skipped_rows}",
|
||||
)
|
||||
self._update_status("FINISHED")
|
||||
self._log(
|
||||
"info",
|
||||
f"Import completed successfully. "
|
||||
f"Successful: {self.import_run.successful_rows}, "
|
||||
f"Failed: {self.import_run.failed_rows}, "
|
||||
f"Skipped: {self.import_run.skipped_rows}",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self._update_status("FAILED")
|
||||
|
||||
@@ -13,6 +13,11 @@ urlpatterns = [
|
||||
views.import_profile_list,
|
||||
name="import_profiles_list",
|
||||
),
|
||||
path(
|
||||
"import/profiles/<int:profile_id>/delete/",
|
||||
views.import_profile_delete,
|
||||
name="import_profile_delete",
|
||||
),
|
||||
path(
|
||||
"import/profiles/add/",
|
||||
views.import_profile_add,
|
||||
@@ -24,14 +29,19 @@ urlpatterns = [
|
||||
name="import_profile_edit",
|
||||
),
|
||||
path(
|
||||
"import/profiles/<int:profile_id>/runs/",
|
||||
views.import_run_add,
|
||||
name="import_profile_runs_index",
|
||||
"import/profiles/<int:profile_id>/runs/list/",
|
||||
views.import_runs_list,
|
||||
name="import_profile_runs_list",
|
||||
),
|
||||
path(
|
||||
"import/profiles/<int:profile_id>/runs/list/",
|
||||
views.import_run_add,
|
||||
name="import_profile_runs_list",
|
||||
"import/profiles/<int:profile_id>/runs/<int:run_id>/log/",
|
||||
views.import_run_log,
|
||||
name="import_run_log",
|
||||
),
|
||||
path(
|
||||
"import/profiles/<int:profile_id>/runs/<int:run_id>/delete/",
|
||||
views.import_run_delete,
|
||||
name="import_run_delete",
|
||||
),
|
||||
path(
|
||||
"import/profiles/<int:profile_id>/runs/add/",
|
||||
|
||||
@@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -107,11 +108,30 @@ def import_profile_edit(request, profile_id):
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def import_run_list(request, profile_id):
|
||||
@csrf_exempt
|
||||
@require_http_methods(["DELETE"])
|
||||
def import_profile_delete(request, profile_id):
|
||||
profile = ImportProfile.objects.get(id=profile_id)
|
||||
|
||||
runs = ImportRun.objects.filter(profile=profile).order_by("id")
|
||||
profile.delete()
|
||||
|
||||
messages.success(request, _("Import Profile deleted successfully"))
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={
|
||||
"HX-Trigger": "updated",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def import_runs_list(request, profile_id):
|
||||
profile = ImportProfile.objects.get(id=profile_id)
|
||||
|
||||
runs = ImportRun.objects.filter(profile=profile).order_by("-id")
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -120,6 +140,19 @@ def import_run_list(request, profile_id):
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def import_run_log(request, profile_id, run_id):
|
||||
run = ImportRun.objects.get(profile__id=profile_id, id=run_id)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"import_app/fragments/runs/log.html",
|
||||
{"run": run},
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
@@ -140,6 +173,8 @@ def import_run_add(request, profile_id):
|
||||
# Defer the procrastinate task
|
||||
process_import.defer(import_run_id=import_run.id, file_path=file_path)
|
||||
|
||||
messages.success(request, _("Import Run queued successfully"))
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={
|
||||
@@ -154,3 +189,22 @@ def import_run_add(request, profile_id):
|
||||
"import_app/fragments/runs/add.html",
|
||||
{"form": form, "profile": profile},
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@csrf_exempt
|
||||
@require_http_methods(["DELETE"])
|
||||
def import_run_delete(request, profile_id, run_id):
|
||||
run = ImportRun.objects.get(profile__id=profile_id, id=run_id)
|
||||
|
||||
run.delete()
|
||||
|
||||
messages.success(request, _("Run deleted successfully"))
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={
|
||||
"HX-Trigger": "updated",
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user