Repository: sissbruecker/linkding

Issue:
Feature Request: Export Bookmarks with Date and Time in Filename
Currently, the export option defaults to exporting bookmarks as `bookmarks.html`. It would be helpful to add the option to include the **date and time** in the exported filename by default (e.g., `bookmarks_YYYY-MM-DD_HH-MM-SS.html`). This would make it easier to organize multiple exports and avoid overwriting previous files.

Thanks for the great project!


Discussion:

Patch:
diff --git a/bookmarks/views/settings.py b/bookmarks/views/settings.py
index abce0ce9..7e6714ee 100644
--- a/bookmarks/views/settings.py
+++ b/bookmarks/views/settings.py
@@ -11,6 +11,7 @@
 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


Test patch:
diff --git a/bookmarks/tests/test_settings_export_view.py b/bookmarks/tests/test_settings_export_view.py
index 303f3d92..4837025d 100644
--- a/bookmarks/tests/test_settings_export_view.py
+++ b/bookmarks/tests/test_settings_export_view.py
@@ -1,3 +1,4 @@
+import datetime
 from unittest.mock import patch
 
 from django.test import TestCase
@@ -29,9 +30,6 @@ def test_should_export_successfully(self):
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response["content-type"], "text/plain; charset=UTF-8")
-        self.assertEqual(
-            response["Content-Disposition"], 'attachment; filename="bookmarks.html"'
-        )
 
         for bookmark in Bookmark.objects.all():
             self.assertContains(response, bookmark.url)
@@ -78,3 +76,16 @@ def test_should_show_hint_when_export_raises_error(self):
             self.assertFormErrorHint(
                 response, "An error occurred during bookmark export."
             )
+
+    def test_filename_includes_date_and_time(self):
+        self.setup_bookmark()
+        
+        # Mock timezone.now to return a fixed datetime for predictable filename
+        fixed_time = datetime.datetime(2023, 5, 15, 14, 30, 45, tzinfo=datetime.timezone.utc)
+        
+        with patch("bookmarks.views.settings.timezone.now", return_value=fixed_time):
+            response = self.client.get(reverse("linkding:settings.export"), follow=True)
+
+        self.assertEqual(response.status_code, 200)
+        expected_filename = 'attachment; filename="bookmarks_2023-05-15_14-30-45.html"'
+        self.assertEqual(response["Content-Disposition"], expected_filename)