From 3277ebdffec38bb331c4d85b9e134a57f3ec9bc0 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Sun, 17 Feb 2013 19:39:37 +0100 Subject: [PATCH] In the process of adding the list of current active hashtags on web page Creating a table in javascript is not a good way, as it is not rendered correctly in the browser. Better format it server side or find a way to populate it correctly client side. Also has to create a remove_hashtag method that takes arguments in input --- twiderboard/flask_app.py | 27 ++++++++++++++++++++++++ twiderboard/templates/trendy.html | 29 +++++++++++++++++++++++++- twiderboard/templates/trendy_tmpl.html | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 twiderboard/templates/trendy_tmpl.html diff --git a/twiderboard/flask_app.py b/twiderboard/flask_app.py index 3745959..eb9b09d 100644 --- a/twiderboard/flask_app.py +++ b/twiderboard/flask_app.py @@ -3,6 +3,8 @@ from flask import Flask, jsonify, render_template, request from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import func +from sqlalchemy import desc + import data from datamodel import TrendyHashtag @@ -17,6 +19,7 @@ h = HashtagLogger(data.engine_url, oauth=data.oauth) h.start() +## Utilities def connect(): """ Separated so that the method can be run in each created thread. @@ -31,6 +34,28 @@ def connect(): return Session(), engine # Bridges class to db +## Ajax queries +@app.route('/trendy') +def trendy(): + + session, engine = connect() + + # requests active hashtags + h_query = session.query(TrendyHashtag).filter(TrendyHashtag.active == True).order_by(desc(TrendyHashtag.created)) + hashtags = h_query.all() + + trendy = [] + for h in hashtags: + trendy.append([h.hashtag, 1]) + + session.close() + engine.dispose() + + trendy = [[1, 2], [3, 4], [5, 6]] + #trendy = 'plop' + return jsonify(trendy=trendy) + + @app.route('/nb_trendy') def nb_trendy(): @@ -73,6 +98,7 @@ def stop(): return "Session closed" +## Static part @app.route('/') def index(): return render_template('index.html') @@ -87,5 +113,6 @@ def statistics(): def about(): return render_template('about.html') + if __name__ == '__main__': app.run(debug=True) diff --git a/twiderboard/templates/trendy.html b/twiderboard/templates/trendy.html index 61710ba..b9cd5af 100644 --- a/twiderboard/templates/trendy.html +++ b/twiderboard/templates/trendy.html @@ -1 +1,28 @@ -I'm trendy! \ No newline at end of file + + \ No newline at end of file diff --git a/twiderboard/templates/trendy_tmpl.html b/twiderboard/templates/trendy_tmpl.html new file mode 100644 index 0000000..cbef19a --- /dev/null +++ b/twiderboard/templates/trendy_tmpl.html @@ -0,0 +1 @@ +trendy_tmpl \ No newline at end of file