diff --git a/bookmarks/migrations/0021_userprofile_display_url.py b/bookmarks/migrations/0021_userprofile_display_url.py new file mode 100644 index 0000000..f44dce3 --- /dev/null +++ b/bookmarks/migrations/0021_userprofile_display_url.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-05-18 07:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookmarks', '0020_userprofile_tag_search'), + ] + + operations = [ + migrations.AddField( + model_name='userprofile', + name='display_url', + field=models.BooleanField(default=False), + ), + ] diff --git a/bookmarks/models.py b/bookmarks/models.py index ecef619..3d8ec93 100644 --- a/bookmarks/models.py +++ b/bookmarks/models.py @@ -171,13 +171,14 @@ class UserProfile(models.Model): default=TAG_SEARCH_STRICT) enable_sharing = models.BooleanField(default=False, null=False) enable_favicons = models.BooleanField(default=False, null=False) + display_url = models.BooleanField(default=False, null=False) class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ['theme', 'bookmark_date_display', 'bookmark_link_target', 'web_archive_integration', 'tag_search', - 'enable_sharing', 'enable_favicons'] + 'enable_sharing', 'enable_favicons', 'display_url'] @receiver(post_save, sender=get_user_model()) diff --git a/bookmarks/styles/bookmarks.scss b/bookmarks/styles/bookmarks.scss index b523378..874c056 100644 --- a/bookmarks/styles/bookmarks.scss +++ b/bookmarks/styles/bookmarks.scss @@ -64,6 +64,10 @@ ul.bookmark-list { vertical-align: text-top; } + .url-display { + color: $secondary-link-color; + } + .description { color: $gray-color-dark; diff --git a/bookmarks/styles/variables-dark.scss b/bookmarks/styles/variables-dark.scss index 384e567..ecaa0e5 100644 --- a/bookmarks/styles/variables-dark.scss +++ b/bookmarks/styles/variables-dark.scss @@ -21,6 +21,8 @@ $link-color: $primary-color !default; $link-color-dark: darken($link-color, 5%) !default; $link-color-light: $link-color !default; +$secondary-link-color: rgba(168, 177, 255, 0.73); + $alternative-color: #59bdb9; $alternative-color-dark: #73f1eb; diff --git a/bookmarks/styles/variables-light.scss b/bookmarks/styles/variables-light.scss index f24591d..7d71d70 100644 --- a/bookmarks/styles/variables-light.scss +++ b/bookmarks/styles/variables-light.scss @@ -2,3 +2,5 @@ $html-font-size: 18px !default; $alternative-color: #05a6a3; $alternative-color-dark: darken($alternative-color, 5%); + +$secondary-link-color: rgba(87, 85, 217, 0.64); \ No newline at end of file diff --git a/bookmarks/templates/bookmarks/bookmark_list.html b/bookmarks/templates/bookmarks/bookmark_list.html index eeb3782..b3894c1 100644 --- a/bookmarks/templates/bookmarks/bookmark_list.html +++ b/bookmarks/templates/bookmarks/bookmark_list.html @@ -18,6 +18,14 @@ {{ bookmark.resolved_title }} + {% if request.user.profile.display_url %} +
+ + {{ bookmark.url }} + +
+ {% endif %}
{% if bookmark.tag_names %} diff --git a/bookmarks/templates/settings/general.html b/bookmarks/templates/settings/general.html index 8562127..ab8c095 100644 --- a/bookmarks/templates/settings/general.html +++ b/bookmarks/templates/settings/general.html @@ -29,6 +29,15 @@ be hidden.
+
+ +
+ When enabled, this setting displays the bookmark URL below the title. +
+
{{ form.bookmark_link_target|add_class:"form-select col-2 col-sm-12" }} diff --git a/bookmarks/tests/test_bookmarks_list_tag.py b/bookmarks/tests/test_bookmarks_list_tag.py index 0178852..a8ae700 100644 --- a/bookmarks/tests/test_bookmarks_list_tag.py +++ b/bookmarks/tests/test_bookmarks_list_tag.py @@ -90,6 +90,25 @@ class BookmarkListTagTest(TestCase, BookmarkFactoryMixin): ''', html, count=count) + def assertBookmarkURLCount(self, html: str, bookmark: Bookmark, link_target: str = '_blank', count=0): + self.assertInHTML(f''' +
+ + { bookmark.url } + +
+ ''', html, count) + + def assertBookmarkURLVisible(self, html: str, bookmark: Bookmark): + self.assertBookmarkURLCount(html, bookmark, count=1) + + + def assertBookmarkURLHidden(self, html: str, bookmark: Bookmark, link_target: str = '_blank'): + self.assertBookmarkURLCount(html, bookmark, count=0) + + + def render_template(self, bookmarks: [Bookmark], template: Template, url: str = '/test') -> str: rf = RequestFactory() request = rf.get(url) @@ -252,3 +271,34 @@ class BookmarkListTagTest(TestCase, BookmarkFactoryMixin): html = self.render_default_template([bookmark]) self.assertFaviconHidden(html, bookmark) + + def test_bookmark_url_should_be_hidden_by_default(self): + profile = self.get_or_create_test_user().profile + profile.save() + + bookmark = self.setup_bookmark() + html = self.render_default_template([bookmark]) + + self.assertBookmarkURLHidden(html,bookmark) + + def test_show_bookmark_url_when_enabled(self): + profile = self.get_or_create_test_user().profile + profile.display_url = True + profile.save() + + bookmark = self.setup_bookmark() + html = self.render_default_template([bookmark]) + + self.assertBookmarkURLVisible(html,bookmark) + + def test_hide_bookmark_url_when_disabled(self): + profile = self.get_or_create_test_user().profile + profile.display_url = False + profile.save() + + bookmark = self.setup_bookmark() + html = self.render_default_template([bookmark]) + + self.assertBookmarkURLHidden(html,bookmark) + + diff --git a/bookmarks/tests/test_settings_general_view.py b/bookmarks/tests/test_settings_general_view.py index 5c8c09c..7fe62fb 100644 --- a/bookmarks/tests/test_settings_general_view.py +++ b/bookmarks/tests/test_settings_general_view.py @@ -29,6 +29,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin): 'enable_sharing': False, 'enable_favicons': False, 'tag_search': UserProfile.TAG_SEARCH_STRICT, + 'display_url': False, } return {**form_data, **overrides} @@ -54,6 +55,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin): 'enable_sharing': True, 'enable_favicons': True, 'tag_search': UserProfile.TAG_SEARCH_LAX, + 'display_url': True, } response = self.client.post(reverse('bookmarks:settings.general'), form_data) html = response.content.decode() @@ -68,6 +70,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin): self.assertEqual(self.user.profile.enable_sharing, form_data['enable_sharing']) self.assertEqual(self.user.profile.enable_favicons, form_data['enable_favicons']) self.assertEqual(self.user.profile.tag_search, form_data['tag_search']) + self.assertEqual(self.user.profile.display_url, form_data['display_url']) self.assertInHTML('''

Profile updated

''', html)