Permalink
Browse files

make some changes

  • Loading branch information...
1 parent 43a04e6 commit 21cd9bc3c72c78d13c13f2ac35db4467cd63c285 David Xie committed Jun 6, 2010
View
8 davidblog/admin.py
@@ -9,10 +9,10 @@
'/$', 'adminviews.index',
'/login/', 'adminviews.login',
'/logout/', 'adminviews.logout',
- '/category/list/', 'adminviews.category_list',
- '/category/add/', 'adminviews.category_add',
- '/category/del/(.*)/', 'adminviews.category_del',
- '/category/edit/(.*)/', 'adminviews.category_edit',
+ '/link/list/', 'adminviews.link_list',
+ '/link/add/', 'adminviews.link_add',
+ '/link/del/(.*)/', 'adminviews.link_del',
+ '/link/edit/(.*)/', 'adminviews.link_edit',
'/tag/list/', 'adminviews.tag_list',
'/tag/add/', 'adminviews.tag_add',
'/tag/del/(.*)/', 'adminviews.tag_del',
View
105 davidblog/adminviews.py
@@ -29,10 +29,11 @@ def GET(self):
class index(object):
@login_required
def GET(self):
- d['entry_num'] = web.ctx.orm.query(Entry).count()
- d['comment_num'] = web.ctx.orm.query(Comment).count()
- d['tag_num'] = web.ctx.orm.query(Tag).count()
- d['link_num'] = web.ctx.orm.query(Link).count()
+ d['entryNum'] = web.ctx.orm.query(Entry).count()
+ d['tagNum'] = web.ctx.orm.query(Tag).count()
+ d['linkNum'] = web.ctx.orm.query(Link).count()
+ d['pageNum'] = web.ctx.orm.query(Page).count()
+ d['commentNum'] = web.ctx.orm.query(Comment).count()
return render.index(**d)
class login(object):
@@ -175,72 +176,80 @@ def GET(self, id):
web.ctx.orm.delete(i)
return web.seeother('/entry/list/')
-class links(object):
+class link_list(object):
@login_required
def GET(self):
page = web.input(page=1)
- page = int(page.page)
- linkNum = list(db.query("SELECT COUNT(id) AS num FROM links"))
- pages = float(linkNum[0]['num'] / 10)
- if pages > int(pages):
- pages = int(pages + 1)
- elif pages == 0:
- pages = 1
- else:
- pages = int(pages)
- if page > pages:
- page = pages
- links = list(db.query('SELECT * FROM links ORDER BY name ASC '
- 'LIMIT $start, 10', vars={'start': (page - 1) * 10}))
-
- para['page'] = page
- para['pages'] = pages
- para['links'] = links
-
- return render.tag(**para)
+ try:
+ page = int(page.page)
+ except:
+ page = 1
+ linkCount = web.ctx.orm.query(Link).count()
+ p = Pagination(linkCount, pageCount, page)
+ links = web.ctx.orm.query(Link).order_by('links.name ASC')[int(p.start):int(p.start+p.limit)]
+ d['p'] = p
+ d['links'] = links
+ return render.link_list(**d)
class link_add(object):
@login_required
def GET(self):
f = linkForm()
-
- para['f'] = f
-
- return render.link_add(**para)
+ d['f'] = f
+ return render.link_add(**d)
@login_required
def POST(self):
f = linkForm()
if f.validates():
- data = dict(**f.d)
- db.insert('links', name = data['name'], url = data['url'])
- return web.seeother('/links/')
+ link = Link()
+ link.name = f.name.value
+ link.description = f.description.value
+ link.url = f.url.value
+ web.ctx.orm.add(link)
+ try:
+ web.ctx.orm.commit()
+ except:
+ web.ctx.orm.rollback()
+ return web.seeother('/link/list/')
+ else:
+ d['f'] = f
+ return render.link_add(**d)
class link_edit(object):
+ def getLink(self, id):
+ return web.ctx.orm.query(Link).filter_by(id=id).first()
+
@login_required
def GET(self, id):
f = linkForm()
- links = list(db.query("SELECT * FROM links WHERE id = $id", vars = {'id':id}))
- f.get('name').value = links[0].name
- f.get('url').value = links[0].slug
-
- para['f'] = f
-
- return render.link_edit(**para)
+ link = self.getLink(id)
+ f.name.value = link.name
+ f.url.value = link.url
+ f.description.value = link.description
+ d['f'] = f
+ d['link'] = link
+ return render.link_edit(**d)
@login_required
def POST(self, id):
f = linkForm()
if f.validates():
- data = dict(**f.d)
- db.update('links', where = "id = %s" % id, name = data['name'], url = data['url'])
- return web.seeother('/links/')
+ link = self.getLink(id)
+ link.name = f.name.value
+ link.url = f.url.value
+ link.description = f.description.value
+ return web.seeother('/link/list/')
+ else:
+ d['f'] = f
+ return render.link_edit(**d)
class link_del(object):
@login_required
def GET(self, id):
- db.delete('links', where = 'id = %s' % id)
- return web.seeother('/links/')
+ link = web.ctx.orm.query(Link).filter_by(id=id).first()
+ web.ctx.orm.delete(link)
+ return web.seeother('/link/list/')
class page_list(object):
@login_required
@@ -262,7 +271,10 @@ def POST(self):
if f.validates():
page = Page(f.title.value, f.slug.value, f.content.value)
web.ctx.orm.add(page)
- return web.seeother('/page/list/')
+ return web.seeother('/page/list/')
+ else:
+ d['f'] = f
+ return render.page_add(**d)
class page_edit(object):
def getPage(self, id):
@@ -286,7 +298,10 @@ def POST(self, id):
page.slug = f.slug.value
page.content = f.content.value
page.modifiedTime= datetime.now()
- return web.seeother('/page/list/')
+ return web.seeother('/page/list/')
+ else:
+ d['f'] = f
+ return render.page_edit(**d)
class page_del(object):
@login_required
View
3 davidblog/forms.py
@@ -25,7 +25,8 @@
linkForm = form.Form(
form.Textbox('name', form.notnull),
- form.Textbox('url', form.notnull, urlValidator)
+ form.Textbox('url', form.notnull, urlValidator),
+ form.Textbox('description', form.notnull)
)
entryForm = form.Form(
View
3 davidblog/models.py
@@ -97,7 +97,8 @@ class Link(Base):
id = Column(Integer, primary_key=True)
name = Column(String(45))
url = Column(String(45))
- created_time = Column(DateTime)
+ description = Column(String(255))
+ created_time = Column(DateTime, default=datetime.now())
class Admin(Base):
__tablename__ = 'admins'
View
5 davidblog/static/admin/css/admin.css
@@ -10,4 +10,7 @@
#edit_entry form table td > span {
color: red;
padding: 5px;
-}
+}
+.actions {
+ text-align:center;
+}
View
11 davidblog/templates/admin/base.html
@@ -16,7 +16,7 @@
<h2><a href="/">泥泞的沼泽</a><span>0.3 alpha</span></h2>
<div id="topmenu">
<ul>
- <li class="current"><a href="/admin/">管理首页</a></li>
+ <li><a href="/admin/">管理首页</a></li>
<li><a href="/admin/entry/list/">文章管理</a></li>
<li><a href="/admin/comment/list/">评论管理</a></li>
<li><a href="/admin/page/list/">页面管理</a></li>
@@ -44,15 +44,6 @@
<div id="credits">
<p>版权所有©2009 - 2010 <a href="http://davidx.me/">David Xie</a>
</div>
- <div id="styleswitcher">
- <ul>
- <li><a href="javascript: document.cookie='theme='; window.location.reload();" title="Default" id="defswitch">d</a></li>
- <li><a href="javascript: document.cookie='theme=1'; window.location.reload();" title="Blue" id="blueswitch">b</a></li>
- <li><a href="javascript: document.cookie='theme=2'; window.location.reload();" title="Green" id="greenswitch">g</a></li>
- <li><a href="javascript: document.cookie='theme=3'; window.location.reload();" title="Brown" id="brownswitch">b</a></li>
- <li><a href="javascript: document.cookie='theme=4'; window.location.reload();" title="Mix" id="mixswitch">m</a></li>
- </ul>
- </div>
<br />
</div>
</div>
View
5 davidblog/templates/admin/entry_add.html
@@ -1,6 +1,11 @@
{% extends 'base.html' %}
{% block title %}添加新日志{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(1)').addClass('current');
+ });
+</script>
<script type="text/javascript" src="/static/markitup/jquery.markitup.pack.js"></script>
<script src="/static/markitup/sets/markdown/set.js" type="text/javascript"></script>
<link href="/static/markitup/sets/markdown/style.css" rel="stylesheet" type="text/css"/>
View
5 davidblog/templates/admin/entry_edit.html
@@ -1,6 +1,11 @@
{% extends 'base.html' %}
{% block title %}修改日志{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(1)').addClass('current');
+ });
+</script>
<script type="text/javascript" src="/static/markitup/jquery.markitup.pack.js"></script>
<script src="/static/markitup/sets/markdown/set.js" type="text/javascript"></script>
<link href="/static/markitup/sets/markdown/style.css" rel="stylesheet" type="text/css"/>
View
7 davidblog/templates/admin/entry_list.html
@@ -1,6 +1,11 @@
{% extends 'base.html' %}
{% block title %}日志列表{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(1)').addClass('current');
+ });
+</script>
<table>
<tr>
<th>名称</th>
@@ -11,7 +16,7 @@
<tr>
<td>{{ one.title }}</td>
<td>{{ one.created_time }}</td>
- <td>
+ <td class="actions">
<a href="/admin/entry/edit/{{ one.id }}/">修改</a> |
<a href="/admin/entry/del/{{ one.id }}/">删除</a>
</td>
View
29 davidblog/templates/admin/index.html
@@ -1,11 +1,26 @@
{% extends "base.html" %}
{% block title %}首页{% endblock %}
{% block content %}
-<ul>
- <li><a href="/admin/entry/list/">现在共有 {{ entryNum }} 篇文章</a></li>
- <li><a href="/admin/comment/list/">现在共有 {{ commentNum }} 条评论</a></li>
- <li><a href="/admin/category/list/">现在共有 {{ categoryNum }} 个分类</a></li>
- <li><a href="/admin/tag/list/">现在共有 {{ tagNum }} 个标签</a></li>
- <li><a href="/admin/link/list/">现在共有 {{ linkNum }} 个链接</a></li>
-</ul>
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(0)').addClass('current');
+ });
+</script>
+<table>
+ <tr>
+ <td><a href="/admin/entry/list/">现在共有 {{ entryNum }} 篇文章</a></td>
+ </tr>
+ <tr>
+ <td><a href="/admin/comment/list/">现在共有 {{ commentNum }} 条评论</a></td>
+ </tr>
+ <tr>
+ <td><a href="/admin/tag/list/">现在共有 {{ tagNum }} 个标签</a></td>
+ </tr>
+ <tr>
+ <td><a href="/admin/link/list/">现在共有 {{ linkNum }} 个链接</a></td>
+ </tr>
+ <tr>
+ <td><a href="/admin/page/list/">现在共有 {{ pageNum }} 个链接</a></td>
+ </tr>
+</table>
{% endblock %}
View
34 davidblog/templates/admin/link_add.html
@@ -1,6 +1,28 @@
-<%inherit file="base.html" />
-<%def name="title()">标签管理</%def>
-
-<form action="/admin/tag/add/" method="POST">
- ${ f.render() }
-</form>
+{% extends "base.html" %}
+{% block title %}添加新地址{% endblock %}
+{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(4)').addClass('current');
+ });
+</script>
+<div id="edit_link">
+ <form action="/admin/link/add/" method="POST">
+ <table>
+ <tr>
+ <th><label>名称</label></th>
+ <td><input type="text" name="name" value="{{ f.name.value | notnull }}" /><span>{{ f.name.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>地址</label></th>
+ <td><input type="text" name="url" value="{{ f.url.value | notnull }}" /><span>{{ f.url.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>描述</label></th>
+ <td><input type="text" name="description" value="{{ f.description.value | notnull }}" /></td>
+ </tr>
+ </table>
+ <p><input type="submit" value="添加" /></p>
+ </form>
+</div>
+{% endblock %}
View
34 davidblog/templates/admin/link_edit.html
@@ -1,6 +1,28 @@
-<%inherit file="base.html" />
-<%def name="title()">修改分类 - 分类管理</%def>
-
-<form action="/admin/category/edit/${ id }/" method="POST">
- ${ f.render() }
-</form>
+{% extends "base.html" %}
+{% block title %}修改地址{% endblock %}
+{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(4)').addClass('current');
+ });
+</script>
+<div id="edit_link">
+ <form action="/admin/link/edit/{{ link.id }}/" method="POST">
+ <table>
+ <tr>
+ <th><label>名称</label></th>
+ <td><input type="text" name="name" value="{{ f.name.value | notnull }}" /><span>{{ f.name.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>地址</label></th>
+ <td><input type="text" name="url" value="{{ f.url.value | notnull }}" /><span>{{ f.url.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>描述</label></th>
+ <td><input type="text" name="description" value="{{ f.description.value | notnull }}" /></td>
+ </tr>
+ </table>
+ <p><input type="submit" value="修改" /></p>
+ </form>
+</div>
+{% endblock %}
View
29 davidblog/templates/admin/page_add.html
@@ -1,6 +1,11 @@
-{% extends "base.html" %}
+{% extends 'base.html' %}
{% block title %}添加新页面{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(3)').addClass('current');
+ });
+</script>
<script type="text/javascript" src="/static/markitup/jquery.markitup.pack.js"></script>
<script src="/static/markitup/sets/markdown/set.js" type="text/javascript"></script>
<link href="/static/markitup/sets/markdown/style.css" rel="stylesheet" type="text/css"/>
@@ -36,14 +41,22 @@
});
});
</script>
-<div id="entry_edit">
+<div id="edit_entry">
<form action="/admin/page/add/" method="POST">
- <p><input type="text" name="title" value="{{ f.title.value | notnull }}" />{{ f.title.note | notnull }}
- <label>标题</label></p>
- <p><input type="text" name="slug" value="{{ f.slug.value | notnull }}" />{{ f.slug.note | notnull }}
- <label>Slug</label></p>
- <p><textarea name="content" id="markItUp">{{ f.content.value | notnull }}</textarea>{{ f.content.note | notnull }}</p>
- <p><input type="submit" value="发表日志" /></p>
+ <table>
+ <tr>
+ <th><label>标题</label></th>
+ <td><input type="text" name="title" value="{{ f.title.value | notnull }}" /><span>{{ f.title.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>Slug</label></th>
+ <td><input type="text" name="slug" value="{{ f.slug.value | notnull }}" /><span>{{ f.slug.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <td colspan="2"><textarea name="content" id="markItUp">{{ f.content.value | notnull }}</textarea><span>{{ f.content.note | notnull }}</span></td>
+ </tr>
+ </table>
+ <p><input type="submit" value="发表页面" /></p>
</form>
</div>
{% endblock %}
View
33 davidblog/templates/admin/page_edit.html
@@ -1,12 +1,17 @@
-{% extends "base.html" %}
-{% block title %}添加新页面{% endblock %}
+{% extends 'base.html' %}
+{% block title %}修改页面{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(3)').addClass('current');
+ });
+</script>
<script type="text/javascript" src="/static/markitup/jquery.markitup.pack.js"></script>
<script src="/static/markitup/sets/markdown/set.js" type="text/javascript"></script>
<link href="/static/markitup/sets/markdown/style.css" rel="stylesheet" type="text/css"/>
<link href="/static/markitup/skins/markitup/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
-$(document).ready(function() {
+$(document).ready(function() {
// Add markItUp! to your textarea in one line
// $('textarea').markItUp( { Settings }, { OptionalExtraSettings } );
$('#markItUp').markItUp(mySettings);
@@ -37,13 +42,21 @@
});
</script>
<div id="entry_edit">
- <form action="/admin/page/edit/{{ page.id }}/" method="POST">
- <p><input type="text" name="title" value="{{ page.title | notnull }}" />{{ f.title.note | notnull }}
- <label>标题</label></p>
- <p><input type="text" name="slug" value="{{ page.slug | notnull }}" />{{ f.slug.note | notnull }}
- <label>Slug</label></p>
- <p><textarea name="content" id="markItUp">{{ page.content | notnull }}</textarea>{{ f.content.note | notnull }}</p>
- <p><input type="submit" value="更新日志" /></p>
+ <form action="/admin/page/edit/{{ page.id }}/" method="POST" id="entry_form">
+ <table>
+ <tr>
+ <th><label>标题</label></th>
+ <td><input type="text" name="title" value="{{ f.title.value | notnull }}" /><span>{{ f.title.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <th><label>Slug</label></th>
+ <td><input type="text" name="slug" value="{{ f.slug.value | notnull }}" /><span>{{ f.slug.note | notnull }}</span></td>
+ </tr>
+ <tr>
+ <td colspan="2"><textarea name="content" id="markItUp">{{ f.content.value | notnull }}</textarea><span>{{ f.content.note | notnull }}</span></td>
+ </tr>
+ </table>
+ <p><input type="submit" value="更新页面" /></p>
</form>
</div>
{% endblock %}
View
25 davidblog/templates/admin/page_list.html
@@ -1,22 +1,27 @@
-{% extends "base.html" %}
-{% block title %}页面管理{% endblock %}
+{% extends 'base.html' %}
+{% block title %}页面列表{% endblock %}
{% block content %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#topmenu').find('li:eq(3)').addClass('current');
+ });
+</script>
<table>
<tr>
- <th>No.</th>
<th>名称</th>
+ <th>发表时间</th>
<th>操作</th>
</tr>
- {% for i in pages %}
+ {% for one in entries %}
<tr>
- <td>{{ loop.index }}</td>
- <td>{{ i.title }}</td>
- <td>
- <a href="/admin/page/edit/{{ i.id }}/">修改</a> |
- <a href="/admin/page/del/{{ i.id }}/">删除</a>
+ <td>{{ one.title }}</td>
+ <td>{{ one.created_time }}</td>
+ <td class="actions">
+ <a href="/admin/page/edit/{{ one.id }}/">修改</a> |
+ <a href="/admin/page/del/{{ one.id }}/">删除</a>
</td>
</tr>
- {% endfor %}
+ {% endfor %}
</table>
<p><a href="/admin/page/add/">添加新页面</a></p>
{% endblock %}
View
9 davidblog/views.py
@@ -51,13 +51,16 @@ def GET(self):
# 读取当前页的文章
i = web.input(page=1)
ids = [int(one.id) for one in web.ctx.orm.query(Entry.id).all()]
- #randomEntries = [web.ctx.orm.query(Entry).filter_by(id=id).first() for id in random.sample(ids, 5)]
+ if len(ids) < 5:
+ randomEntries = web.ctx.orm.query(Entry).all()
+ else:
+ randomEntries = web.ctx.orm.query(Entry).filter(Entry.id.in_(random.sample(ids, 5)))
entryCount = web.ctx.orm.query(Entry).count()
p = Pagination(entryCount, 5, int(i.page))
d['entries'] = web.ctx.orm.query(Entry).order_by('entries.created_time DESC')[p.start:p.start + p.limit]
d['p'] = p
d['usedTime'] = time.time() - d['startTime']
- #d['randomEntries'] = randomEntries
+ d['randomEntries'] = randomEntries
return render.index(**d)
class entry(object):
@@ -96,7 +99,7 @@ def POST(self, slug):
for e in set(emails):
try:
web.sendmail('admin@davidx.me', e,
- u'您在"泥泞的沼泽"上回复的日志又有新的回复了!', message,
+ '您在"泥泞的沼泽"上回复的日志又有新的回复了!'.encode('utf-8'), message,
headers={'Content-Type':'text/html;charset=utf-8'})
except:
pass

0 comments on commit 21cd9bc

Please sign in to comment.