Commit 9eda3049a5bee5293fa0143dfd5b80dce3f3d4cf

  • avatar
  • arvind
  • Tue Jan 08 16:28:24 IST 2013
Making correct use of bootstrap
			 - Changed the delete button from image to a icon.
			 - Changed the url for glyphicons in bootstrap.css
  • Diff rendering mode:
  • inline
  • side by side

flaskr.py

1# -*- coding: utf-8 -*-
2"""
3 swtr
4 ~~~~~~
5
6 http://swtr.us
7
8 :license: BSD, see LICENSE for more details.
9"""
10from __future__ import with_statement
11from pymongo import Connection
12from bson.objectid import ObjectId
13from bson.errors import InvalidId
14from flask import Flask, request, session, g, redirect, url_for, abort, \
15 render_template, flash, _app_ctx_stack
16
17# configuration
18DATABASE = 'alipiBlog'
19COLLECTION_NAME = 'posts'
20DEBUG = True
21SECRET_KEY = 'development key'
22USERNAME = 'admin'
23PASSWORD = 'default'
24DB_PORT = 27017
25DB_HOST = 'localhost'
26
27# create our little application :)
28app = Flask(__name__)
29app.config.from_object(__name__)
30app.config.from_envvar('FLASKR_SETTINGS', silent=True)
31
32
33@app.before_request
34def init_db():
35 g.connection = Connection(app.config['DB_HOST'], app.config['DB_PORT'])
36 db = g.connection[app.config['DATABASE']]
37 g.collection = db[app.config["COLLECTION_NAME"]]
38
39
40@app.teardown_request
41def close_db(exception):
42 g.connection.disconnect()
43
44
45@app.errorhandler(400)
46def page_not_found(e):
47 return render_template('404.html'), 404
48
49
50@app.route('/')
51def show_entries():
52 res = g.collection.find().sort('_id',direction=-1)
53 entries = make_list(res)
54 return render_template('show_entries.html', entries=entries)
55
56
57@app.route('/add', methods=['POST'])
58def add_entry():
59 if not session.get('logged_in'):
60 abort(401)
61 g.collection.insert({'title':request.form['title'], 'text':request.form['text']})
62 flash('New entry was successfully posted')
63 return redirect(url_for('show_entries'))
64
65
66@app.route('/login', methods=['GET', 'POST'])
67def login():
68 error = None
69 if request.method == 'POST':
70 if request.form['username'] != app.config['USERNAME']:
71 error = 'Invalid username'
72 elif request.form['password'] != app.config['PASSWORD']:
73 error = 'Invalid password'
74 else:
75 session['logged_in'] = True
76 flash('You were logged in')
77 return redirect(url_for('show_entries'))
78 return render_template('login.html', error=error)
79
80
81@app.route('/posts/<post_id>',methods=['GET'])
82def show_specific_entry(post_id):
83 try:
84 res = g.collection.find({'_id':ObjectId(post_id)});
85 if(res.count() > 0):
86 entries = make_list(res)
87 return render_template('show_posts.html', entries=entries)
88 else:
89 abort(400)
90 except InvalidId:
91 abort(400)
92
93
94@app.route('/logout')
95def logout():
96 session.pop('logged_in', None)
97 flash('You were logged out')
98 return redirect(url_for('show_entries'))
99
100def make_list(res):
101 entries = []
102 for row in res:
103 d = dict()
104 d['text'] = row['text']
105 d["title"] = row["title"]
106 entries.append(d)
107 return entries
108
109if __name__ == '__main__':
110 app.run()

static/bootstrap.min.css

220table .span10{float:none;width:764px;margin-left:0;}220table .span10{float:none;width:764px;margin-left:0;}
221table .span11{float:none;width:844px;margin-left:0;}221table .span11{float:none;width:844px;margin-left:0;}
222table .span12{float:none;width:924px;margin-left:0;}222table .span12{float:none;width:924px;margin-left:0;}
223[class^="icon-"],[class*=" icon-"]{display:inline-block;width:14px;height:14px;line-height:14px;vertical-align:text-top;background-image:url("../img/glyphicons-halflings.png");background-position:14px 14px;background-repeat:no-repeat;*margin-right:.3em;}[class^="icon-"]:last-child,[class*=" icon-"]:last-child{*margin-left:0;}
223[class^="icon-"],[class*=" icon-"]{display:inline-block;width:14px;height:14px;line-height:14px;vertical-align:text-top;background-image:url("img/glyphicons-halflings.png");background-position:14px 14px;background-repeat:no-repeat;*margin-right:.3em;}[class^="icon-"]:last-child,[class*=" icon-"]:last-child{*margin-left:0;}
224.icon-white{background-image:url("../img/glyphicons-halflings-white.png");}224.icon-white{background-image:url("../img/glyphicons-halflings-white.png");}
225.icon-glass{background-position:0 0;}225.icon-glass{background-position:0 0;}
226.icon-music{background-position:-24px 0;}226.icon-music{background-position:-24px 0;}

static/img/glyphicons-halflings.png

1PNG
2
3 IHDRtEXtSoftwareAdobe ImageReadyqe<1IDATx}ml\EW^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=entries>13<ul class=entries>
14 {% for entry in entries %}14 {% for entry in entries %}
15 <li><h2>{{ entry.title }}</h2>@<b>{{entry.user}}</b> <a href=""><img style="height:15px;" src="{{ url_for('static', filename='bin.png') }}" onclick=deletePost({{ entry.id|string|tojson|safe }});></img></a>
15 <li><h2>{{ entry.title }}</h2>@<b>{{entry.user}}</b> <a href=""><i class="icon-trash" onclick=deletePost({{ entry.id|string|tojson|safe }});></i></a>
16 <p> {{ entry.text|safe }} </p>16 <p> {{ entry.text|safe }} </p>
17 {% endfor %}17 {% endfor %}
18</ul>18</ul>