Permalink
Browse files

more work on getting an actual app and API

  • Loading branch information...
1 parent ee749bc commit 1964e4c31e607a718d281484bcbfa3b645c89696 @ranman committed Apr 9, 2013
Showing with 37 additions and 4 deletions.
  1. +28 −4 gitstreamer.py
  2. +9 −0 templates/404.html
  3. 0 templates/index.html
  4. 0 templates/user.html
View
@@ -1,29 +1,53 @@
import os
-from flask import Flask, render_template, send_from_directory
+from flask import Flask, render_template, send_from_directory, make_response
from flask.ext.pymongo import PyMongo
app = Flask(__name__)
app.config.update(
DEBUG=True,
+ HOST='0.0.0.0',
+ PORT=8080,
+ MONGO_DBNAME='gitstreamer',
+ MONGO_HOST='localhost',
+ MONGO_PORT=27017,
+ MONGO_USERNAME='gitstreamer',
+ MONGO_PASSWORD='gitstreamer'
)
mongo = PyMongo(app)
@app.route('/favicon.ico')
def favicon():
return send_from_directory(
- os.path.join(app.root_path, 'static'),
- 'ico/favicon.ico')
+ os.path.join(app.root_path, 'static'), 'ico/favicon.ico')
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
+@app.route('/img/<ObjectId:gitshot_id>')
+def render_image(gitshot_id):
+ img = mongo.db.gitshots.find_one_or_404(gitshot_id, {'img': True})['img']
+
+ def wsgi_app(environ, start_response):
+ start_response('200 OK', [('Content-type', 'image/jpeg')])
+ return img
+
+ return make_response(wsgi_app)
+
+
+@app.route('/user/<username>')
+def user_profile(username):
+ gitshots = mongo.db.users.find({'author': username}, {'img': False})
+ return render_template('user.html', gitshots=gitshots)
+
+
@app.route('/')
def index():
- return render_template('index.html')
+ gitshots = mongo.db.gitshots.find({}, {'img': False})
+ return render_template('index.html', gitshots=gitshots)
if __name__ == "__main__":
app.run()
View
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<title>What! I can't find that file</title>
+</head>
+<body>
+I can't find that file.
+</body>
+</html>
View
No changes.
View
No changes.

0 comments on commit 1964e4c

Please sign in to comment.