Show URL as fallback if no title is available (#64)

This commit is contained in:
Sascha Ißbrücker 2021-01-16 00:57:57 +01:00 committed by GitHub
parent 94eb55896d
commit 085027b00a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -51,7 +51,12 @@ class Bookmark(models.Model):
@property
def resolved_title(self):
return self.website_title if not self.title else self.title
if self.title:
return self.title
elif self.website_title:
return self.website_title
else:
return self.url
@property
def resolved_description(self):

View file

@ -0,0 +1,16 @@
from django.test import TestCase
from bookmarks.models import Bookmark
class BookmarkTestCase(TestCase):
def test_bookmark_resolved_title(self):
bookmark = Bookmark(title='Custom title', website_title='Website title', url='https://example.com')
self.assertEqual(bookmark.resolved_title, 'Custom title')
bookmark = Bookmark(title='', website_title='Website title', url='https://example.com')
self.assertEqual(bookmark.resolved_title, 'Website title')
bookmark = Bookmark(title='', website_title='', url='https://example.com')
self.assertEqual(bookmark.resolved_title, 'https://example.com')