Permalink
Browse files

modifying admin page

  • Loading branch information...
David Shieh
David Shieh committed Mar 7, 2010
1 parent 7b4407d commit c91d039cb58d78b6d7db184d8feeabb4d8688ae9
View
@@ -7,6 +7,7 @@
from settings import pageCount from settings import pageCount
from settings import render_admin as render from settings import render_admin as render
from utils import Pagination from utils import Pagination
from models import *
d = {} d = {}
@@ -101,6 +102,7 @@ def GET(self, id):
entry = self.getEntry(id) entry = self.getEntry(id)
if entry: if entry:
f = entryForm() f = entryForm()
entry.tagList = ",".join([i.name for i in entry.tags])
d['entry'] = entry d['entry'] = entry
d['f'] = f d['f'] = f
return render.entry_edit(**d) return render.entry_edit(**d)
@@ -113,7 +115,7 @@ def POST(self, id):
if f.validates(): if f.validates():
if i.tags is not None: if i.tags is not None:
newTags = set([i.strip() for i in i.tags.split(',')]) newTags = set([i.strip() for i in i.tags.split(',')])
originalTags = set([i.strip() for i in entry.tags.split(',')]) originalTags = set([i.name.strip() for i in entry.tags])
tagsAdd = list(newTags - originalTags) tagsAdd = list(newTags - originalTags)
tagsDel = list(originalTags - newTags) tagsDel = list(originalTags - newTags)
#添加tag #添加tag
@@ -147,25 +149,14 @@ def POST(self, id):
class entry_del(object): class entry_del(object):
@login_required @login_required
def GET(self, id): def GET(self, id):
entry = list(db.query('SELECT * FROM entries WHERE id = $id', vars={'id':id})) entry = web.ctx.orm.query(Entry).filter_by(id=id).first()
if len(entry) > 0: if entry:
db.query('DELETE FROM entries WHERE id = $id', vars={'id':id}) if len(entry.tags) > 0:
category = list(db.query('SELECT * FROM categories WHERE id = $id', for tag in entry.tags:
vars={'id':entry[0].categoryId})) tag.entryNum = tag.entryNum - 1
db.query('UPDATE categories SET `entryNum` = $entryNum WHERE id = $categoryId', entry.tags.remove(tag)
vars={'entryNum':int(category[0].entryNum) - 1, 'categoryId':category[0].id}) web.ctx.orm.delete(entry)
tags = list(db.query('SELECT t.id AS tagId, t.entryNum AS entryNum ' return web.seeother('/entry/list/')
'FROM entry_tag et LEFT JOIN tags t ON t.id = et.tagId '
'WHERE et.entryId = $entryId', vars= {'entryId':entry[0].id}))
for tag in tags:
if tag.entryNum > 2:
db.query('UPDATE tags SET `entryNum` = $entryNum WHERE id = $id',
vars={'entryNum':int(tag.entryNum) - 1, 'id':tag.tagId})
if temp[0].entryNum == 1:
db.query('DELETE FROM tags WHERE id = $tagId', vars={'tagId':tag.tagId})
db.query('DELETE FROM entry_tag WHERE entryId = $entryId AND tagId = $tagId',
vars={'entryId':tag.entryId, 'tagId':tag.tagId})
return web.seeother('/entry/')
class links(object): class links(object):
@login_required @login_required
View
@@ -4,7 +4,7 @@
from settings import db from settings import db
__all__ = [ __all__ = [
'commentForm', 'linkForm' 'commentForm', 'linkForm', 'entryForm'
] ]
username_validate = form.regexp(r".{3,15}$", u"请输入3-15位的用户名") username_validate = form.regexp(r".{3,15}$", u"请输入3-15位的用户名")
@@ -24,11 +24,6 @@
form.Button('submit', type="submit", description=u"留言"), form.Button('submit', type="submit", description=u"留言"),
) )
categoryForm = form.Form(
form.Textbox('name', form.notnull),
form.Textbox('slug', form.notnull)
)
linkForm = form.Form( linkForm = form.Form(
form.Textbox('name', form.notnull), form.Textbox('name', form.notnull),
form.Textbox('url', form.notnull, urlValidator) form.Textbox('url', form.notnull, urlValidator)
@@ -38,5 +33,4 @@
form.Textbox('title', form.notnull), form.Textbox('title', form.notnull),
form.Textbox('content', form.notnull), form.Textbox('content', form.notnull),
form.Textbox('slug', form.notnull), form.Textbox('slug', form.notnull),
form.Textarea('categoryId', form.notnull),
) )
View
@@ -31,7 +31,13 @@ def getRender():
render = getRender() render = getRender()
#render_jinja配置 -- admin #render_jinja配置 -- admin
render_admin = render_jinja( def getAdminRender():
os.getcwd() + '/templates/admin', render = render_jinja(
encoding = 'utf-8', os.getcwd() + '/templates/admin',
) encoding = 'utf-8',
)
myFilters = {'avatar':avatar,'notnull':notnull,
'formnote':formnote, 'content':content}
render._lookup.filters.update(myFilters)
return render
render_admin = getAdminRender()
View
@@ -104,7 +104,9 @@ body {
margin:15px 0; margin:15px 0;
} }
.blog_each > div a:link, .blog_each > div a:link,
.blog_each > div a:visited { .blog_each > div a:visited,
.blog_each > h3 a:link,
.blog_each > h3 a:visited {
text-decoration:underline; text-decoration:underline;
color:#A76B2E; color:#A76B2E;
} }
View
@@ -2,6 +2,6 @@
<h1><a href="/entry/{{ entry.slug }}/">{{ entry.title }}</a></h1> <h1><a href="/entry/{{ entry.slug }}/">{{ entry.title }}</a></h1>
<h3>{% if entry.tags %}<span>标签 : </span>{% for tag in entry.tags %} <h3>{% if entry.tags %}<span>标签 : </span>{% for tag in entry.tags %}
<span><a href="/tag/{{ tag.name }}/">{{ tag.name }}</a></span> <span><a href="/tag/{{ tag.name }}/">{{ tag.name }}</a></span>
{% endfor %} | {% endif %}<span>发表 : </span>{{ entry.createdTime }} | {{ entry.commentNum }} 条回复</h3> {% endfor %} | {% endif %}<span>发表 : </span>{{ entry.createdTime }} | <a href="/entry/{{ entry.slug }}/#comments">{{ entry.commentNum }} 条回复</a></h3>
<div>{{ entry.content|content }}</div> <div>{{ entry.content|content }}</div>
</div> </div>
@@ -38,38 +38,14 @@
</script> </script>
<div id="edit_entry"> <div id="edit_entry">
<form action="/admin/entry/add/" method="POST"> <form action="/admin/entry/add/" method="POST">
<table> <p>{{ f.title.render() }}
<tr> <label>标题</label></p>
<th>标题</th> <p>{{ f.slug.render() }}
<td>{{ f.title.render() }}</td> <label>Slug</label></p>
</tr> <p><input type="text" name="tags" />
<tr> <label>标签</label></p>
<th>Slug</th> <p><textarea name="content" id="markItUp"></textarea></p>
<td>{{ f.slug.render() }}</td> <p><input type="submit" value="发表日志" /></p>
</tr>
<tr>
<th>分类</th>
<td>
<select name="categoryId">
{% for one in categories %}
<option value="{{ one.id }}">{{ one.name }}({{ one.entryNum }})</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<th>标签</th>
<td><input type="text" name="tags" /></td>
</tr>
<tr>
<th>正文</th>
<td><textarea name="content" id="markItUp"></textarea></td>
</tr>
<tr>
<th>&nbsp;</th>
<td><input type="submit" value="发表日志" /></td>
</tr>
</table>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}
@@ -38,38 +38,14 @@
</script> </script>
<div id="entry_edit"> <div id="entry_edit">
<form action="/admin/entry/edit/{{ entry.id }}/" method="POST" id="entry_form"> <form action="/admin/entry/edit/{{ entry.id }}/" method="POST" id="entry_form">
<table> <p><input type="text" name="title" value="{{ entry.title }}" />{{ f.title.note | notnull }}
<tr> <label>标题</label></p>
<th>标题</th> <p><input type="text" name="slug" value="{{ entry.slug }}" />{{ f.slug.note | notnull }}
<td><input type="text" name="title" value="{{ f.title.value }}" /></td> <label>Slug</label></p>
</tr> <p><input type="text" name="tags" value="{{ entry.tagList }}" />
<tr> <label>标签</label></p>
<th>Slug</th> <p><textarea name="content" id="markItUp">{{ entry.content }}</textarea>{{ f.content.note | notnull }}</p>
<td><input type="text" name="slug" value="{{ f.slug.value }}" /></td> <p><input type="submit" value="更新日志" /></p>
</tr>
<tr>
<th>分类</th>
<td>
<select name="categoryId">
{% for one in categories %}
<option value="{{ one.id }}" {% if one.id == entry.categoryId %}selected="selected"{% endif %}>{{ one.name }}({{ one.entryNum }})</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<th>标签</th>
<td><input type="text" name="tags" value="{{ entry.tags }}" /></td>
</tr>
<tr>
<th>正文</th>
<td><textarea name="content" id="markItUp">{{ entry.content }}</textarea></td>
</tr>
<tr>
<th>&nbsp;</th>
<td><input type="submit" value="更新日志" /></td>
</tr>
</table>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}
@@ -12,15 +12,15 @@
<td>{{ one.title }}</td> <td>{{ one.title }}</td>
<td>{{ one.categoryName }}</td> <td>{{ one.categoryName }}</td>
<td> <td>
<a href="/admin/entry/edit/{{ one.entryId }}/">修改</a> <a href="/admin/entry/edit/{{ one.id }}/">修改</a>
<a href="/admin/entry/del/{{ one.entryId }}/">删除</a> <a href="/admin/entry/del/{{ one.id }}/">删除</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<div id="pager"> <div id="pager">
{% for i in range(p[1]) %} {% for i in range(p.pages) %}
<span><a href="/admin/entry/list/?page={{ i + 1 }}">{{ i + 1 }}</a></span> <span><a href="/admin/entry/list/?page={{ i + 1 }}">{{ i + 1 }}</a></span>
{% endfor %} {% endfor %}
</div> </div>
View
@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<div id="blog_list"> <div id="blog_list">
{% include "_entry.html" %} {% include "_entry.html" %}
<div id="comments"> <div id="comments" name="comments">
<h2><span id="comments_num">{{ entry.comments | length }}</span> 条评论</h2> <h2><span id="comments_num">{{ entry.comments | length }}</span> 条评论</h2>
{% if entry.comments %} {% if entry.comments %}
{% if p.pages > 1 %} {% if p.pages > 1 %}

0 comments on commit c91d039

Please sign in to comment.