From 395115eef9c6176f0ed3b96d02668a1a1bb5495a Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Wed, 20 Jul 2016 21:42:53 +0200 Subject: [PATCH] 'starred' support; catch case where there's no title --- digimarks.py | 19 ++++++++++++++++--- templates/bookmarks.html | 3 +++ templates/edit.html | 15 ++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/digimarks.py b/digimarks.py index d052abb..03b1805 100644 --- a/digimarks.py +++ b/digimarks.py @@ -65,8 +65,9 @@ class Bookmark(db.Model): #image = CharField(default='') url_hash = CharField() tags = CharField() + starred = BooleanField(default=False) - # Website favicon - http://codingclues.eu/2009/retrieve-the-favicon-for-any-url-thanks-to-google/ + # Website (domain) favicon favicon = CharField(null=True) # Status code: 200 is OK, 404 is not found, for example (showing an error) @@ -98,7 +99,10 @@ class Bookmark(db.Model): print result.status_code if result.status_code == 200: html = bs4.BeautifulSoup(result.text, 'html.parser') - self.title = html.title.text.strip() + try: + self.title = html.title.text.strip() + except AttributeError: + self.title = '' else: self.http_status = result.status_code return self.title @@ -113,9 +117,11 @@ class Bookmark(db.Model): def set_favicon(self): """ Fetch favicon for the domain """ + # http://codingclues.eu/2009/retrieve-the-favicon-for-any-url-thanks-to-google/ u = urlparse(self.url) domain = u.netloc filename = os.path.join(MEDIA_ROOT, 'favicons/' + domain + '.png') + # if file exists, don't re-download it response = requests.get('http://www.google.com/s2/favicons?domain=' + domain, stream=True) with open(filename, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) @@ -206,8 +212,15 @@ def addingbookmark(userkey): title = request.form['title'] url = request.form['url'] tags = request.form['tags'] + if 'starred' in request.form: + starred = True + try: + request.form['starred'] + except: + starred = False + print starred if url: - bookmark = Bookmark(url=url, title=title, tags=tags, userkey=userkey) + bookmark = Bookmark(url=url, title=title, tags=tags, starred=starred, userkey=userkey) bookmark.set_hash() #bookmark.fetch_image() if not title: diff --git a/templates/bookmarks.html b/templates/bookmarks.html index a6510a6..44b5fa9 100644 --- a/templates/bookmarks.html +++ b/templates/bookmarks.html @@ -24,6 +24,9 @@ {% if bookmark.favicon %}     {% endif %} + {% if bookmark.starred == True %} + star + {% endif %} {% if bookmark.title %} {{ bookmark.title }} {% else %} diff --git a/templates/edit.html b/templates/edit.html index 43b9259..0f6623b 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -17,7 +17,7 @@ {% endif %} -
+
description @@ -33,26 +33,31 @@
label - +
{#star#} - +
+
+ + +
+

{% if bookmark.url_hash %} -
+

+
- {% endif %}
{% endblock %}