Add date and time to HTML export filename (#1101)

This commit is contained in:
Sascha Ißbrücker
2025-06-20 06:01:15 +02:00
committed by GitHub
parent 809e9e02f3
commit e87304501f
2 changed files with 20 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ from django.db.models import prefetch_related_objects
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
from rest_framework.authtoken.models import Token
from bookmarks.models import (
@@ -239,8 +240,12 @@ def bookmark_export(request: HttpRequest):
prefetch_related_objects(bookmarks, "tags")
file_content = exporter.export_netscape_html(list(bookmarks))
# Generate filename with current date and time
current_time = timezone.now()
filename = current_time.strftime("bookmarks_%Y-%m-%d_%H-%M-%S.html")
response = HttpResponse(content_type="text/plain; charset=UTF-8")
response["Content-Disposition"] = 'attachment; filename="bookmarks.html"'
response["Content-Disposition"] = f'attachment; filename="{filename}"'
response.write(file_content)
return response