Permalink
Browse files

Merge branch 'trunk'

  • Loading branch information...
2 parents b678077 + 658a1b2 commit 767c4d0e8e6248c46ffa4daf65f8d081cf93846b David Shieh committed Mar 4, 2010
Showing with 497 additions and 531 deletions.
  1. +12 −0 ChangeLog.txt
  2. +5 −0 TODO.txt
  3. +8 −8 davidblog.py
  4. +10 −27 forms.py
  5. +98 −0 models.py
  6. +7 −10 settings.py
  7. +93 −203 static/css/styles.css
  8. +6 −3 templatefilters.py
  9. +7 −0 templates/_entry.html
  10. +24 −0 templates/_leftbar.html
  11. +8 −36 templates/base.html
  12. +45 −45 templates/entry.html
  13. +17 −26 templates/index.html
  14. +20 −23 templates/tag.html
  15. +2 −0 utils/__init__.py
  16. +22 −0 utils/captcha.py
  17. +44 −0 utils/pagination.py
  18. +69 −150 views.py
View
@@ -0,0 +1,12 @@
+
+### 1.0 这是一个比较大的改动 ###
+ 1. 使用了sqlalchemy这个ORM
+ 2. 去掉了category部分, 现在对文章的分类就只有tags
+ 3. 加入pygments作代码高亮的处理
+ 4. 模板引擎切换到jinja2上
+ 5. 加入一个随机文章的功能
+
+### 0.3 主要是修复bug ###
+ 1. 部分使用了jinja2(即部分页面没有更换引擎, 不能正常显示)
+ 2. 使用markdown作为日志正文的语法
+ 3. 去掉了ajax提交留言的功能
View
@@ -0,0 +1,5 @@
+1. 全部页面都切换到jinja2上(Done)
+2. 加入一个random entries的功能, 放在右侧
+3. 优化程序结构
+4. 加入文章搜索功能
+5. 使用pygments处理代码高亮
View
@@ -3,26 +3,26 @@
import web
import views
-from views import my_loadhook
+from views import my_handler
import admin
urls = (
'/admin', admin.app_admin,
'/', 'views.index',
- '/entry/(.*)/', 'views.entry',
- '/page/(.*)/', 'views.page',
- '/category/(.*)', 'views.category',
- '/tag/(.*)/', 'views.tag',
- '/captcha/', 'views.captcha',
- '/rss.xml', 'views.rss',
+ '^/entry/(.*)/$', 'views.entry',
+ '^/page/(.*)/$', 'views.page',
+ '^/tag/(.*)/$', 'views.tag',
+ '^/captcha/$', 'views.captcha',
+ '^/rss.xml$', 'views.rss',
)
app = web.application(urls, globals(), autoreload = True)
session = web.session.Session(
app, web.session.DiskStore('sessions'),
initializer={'captcha': 0, 'isAdmin':0})
-app.add_processor(web.loadhook(my_loadhook))
+#app.add_processor(web.loadhook(my_loadhook))
+app.add_processor(my_handler)
#app.notfound = notfound
#app.internalerror = internalerror
View
@@ -1,44 +1,27 @@
-#-*-coding=utf-8-*-
-
+#-*-coding=utf-8-*-
import web
from web import form
from settings import db
__all__ = [
- 'loginForm', 'commentForm', 'categoryForm',
- 'linkForm', 'entryForm'
+ 'commentForm', 'linkForm'
]
-usernameValidator = form.regexp(r".{3,15}$", "Username must be 3-15 charactors")
-emailValidator = form.regexp(r".*@.*", 'Please input a valid email address')
-urlValidator = form.regexp(r"http://.*", "Please input a valid url address")
+username_validate = form.regexp(r".{3,15}$", u"请输入3-15位的用户名")
+email_validate = form.regexp(r".*@.*", u"请输入合法的Email地址")
+urlValidator = form.regexp(r"http://.*", u"请输入合法的URL地址")
captchaValidator = form.Validator('Captcha Code',
- lambda x: x == web.config._session.captcha)
-
-def passwordValidator(i):
- user = list(db.query('SELECT * FROM admins WHERE username = $username',
- vars={'username': i.username}))[0]
- return hashlib.md5(i.password).hexdigest() == user.password
-
-loginForm = form.Form(
- form.Textbox('username',
- form.notnull, usernameValidator),
- form.Password('password',
- form.notnull),
- validators = [
- form.Validator('Username/Password wrong!', passwordValidator)
- ]
- )
+ lambda x: x == web.ctx.session.captcha)
commentForm = form.Form(
- form.Textbox('username',
- form.notnull, usernameValidator),
- form.Textbox('email',
- form.notnull, emailValidator),
+ form.Textbox('username', form.notnull, username_validate),
+ form.Textbox('email', form.notnull, email_validate),
form.Textbox('url'),
form.Textbox('captcha', captchaValidator,
description="Captcha Code"),
form.Textarea('comment', form.notnull),
+ form.Textbox('captcha', captchaValidator),
+ form.Button('submit', type="submit", description=u"留言"),
)
categoryForm = form.Form(
View
@@ -0,0 +1,98 @@
+#-*-coding:utf-8-*-
+from datetime import datetime
+from sqlalchemy import create_engine, Table, ForeignKey
+from sqlalchemy import Column, Integer, String, Text, DateTime
+from sqlalchemy.orm import relation, backref
+from sqlalchemy.ext.declarative import declarative_base
+
+engine = create_engine('mysql://root:root@localhost/davidblog_new?charset=utf8')
+
+Base = declarative_base()
+metadata = Base.metadata
+
+entry_tag = Table('entry_tag', metadata,
+ Column('entryId', Integer, ForeignKey('entries.id')),
+ Column('tagId', Integer, ForeignKey('tags.id'))
+ )
+
+class Comment(Base):
+ __tablename__ = 'comments'
+
+ id = Column(Integer, primary_key=True)
+ entryId = Column(Integer, ForeignKey('entries.id'))
+ email = Column(String)
+ username = Column(String)
+ url = Column(String)
+ comment = Column(Text)
+ createdTime = Column(DateTime)
+
+ def __init__(self, entryId, username, email, url, comment):
+ self.entryId = entryId
+ self.username = username
+ self.email = email
+ self.url = url
+ self.comment = comment
+ self.createdTime = datetime.now()
+
+class Entry(Base):
+ __tablename__ = 'entries'
+
+ id = Column(Integer, primary_key=True)
+ title = Column(String)
+ slug = Column(String, unique=True)
+ content = Column(Text)
+ createdTime = Column(DateTime)
+ modifiedTime = Column(DateTime)
+ viewNum = Column(Integer, default=0)
+ commentNum = Column(Integer, default=0)
+
+ tags = relation('Tag', secondary=entry_tag, backref='entries')
+ comments = relation(Comment, order_by=Comment.createdTime,
+ backref="entries"
+ )
+
+ def __init__(self, title, slug, content):
+ self.title = title
+ self.slug = slug
+ self.content = content
+
+ def __repr__(self):
+ return "<Entry ('%s')>" % self.id
+
+class Tag(Base):
+ __tablename__ = 'tags'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(String, unique=True)
+ entryNum = Column(Integer, default=0)
+
+ def __init__(self, name):
+ self.name = name
+
+ def __repr__(self):
+ return "<Tag ('%s')>" % self.name
+
+class Page(Base):
+ __tablename__ = 'pages'
+
+ id = Column(Integer, primary_key=True)
+ title = Column(String)
+ slug = Column(String, unique=True)
+ content = Column(Text)
+ createdTime = Column(DateTime)
+ modifiedTime = Column(DateTime)
+
+ def __init__(self, title):
+ self.title = title
+
+ def __repr__(self):
+ return "<Page ('%s')>" % (self.title,)
+
+class Link(Base):
+ __tablename__ = 'links'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(String)
+ url = Column(String)
+ createdTime = Column(DateTime)
+
View
@@ -4,7 +4,7 @@
import web
import memcache
from web.contrib.template import render_jinja
-from templatefilters import avatar, notnull, formnote
+from templatefilters import avatar, notnull, formnote, content
import os
__all__ = [
@@ -13,28 +13,25 @@
pageCount = 5
#数据库配置
-db = web.database(dbn = 'mysql',
- db = 'davidblog',
- user = 'root',
- pw = 'root',
- charset = 'utf8')
+db = web.database(dbn = 'mysql', db = 'davidblog_new', user='root', pw = 'root')
#memcache配置
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
-#render_mako配置
+#render_jinja配置
def getRender():
render = render_jinja(
os.getcwd() + '/templates',
encoding = 'utf-8',
)
- myFilters = {'avatar':avatar,'notnull':notnull,'formnote':formnote}
+ myFilters = {'avatar':avatar,'notnull':notnull,
+ 'formnote':formnote, 'content':content}
render._lookup.filters.update(myFilters)
return render
render = getRender()
-#render_mako配置 -- admin
+#render_jinja配置 -- admin
render_admin = render_jinja(
os.getcwd() + '/templates/admin',
- encoding = 'utf-8'
+ encoding = 'utf-8',
)
Oops, something went wrong.

0 comments on commit 767c4d0

Please sign in to comment.