Permalink
Browse files

modifying admin page

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

0 comments on commit c91d039

Please sign in to comment.