Skip to content

Commit

Permalink
make some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
David Xie committed Jun 6, 2010
1 parent 43a04e6 commit 21cd9bc
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 113 deletions.
8 changes: 4 additions & 4 deletions davidblog/admin.py
Expand Up @@ -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',
Expand Down
105 changes: 60 additions & 45 deletions davidblog/adminviews.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion davidblog/forms.py
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion davidblog/models.py
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion davidblog/static/admin/css/admin.css
Expand Up @@ -10,4 +10,7 @@
#edit_entry form table td > span {
color: red;
padding: 5px;
}
}
.actions {
text-align:center;
}
11 changes: 1 addition & 10 deletions davidblog/templates/admin/base.html
Expand Up @@ -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>
Expand Down Expand Up @@ -44,15 +44,6 @@ <h2><a href="/">泥泞的沼泽</a><span>0.3 alpha</span></h2>
<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>
Expand Down
5 changes: 5 additions & 0 deletions 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"/>
Expand Down
5 changes: 5 additions & 0 deletions 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"/>
Expand Down
7 changes: 6 additions & 1 deletion 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>
Expand All @@ -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>
Expand Down
29 changes: 22 additions & 7 deletions 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 %}
34 changes: 28 additions & 6 deletions 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 %}
34 changes: 28 additions & 6 deletions 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 %}

0 comments on commit 21cd9bc

Please sign in to comment.