-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlers.py
88 lines (66 loc) · 2.2 KB
/
controlers.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""
This is controler for web application
"""
#import sys
import bottle
from models import Message
from models import User
import cgi
import re
@bottle.get("/login")
def include_header():
return bottle.template("login.html", dict(username="", passwd=""))
@bottle.post("/newpost")
def press_login():
username = bottle.request.forms.get("username")
passwd = bottle.request.forms.get("password")
print dict(username=username, subject="", body="", tags="")
user = User()
if user.is_user(username, passwd):
return bottle.template("addpost.html", dict(username=username, subject="",
body = "", tags=""))
@bottle.post("/tohome")
def go_home_page():
username = bottle.request.forms.get("username")
title = bottle.request.forms.get("title")
tags = bottle.request.forms.get("tags")
tags = cgi.escape(tags)
tags_array = extract_tags(tags)
new_post = Message()
new_post.add_new_message(message=title, user=username, tags=tags_array)
return bottle.redirect("/")
@bottle.route("/")
def run_index_page():
"""
Return index page on bottle freamework
"""
some_post = Message()
new_dict = some_post.get_message_by_key()
return bottle.template("index.html", {"message_list": new_dict})
@bottle.route("/post")
@bottle.route("/post/<tag>")
def view_post(tag=[]):
some_post = Message()
new_dict = some_post.get_message_by_key(tags=tag)
return bottle.template("posts.html", {"message_list":new_dict})
@bottle.route("/userlist")
def view_users():
"""
"""
user = User()
return bottle.template("users.html", {"description": user.get_description(),
"users":user.get_list_all_users()})
def extract_tags(tags):
whitespace = re.compile('\s')
nowhite = whitespace.sub("",tags)
tags_array = nowhite.split(',')
# let's clean it up
cleaned = []
for tag in tags_array:
if tag not in cleaned and tag != "":
cleaned.append(tag)
return cleaned
#sessions = sessionDAO.SessionDAO(database)
bottle.debug(True)
bottle.run(host="localhost", port="8081")