Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added new post page
  • Loading branch information
swies committed Oct 21, 2011
1 parent d470024 commit 4d1517b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app.py
Expand Up @@ -49,6 +49,8 @@ def get(self):

(r'/post/([0-9]+)', post.PostHandler),
(r'/post/([0-9]+)/check', post.CheckHandler),

(r'/newpost', post.NewPost),
],
static_url_prefix = '/static/',
static_path = util.path('static'),
Expand Down
37 changes: 36 additions & 1 deletion post.py
Expand Up @@ -24,8 +24,9 @@
'''

import auth
import re
import hashlib
import json
import re
import tornado.web
import util

Expand Down Expand Up @@ -69,6 +70,40 @@ def post(self, id):
'last_comment=NOW() where id=%s', id)
self.redirect(self.request.path)


class NewPost(auth.SecuredHandler):
def get(self):
self.render('newpost.html', errors=[], title='', url='', tags='', description='')

def post(self):
errors = []
url = self.get_argument('url', '')
if not url:
errors.append("You've got to enter a url")
title = self.get_argument('title', '')
if not title:
errors.append("Every post needs a title")
tags = self.get_argument('tags', '')
description = self.get_argument('description', '')

if errors:
return self.render('newpost.html', errors=errors, title=title, url=url, tags=tags, description=description)

linkhash = hashlib.md5(url).hexdigest()
split_tags = []
if tags.strip():
split_tags = tags.split(' ')
self.db.execute('insert into posts (linkhash, author, title, ' +
'link, summary, tags, posted_at) values ' +
'(%s, %s, %s, %s, %s, %s, NOW())',
linkhash,
self.current_user.lower(),
title,
url,
description,
json.dumps(split_tags))
self.redirect('/')

class CheckHandler(auth.SecuredHandler):
def post(self, id):
'''add a check'''
Expand Down
10 changes: 6 additions & 4 deletions templates/base.html
Expand Up @@ -29,7 +29,7 @@
font-size: 120%;
text-decoration: none;
}
div.signinout {
div.inheader {
float: right;
font-size: 90%;
}
Expand Down Expand Up @@ -84,11 +84,13 @@
</head>
<body>
<div id="main">
<div class="inheader">
{% if not current_user %}
<div class="signinout">
<a href="/signin">sign in</a>
</div>
<a href="/signin">sign in</a>
{% else %}
<a href="/newpost">new post</a>
{% end %}
</div>
<h2 class="sitename">
<a href="/">FunFriends.org</a>
</h2>
Expand Down
27 changes: 27 additions & 0 deletions templates/newpost.html
@@ -0,0 +1,27 @@
{% extends "base.html" %}

{% block body %}
<style type="text/css">
label { display: block; margin-top: 1em; }
.error { color: red; }
</style>
<h2>New Post</h2>
{% if errors %}
<ul>
{% for e in errors %}
<li class="error">{{ e }}</li>
{% end %}
</ul>
{% end %}
<form method="post">
<label for="url">url:</label>
<input required type="url" style="width: 100%;" id="url" name="url" value="{{ url }}"> <br>
<label for="title">title:</label>
<input required style="width: 100%;" id="title" name="title" value="{{ title }}"> <br>
<label for="tags">tags (optional, space separated):</label>
<input style="width: 100%;" id="tags" name="tags" value="{{ tags }}"> <br>
<label for="description">description (optional):</label>
<textarea style="width: 100%; height: 100px;" id="description" name="description">{{ description }}</textarea> <br>
<input type="submit" value="Post it!">
</form>
{% end %}

0 comments on commit 4d1517b

Please sign in to comment.