For the past several days, I have looked into starting to turn my website towards realtime. I looked at Gevent (can't use b/c I'm using Python 3.3), Tornado, and Webalchemy.
Webalchemy and Tornado are both options. At this time, I have not successfully meshed their code with mine..that is, I have not been able to get a realtime result. I have set a modest goal for myself: getting the upvote/downvote ticker to display in realtime.
This is my upvote function:
@mod.route('/updebate/<int:entries_did>')
def up_vote(entries_did):
connection = g.db.session.connection()
g.db.engine.execute(
'update users_user set rating = rating + 1 where id in (select id from users_debates where users_debates.did ="{0}")'.format(entries_did))
g.db.engine.execute(
'update users_debates set rating = rating + 1 where did = "{0}"'.format(entries_did))
# g.db.commit()
return redirect(request.referrer)
As you can see, right now I'm simply "request.referrer"-ing..definitely not what I want to do.
Here is the code from my HTML page:
{% for entry in entries %}
<li><h2>
<a href="/updebate/{{ entry.did }}" style="text-decoration:none; color:orange;">⬆</a>{{ entry.rating }}<a href="/downdebate/{{ entry.did }}" style="text-decoration:none; color:orange;">⬇</a><a href="/debate/{{ entry.did }}">{{ entry.title }}</a></h2>{{ entry.text|safe }}
CREATED BY: {{ entry.name }}
{% else %}
<li><em>Unbelievable. No entries here so far</em>
{% endfor %}
Thoughts?