diff --git a/microblog.db b/microblog.db new file mode 100644 index 0000000..5b83236 Binary files /dev/null and b/microblog.db differ diff --git a/microblog.py b/microblog.py index f5f7f79..a4e2f74 100644 --- a/microblog.py +++ b/microblog.py @@ -50,8 +50,14 @@ def write_entry(title, text): def get_all_entries(): con = get_database_connection() - cur = con.execute('SELECT title, text FROM entries ORDER BY id DESC') - return [dict(title=row[0], text=row[1]) for row in cur.fetchall()] + cur = con.execute('SELECT id, title, text FROM entries ORDER BY id DESC') + return [dict(id=row[0], title=row[1], text=row[2]) for row in cur.fetchall()] + + +def get_one_entry(entry_id): + con = get_database_connection() + cur = con.execute('SELECT title, text FROM entries where id = ?', entry_id ) + return cur.fetchone() def do_login(usr, pwd): @@ -103,5 +109,13 @@ def add_entry(): return redirect(url_for('show_entries')) +@app.route('/permalink/') +def permalink(entry_id): + entry = get_one_entry(entry_id) + if entry: + return render_template('permalink.html', title=entry[0], text=entry[1]) + else: + abort(404) + if __name__ == '__main__': app.run(debug=True) diff --git a/templates/permalink.html b/templates/permalink.html new file mode 100644 index 0000000..e79b146 --- /dev/null +++ b/templates/permalink.html @@ -0,0 +1,10 @@ +{% extends "layout.html" %} +{% block body %} + {% if session.logged_in %} +

{{ title }}

+

{{ text }}

+ {% else %} +

You must be logged in to see a permalink (although I'm not sure why).

+ {% endif %} + Home +{% endblock %} diff --git a/templates/show_entries.html b/templates/show_entries.html index f44fd92..79b8388 100644 --- a/templates/show_entries.html +++ b/templates/show_entries.html @@ -8,7 +8,7 @@
- +
@@ -19,7 +19,7 @@

Posts

-{% endblock %} \ No newline at end of file +{% endblock %}