From 0b6c9d3ad08dc22ce503ef549276f8d045f378f9 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Sat, 23 Jul 2016 16:01:49 +0200 Subject: [PATCH] Create public tag page, better retrieval of PublicTag page --- digimarks.py | 43 +++++++++++++++++++++++++++++++++++----- templates/bookmarks.html | 16 +++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/digimarks.py b/digimarks.py index 46faec6..aca1064 100644 --- a/digimarks.py +++ b/digimarks.py @@ -12,6 +12,7 @@ from utilkit import datetimeutil from flask import Flask, abort, redirect, render_template, request, url_for from flask_peewee.db import Database +#from flask_peewee.utils import get_object_or_404 from peewee import * try: @@ -338,16 +339,48 @@ def tag(userkey, tag): bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.tags.contains(tag)) tags = get_tags_for_user(userkey) pageheader = 'tag: ' + tag - return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, action=pageheader) + message = request.args.get('message') + + try: + publictag = PublicTag.get(PublicTag.userkey == userkey, PublicTag.tag == tag) + except PublicTag.DoesNotExist: + publictag = None + + return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, tag=tag, publictag=publictag, action=pageheader, message=message) @app.route('/pub/') 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) + #this_tag = get_object_or_404(PublicTag.select().where(PublicTag.tagkey == tagkey)) + try: + this_tag = PublicTag.get(PublicTag.tagkey == tagkey) + bookmarks = Bookmark.select().where(Bookmark.userkey == this_tag.userkey, Bookmark.tags.contains(this_tag.tag)) + return render_template('publicbookmarks.html', bookmarks=bookmarks, tag=tag, action=this_tag.tag) + except PublicTag.DoesNotExist: + abort(404) + + +@app.route('///makepublic', methods=['GET', 'POST']) +def addpublictag(userkey, tag): + #user = get_object_or_404(User.get(User.key == userkey)) + user = User.get(User.key == userkey) + try: + publictag = PublicTag.get(PublicTag.userkey == userkey, PublicTag.tag == tag) + except PublicTag.DoesNotExist: + publictag = None + if not publictag: + newpublictag = PublicTag() + newpublictag.generate_key() + newpublictag.userkey = userkey + newpublictag.tag = tag + newpublictag.save() + + message = 'Public link to this tag created' + return redirect(url_for('tag', userkey=userkey, tag=tag, message=message)) + else: + message = 'Public link already existed' + return redirect(url_for('tag', userkey=userkey, tag=tag, message=message)) @app.route('//adduser') diff --git a/templates/bookmarks.html b/templates/bookmarks.html index 78264f1..91357c3 100644 --- a/templates/bookmarks.html +++ b/templates/bookmarks.html @@ -6,6 +6,22 @@ {% block pageheader %}{{ action }}{% endblock %} {% block pagecontent %} +{% if tag and not publictag %} +
+
+
+

+
+
+
+{% endif %} + +{% if tag and publictag %} + +{% endif %} + {% if message %}