-
Notifications
You must be signed in to change notification settings - Fork 4
/
blog.py
54 lines (43 loc) · 1.46 KB
/
blog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import web
from web import form
from postscontroller import Posts_Controller
from blogpost import Blog_Post
urls = (
'/', 'index',
'/blog', 'blog',
'/blog/new', 'new_post'
)
render = web.template.render('templates', base='base')
app = web.application(urls, globals())
Posts_Controller = Posts_Controller()
class index: #This will become a landing page eventually
def GET(self):
return render.index(self)
class blog:
def GET(self):
posts = Posts_Controller.get_posts()
postId = web.input(id=None)
if postId.id == None:
return render.blog(posts, None)
elif int(postId.id) >= 0:
return render.blog(posts, int(postId.id))
class new_post:
new_post_form = form.Form(
form.Textbox('title', description='Title: ', size=25),
form.Textarea('content', description='Content: ', rows=30, cols=50),
form.Button('Submit Post')
)
def GET(self):
new_post_form = self.new_post_form()
return render.new_post(new_post_form)
def POST(self):
new_post_form = self.new_post_form()
if not new_post_form.validates():
return render.new_post(new_post_form)
else:
Posts_Controller.add_post(Blog_Post(new_post_form.d.title, new_post_form.d.content))
return render.new_post(None)
if __name__ == '__main__':
app.run()