Export
Export all bookmarks in Netscape HTML format.
+
+ Note that exporting bookmark notes is currently not supported due to limitations of the format.
+ For proper backups please use a database backup as described in the documentation.
+
Download (.html)
{% if export_error %}
diff --git a/bookmarks/tests/helpers.py b/bookmarks/tests/helpers.py
index d68875a..e72f2fd 100644
--- a/bookmarks/tests/helpers.py
+++ b/bookmarks/tests/helpers.py
@@ -1,5 +1,6 @@
import random
import logging
+import datetime
from typing import List
from bs4 import BeautifulSoup
@@ -35,6 +36,7 @@ class BookmarkFactoryMixin:
website_description: str = '',
web_archive_snapshot_url: str = '',
favicon_file: str = '',
+ added: datetime = None,
):
if not title:
title = get_random_string(length=32)
@@ -45,6 +47,8 @@ class BookmarkFactoryMixin:
if not url:
unique_id = get_random_string(length=32)
url = 'https://example.com/' + unique_id
+ if added is None:
+ added = timezone.now()
bookmark = Bookmark(
url=url,
title=title,
@@ -52,7 +56,7 @@ class BookmarkFactoryMixin:
notes=notes,
website_title=website_title,
website_description=website_description,
- date_added=timezone.now(),
+ date_added=added,
date_modified=timezone.now(),
owner=user,
is_archived=is_archived,
@@ -125,13 +129,15 @@ class BookmarkHtmlTag:
description: str = '',
add_date: str = '',
tags: str = '',
- to_read: bool = False):
+ to_read: bool = False,
+ private: bool = True):
self.href = href
self.title = title
self.description = description
self.add_date = add_date
self.tags = tags
self.to_read = to_read
+ self.private = private
class ImportTestMixin:
@@ -141,7 +147,8 @@ class ImportTestMixin:
+ TOREAD="{1 if tag.to_read else 0}"
+ PRIVATE="{1 if tag.private else 0}">
{tag.title if tag.title else ''}
{f'
{tag.description}' if tag.description else ''}
diff --git a/bookmarks/tests/test_exporter.py b/bookmarks/tests/test_exporter.py
index aab46af..74f7b06 100644
--- a/bookmarks/tests/test_exporter.py
+++ b/bookmarks/tests/test_exporter.py
@@ -1,10 +1,36 @@
from django.test import TestCase
+from django.utils import timezone
from bookmarks.services import exporter
from bookmarks.tests.helpers import BookmarkFactoryMixin
class ExporterTestCase(TestCase, BookmarkFactoryMixin):
+ def test_export_bookmarks(self):
+ added = timezone.now()
+ timestamp = int(added.timestamp())
+
+ bookmarks = [
+ self.setup_bookmark(url='https://example.com/1', title='Title 1', added=added,
+ description='Example description'),
+ self.setup_bookmark(url='https://example.com/2', title='Title 2', added=added,
+ tags=[self.setup_tag(name='tag1'), self.setup_tag(name='tag2'),
+ self.setup_tag(name='tag3')]),
+ self.setup_bookmark(url='https://example.com/3', title='Title 3', added=added, unread=True),
+ self.setup_bookmark(url='https://example.com/4', title='Title 4', added=added, shared=True),
+
+ ]
+ html = exporter.export_netscape_html(bookmarks)
+
+ lines = [
+ f'Title 1',
+ 'Example description',
+ f'Title 2',
+ f'Title 3',
+ f'Title 4',
+ ]
+ self.assertIn('\n\r'.join(lines), html)
+
def test_escape_html_in_title_and_description(self):
bookmark = self.setup_bookmark(
title='