mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
PublicTag: public page with read-only bookmarks with this tag
This commit is contained in:
23
digimarks.py
23
digimarks.py
@@ -167,6 +167,17 @@ class Bookmark(db.Model):
|
||||
return result
|
||||
|
||||
|
||||
class PublicTag(db.Model):
|
||||
""" Publicly shared tag """
|
||||
tagkey = CharField()
|
||||
userkey = CharField()
|
||||
tag = CharField()
|
||||
|
||||
def generate_key(self):
|
||||
""" Generate hash-based key for publicly shared tag """
|
||||
self.tagkey = os.urandom(16).encode('hex')
|
||||
|
||||
|
||||
def get_tags_for_user(userkey):
|
||||
""" Extract all tags from the bookmarks """
|
||||
bookmarks = Bookmark.select().filter(Bookmark.userkey == userkey)
|
||||
@@ -330,6 +341,15 @@ def tag(userkey, tag):
|
||||
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, action=pageheader)
|
||||
|
||||
|
||||
@app.route('/pub/<tagkey>')
|
||||
def publictag(tagkey):
|
||||
""" Read-only overview of the bookmarks in the userkey/tag of this PublicTag """
|
||||
this_tag = get_object_or_404(PublicTag.get(PublicTag.tagkey == tagkey))
|
||||
print this_tag
|
||||
bookmarks = Bookmark.select().where(Bookmark.userkey == this_tag.userkey, tags.contains(this_tag.tag))
|
||||
return render_template('publicbookmarks.html', bookmarks=bookmarks, tag=tag)
|
||||
|
||||
|
||||
@app.route('/<systemkey>/adduser')
|
||||
def adduser(systemkey):
|
||||
""" Add user endpoint, convenience """
|
||||
@@ -346,9 +366,10 @@ def adduser(systemkey):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# create the bookmark table if it does not exist
|
||||
# create the bookmark, user and public tag tables if they do not exist
|
||||
Bookmark.create_table(True)
|
||||
User.create_table(True)
|
||||
PublicTag.create_table(True)
|
||||
|
||||
users = User.select()
|
||||
print 'Current user keys:'
|
||||
|
||||
56
templates/publicbookmarks.html
Normal file
56
templates/publicbookmarks.html
Normal file
@@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
{% if not action %}
|
||||
{% set action = 'Bookmarks' %}
|
||||
{% endif %}
|
||||
{% block title %}{{ action }}{% endblock %}
|
||||
{% block pageheader %}{{ action }}{% endblock %}
|
||||
{% block pagecontent %}
|
||||
|
||||
{% if message %}
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card-panel orange lighten-2">
|
||||
<span class="white-text">
|
||||
{{ message }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
{% for bookmark in bookmarks %}
|
||||
<div class="col s12 m6 l4">
|
||||
<div class="card green darken-3">
|
||||
<div class="card-content white-text">
|
||||
<span class="card-title activator"><i class="material-icons right">more_vert</i></span>
|
||||
{% if bookmark.http_status != 200 %}
|
||||
<i class="material-icons" title="HTTP status {{ bookmark.http_status }}">report_problem</i>
|
||||
{% endif %}
|
||||
{% if bookmark.favicon %}
|
||||
<img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" />
|
||||
{% endif %}
|
||||
<p><a href="{{ bookmark.url }}" title="{{ bookmark.url }}" rel="noreferrer">
|
||||
{% if bookmark.starred == True %}
|
||||
<i class="material-icons">star</i>
|
||||
{% endif %}
|
||||
{% if bookmark.title %}
|
||||
{{ bookmark.title }}
|
||||
{% else %}
|
||||
[ no title ]
|
||||
{% endif %}
|
||||
</a></p>
|
||||
</div>
|
||||
<div class="card-reveal green darken-3">
|
||||
<span class="card-title white-text">Added @ {{ bookmark.created_date.strftime('%Y-%m-%d %H:%M') }}<i class="material-icons right">close</i></span>
|
||||
<div class="white-text">
|
||||
{% if bookmark.favicon %}
|
||||
<img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" />
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user