Creando un foro de la manera fácil (32 líneas)
Aquí están algunos de los features que quiero:
Login via twitter / Facebook / Google / OpenID
Número ilimitado de threads
Soporte de like / dislike en threads y en posts
Avatares
HTML en los posts
Que mande mail al usuario si le responden
Feeds RSS para los threads
Se lo puede ver en acción en http://foro.netmanagers.com.ar (por un tiempo limitado ;-)
Y aquí está el código:
import bottle import disqusapi as disqus import json shortname = 'magicmisteryforum' api = disqus.DisqusAPI(open("key").read().strip()) @bottle.route('/', method='GET') def index(): msg = bottle.request.GET.get('msg', '') threads = api.forums.listThreads(forum=shortname, limit=100) print threads[0] return bottle.template('main.tpl', threads=threads, shortname=shortname, msg=msg) @bottle.route('/new', method='POST') def new(): title = bottle.request.forms.get('title', None) if not title: bottle.redirect('/?msg=Missing%20Thread%20Name') return thread = api.threads.create(forum=shortname, title = title) thread_id = thread.__dict__['response']['id'] # Redirecting to /thread/thread_id doesn't work # because threads take a few seconds to appear on the listing bottle.redirect('/') @bottle.route('/thread/:id') def thread(id): t = api.threads.details(thread=id) return bottle.template('thread.tpl', shortname=shortname, id=id, thread=t.__dict__['response']) @bottle.route('/static/:path#.+#') def server_static(path): return bottle.static_file(path, root='./static') app = bottle.app() app.catchall = False #Now most exceptions are re-raised within bottle. bottle.run(host='184.82.108.14', port=80, app=app)
Requiere Bottle y la Disqus python API
Por supuesto que hay un poquito de templates, acá está main.tpl y thread.tpl. Como apesto para el HTML, usa Bluetrip CSS y es sencillo de customizar.
POR SUPUESTO QUE HAGO TRAMPA!
Esta cosa es apenas una capa de pintura encima de Disqus! Más un blog sin posts pero con comentarios que un foro! Pero... qué le falta para ser un foro de verdad? Funciona, no? Hasta se podrían usar categorías de Disqus para crear subforos...
Teniendo todo en cuenta, creo que es un hack bonito.
Y si esperás unos días, esto lleva a otra cosa que es mucho más mágica...
Código fuente completo en http://magicforum.googlecode.com
Genialidad en acción
Awesome to see someone using the new API bindings! Would love to hear any feedback or criticism you have about the new API and the bindings.
Well, my main problem is that I can't find a way to create a thread and then show it. It seems there is a long delay between api.threads.create and the moment when you can use posts.create on it, or when it appears on api.threads.list
Other than that, it has been lots of fun :-)
There shouldn't be any delay for creating a post, though there might be a small delay before it appears in the threads/list method. Is there something that would help ease that process (assuming the delay still exists).
When I try to do this:
I get this error:
Ah you're right, I see the code now. Will be making a change so at least for now all creation (POST) requests shouldn't have to deal w/ this delay.
We're aware the delay sucks, do plan to solve the delay eventually (hopefully soon).
No big problem, the user would just have to wait and post later. If this had any users, of course.
Well done. Can't wait to see where this goes.
Yes, bottle is nice for this kind of things. One of the first things I did a few months ago, after switching job, was a 100LOC(?) kind-of-management of dashboard using bootle and Google Charts. It was really low effort, high reward (everybody loves it) exercise.
My only complaint is that there is no syntax support for Disqus, so if I want to paste some code, it goes AWOL. Oh well, maybe you could utilize the pastebin API?
Is it really working?
Sure, http://foro.netmanagers.com.ar
I'll post the same information to my blog, thanks for
ideas and great article.
Well, the write-up is truly the freshest on this laudable topic.