mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 00:15: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='')
|
#image = CharField(default='')
|
||||||
url_hash = CharField()
|
url_hash = CharField()
|
||||||
tags = 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)
|
favicon = CharField(null=True)
|
||||||
|
|
||||||
# Status code: 200 is OK, 404 is not found, for example (showing an error)
|
# 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
|
print result.status_code
|
||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
html = bs4.BeautifulSoup(result.text, 'html.parser')
|
html = bs4.BeautifulSoup(result.text, 'html.parser')
|
||||||
|
try:
|
||||||
self.title = html.title.text.strip()
|
self.title = html.title.text.strip()
|
||||||
|
except AttributeError:
|
||||||
|
self.title = ''
|
||||||
else:
|
else:
|
||||||
self.http_status = result.status_code
|
self.http_status = result.status_code
|
||||||
return self.title
|
return self.title
|
||||||
@@ -113,9 +117,11 @@ class Bookmark(db.Model):
|
|||||||
|
|
||||||
def set_favicon(self):
|
def set_favicon(self):
|
||||||
""" Fetch favicon for the domain """
|
""" Fetch favicon for the domain """
|
||||||
|
# http://codingclues.eu/2009/retrieve-the-favicon-for-any-url-thanks-to-google/
|
||||||
u = urlparse(self.url)
|
u = urlparse(self.url)
|
||||||
domain = u.netloc
|
domain = u.netloc
|
||||||
filename = os.path.join(MEDIA_ROOT, 'favicons/' + domain + '.png')
|
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)
|
response = requests.get('http://www.google.com/s2/favicons?domain=' + domain, stream=True)
|
||||||
with open(filename, 'wb') as out_file:
|
with open(filename, 'wb') as out_file:
|
||||||
shutil.copyfileobj(response.raw, out_file)
|
shutil.copyfileobj(response.raw, out_file)
|
||||||
@@ -206,8 +212,15 @@ def addingbookmark(userkey):
|
|||||||
title = request.form['title']
|
title = request.form['title']
|
||||||
url = request.form['url']
|
url = request.form['url']
|
||||||
tags = request.form['tags']
|
tags = request.form['tags']
|
||||||
|
if 'starred' in request.form:
|
||||||
|
starred = True
|
||||||
|
try:
|
||||||
|
request.form['starred']
|
||||||
|
except:
|
||||||
|
starred = False
|
||||||
|
print starred
|
||||||
if url:
|
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.set_hash()
|
||||||
#bookmark.fetch_image()
|
#bookmark.fetch_image()
|
||||||
if not title:
|
if not title:
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
{% if bookmark.favicon %}
|
{% if bookmark.favicon %}
|
||||||
<img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" />
|
<img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if bookmark.starred == True %}
|
||||||
|
<i class="material-icons">star</i>
|
||||||
|
{% endif %}
|
||||||
{% if bookmark.title %}
|
{% if bookmark.title %}
|
||||||
{{ bookmark.title }}
|
{{ bookmark.title }}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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">
|
<div class="input-field col s12">
|
||||||
<i class="material-icons prefix">description</i>
|
<i class="material-icons prefix">description</i>
|
||||||
@@ -33,26 +33,31 @@
|
|||||||
|
|
||||||
<div class="input-field col s12">
|
<div class="input-field col s12">
|
||||||
<i class="material-icons prefix">label</i>
|
<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>
|
<label for="tags">Tags</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input-field col s12">
|
<div class="input-field col s12">
|
||||||
{#<i class="material-icons prefix">star</i>#}
|
{#<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>
|
<label for="starred">Starred</label>
|
||||||
</div>
|
</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">
|
<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>
|
<p class="left-align"><button class="btn btn-large waves-effect waves-light" type="submit" name="submit">Save</button></p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% if bookmark.url_hash %}
|
{% 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">
|
<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>
|
<p class="left-align"><button class="btn btn-large waves-effect waves-light" type="button" name="delete">Delete</button></p>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user