Skip to content

Commit

Permalink
more configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Cong Ling committed Sep 15, 2012
1 parent 9781b3a commit b11426f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
init.sql
blog.cfg
.ropeproject
37 changes: 24 additions & 13 deletions blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def db(self):
def write_error(self, status_code, **kwargs):
if status_code == 400:
error = "400: Bad Request"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)
if status_code == 405:
error = "405: Method Not Allowed"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)
if status_code == 404:
error = "404: Page Not Found"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)

def get_current_user(self):
return self.get_secure_cookie('user')
Expand All @@ -76,7 +76,9 @@ def get(self):
page = p.page(1)
isAdmin = self.isAdmin()
label_list = Label.group(self.db)
self.render('index.html', articles=page.object_list, label_list=label_list, isAdmin=isAdmin, page=page)
self.render('index.html', articles=page.object_list, label_list=label_list,
isAdmin=isAdmin, page=page, home_title=options.home_title,
user=options.user, photo=options.photo)


class ArticleListHandler(BaseHandler):
Expand All @@ -85,21 +87,24 @@ def get(self, pageId):
page = p.page(int(pageId))
isAdmin = self.isAdmin()
label_list = Label.group(self.db)
self.render('index.html', articles=page.object_list, label_list=label_list, isAdmin=isAdmin, page=page)
self.render('index.html', articles=page.object_list, label_list=label_list,
isAdmin=isAdmin, page=page, home_title=options.home_title,
user=options.user, photo=options.photo)


class ArticleHandler(BaseHandler):
def get(self, id):
article = Article.get(self.db, id)
if article is None:
error = '404: Page Not Found'
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)
else:
isAdmin = self.isAdmin()
label_list = Label.group(self.db)
blog_hostname = options.blog_hostname
self.render('article.html', article=article, label_list=label_list,
blog_hostname=blog_hostname, isAdmin=isAdmin)
blog_hostname=blog_hostname, isAdmin=isAdmin, home_title=options.home_title,
user=options.user, photo=options.photo)


class PreviewHandler(BaseHandler):
Expand All @@ -121,7 +126,8 @@ def post(self):
data['labels'] = self.get_argument('labels')
data['content'] = content_md

self.render('preview.html', article=article, data=data)
self.render('preview.html', article=article, data=data,
user=options.user, photo=options.photo)


class EditArticleHandler(BaseHandler):
Expand All @@ -130,7 +136,7 @@ def get(self, id):
article = Article.get(self.db, id)
if article is None:
error = '404: Page Not Found'
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)
else:
labels = ' '.join(map(lambda item: '[' + item['detail'] + ']', article['labels']))
self.render('editArticle.html', article=article, labels=labels)
Expand All @@ -155,7 +161,7 @@ def post(self, id):
self.redirect('/article/' + id, permanent=True)
except:
error = "The post data invalid"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)


class CreateArticleHandler(BaseHandler):
Expand All @@ -180,7 +186,7 @@ def post(self):
self.redirect('/', permanent=True)
except:
error = "The post data invalid"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)


class SearchHandler(BaseHandler):
Expand All @@ -196,7 +202,9 @@ def get(self):
isAdmin = self.isAdmin()
label_list = Label.group(self.db)

self.render('search.html', articles=page.object_list, label_list=label_list, isAdmin=isAdmin, page=page)
self.render('search.html', articles=page.object_list, label_list=label_list,
isAdmin=isAdmin, page=page, home_title=options.home_title,
user=options.user, photo=options.photo)


class LoginHandler(BaseHandler):
Expand Down Expand Up @@ -227,7 +235,7 @@ def post(self):
self.redirect('/login', permanent=True)
except:
error = "The user not exists"
self.render('error.html', error=error)
self.render('error.html', error=error, home_title=options.home_title)

def validate(self, username):
regex = re.compile(r'^[\w\d]+$')
Expand All @@ -246,6 +254,9 @@ def main():
define("mysql_user", default=mysql['user'])
define("mysql_password", default=mysql['password'])
define("blog_hostname", default=blog['hostname'])
define("user", default=blog['user'])
define("home_title", default=blog['home_title'])
define("photo", default=blog['photo'])

http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
Expand Down
13 changes: 13 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,23 @@

hostname = raw_input('请输入博客域名: ')
port = raw_input('请输入程序监听的端口号: ')
user = raw_input('请输入博主的名字(默认: Adonis Ling): ')
home_title = raw_input("请输入主页的标题(默认: Adonis's Blog ): ")
photo = raw_input('请输入博主头像的文件名(默认: talent.jpg)')

if len(user) == 0:
user = 'Adonis Ling'
if len(home_title) == 0:
home_title = "Adonis's Blog"
if len(photo) == 0:
photo = 'talent.jpg'

config.add_section('blog')
config.set('blog', 'hostname', hostname)
config.set('blog', 'port', port)
config.set('blog', 'user', user)
config.set('blog', 'home_title', home_title)
config.set('blog', 'photo', photo)

with open('blog.cfg', 'w') as cfg:
config.write(cfg)
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html xmlns:wb="http://open.weibo.com/wb">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="icon" href="/static/img/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="/static/css/pygments.css" />
Expand Down
2 changes: 1 addition & 1 deletion templates/editArticle.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}

{% block title %}
Post an Article
Edit an Article
{% end %}

{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion templates/error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block title %}
Adonis's Blog
{{ home_title }}
{% end %}

{% block content %}
Expand Down
6 changes: 3 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% extends "base.html" %}

{% block title %}
Adonis's Blog
{{ home_title }}
{% end %}

{% block content %}
<div id="main-board">
<div id="side-bar">
<div id="info">
<div id="photo"><img src="/static/img/talent.jpg" alt="Adonis Ling" /></div>
<div id="name">Adonis Ling</div>
<div id="photo"><img src="/static/img/{{ photo }}" alt="{{ user }}" /></div>
<div id="name">{{ user }}</div>
{% if isAdmin %}
<div id="logout"><a href="/logout">登出</a></div>
{% end %}
Expand Down
4 changes: 2 additions & 2 deletions templates/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div id="main-board">
<div id="side-bar">
<div id="info">
<div id="photo"><img src="/static/img/talent.jpg" alt="Adonis Ling" /></div>
<div id="name">Adonis Ling</div>
<div id="photo"><img src="/static/img/{{ photo }}" alt="{{ user }}" /></div>
<div id="name">{{ user }}</div>
</div>
</div>
<div id="content">
Expand Down
2 changes: 1 addition & 1 deletion templates/search.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "index.html" %}

{% block title %}
Adonis's Blog
{{ home_title }}
{% end %}

{% block articles %}
Expand Down

0 comments on commit b11426f

Please sign in to comment.