mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
'starred' support; catch case where there's no title
This commit is contained in:
17
digimarks.py
17
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')
|
||||
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:
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
{% if bookmark.favicon %}
|
||||
<img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" />
|
||||
{% endif %}
|
||||
{% if bookmark.starred == True %}
|
||||
<i class="material-icons">star</i>
|
||||
{% endif %}
|
||||
{% if bookmark.title %}
|
||||
{{ bookmark.title }}
|
||||
{% else %}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<form class="col s12" action="{{ url_for('addingbookmark', userkey=userkey) }}" method="POST">
|
||||
<form action="{{ url_for('addingbookmark', userkey=userkey) }}" method="POST">
|
||||
|
||||
<div class="input-field col s12">
|
||||
<i class="material-icons prefix">description</i>
|
||||
@@ -33,26 +33,31 @@
|
||||
|
||||
<div class="input-field col s12">
|
||||
<i class="material-icons prefix">label</i>
|
||||
<input placeholder="tags, supported by comma's" type="text" name="tags" id="tags" value="{{ bookmark.tags }}" class="validate" />
|
||||
<input placeholder="tags, divided by comma's" type="text" name="tags" id="tags" value="{{ bookmark.tags }}" class="validate" />
|
||||
<label for="tags">Tags</label>
|
||||
</div>
|
||||
|
||||
<div class="input-field col s12">
|
||||
{#<i class="material-icons prefix">star</i>#}
|
||||
<input type="checkbox" name="starred" id="starred" />
|
||||
<input type="checkbox" name="starred" id="starred" {% if bookmark.starred == True %}checked{% endif %} />
|
||||
<label for="starred">Starred</label>
|
||||
</div>
|
||||
|
||||
<div class="input-field col s12">
|
||||
<input type="checkbox" name="strip" id="strip" />
|
||||
<label for="strip">Strip parameters from url</label>
|
||||
</div>
|
||||
|
||||
<div class="input-field col l2 m3 s4">
|
||||
<p class="left-align"><button class="btn btn-large waves-effect waves-light" type="submit" name="submit">Save</button></p>
|
||||
</div>
|
||||
</form>
|
||||
{% if bookmark.url_hash %}
|
||||
<form class="col s12" action="{{ url_for('deletingbookmark', userkey=userkey, urlhash=bookmark.url_hash) }}" method="POST">
|
||||
<div class="input-field col l2 m3 s4">
|
||||
<form action="{{ url_for('deletingbookmark', userkey=userkey, urlhash=bookmark.url_hash) }}" method="POST">
|
||||
<p class="left-align"><button class="btn btn-large waves-effect waves-light" type="button" name="delete">Delete</button></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user