Permalink
Browse files

cil-0085f7a8: Allow editing of comments in the admin interface

  • Loading branch information...
1 parent 86c96a5 commit e92594a48219b57b851e64bd653a0e8a56e3e490 @chilts chilts committed Feb 13, 2010
Showing with 105 additions and 8 deletions.
  1. +1 −0 admin.py
  2. +54 −1 comment.py
  3. +42 −0 error.py
  4. +2 −2 issues/i_0085f7a8.cil
  5. +2 −5 models.py
  6. +4 −0 theme/admin/comment-list.html
View
@@ -112,6 +112,7 @@ def get(self, page):
# comments
('/admin/comment/', comment.Index),
+ ('/admin/comment/edit.html', comment.Edit),
('/admin/comment/del.html', comment.Del),
('/admin/comment/del-all.html', comment.DelAll),
View
@@ -34,8 +34,10 @@
from google.appengine.ext import db
# local modules
+from models import Comment, Section
+import models
import webbase
-from models import Comment
+import error
## ----------------------------------------------------------------------------
@@ -77,6 +79,57 @@ def get(self):
self.redirect('./')
return
+# Edit
+class Edit(webbase.WebBase):
+ def get(self):
+ item = None
+ if self.request.get('key'):
+ item = Comment.get( self.request.get('key') )
+ else:
+ raise error.RequiresEntityError("Needs a comment key (ie. can't add new comments in the admin interface)")
+
+ vals = {
+ 'item' : item,
+ 'sections' : Section.all(),
+ 'types' : models.type_choices
+ }
+ self.template( 'comment-form.html', vals, 'admin' );
+
+ def post(self):
+ item = None
+ vals = {}
+ try:
+ # get all the incoming values
+ name = self.request.get('name')
+ email = self.request.get('email')
+ website = self.request.get('website')
+ comment = self.request.get('comment')
+
+ if self.request.get('key'):
+ item = Comment.get( self.request.get('key') )
+ item.name = name
+ item.email = email
+ item.website = website
+ item.comment = comment
+ else:
+ # we have no ability to add comments, so fail here
+ raise error.RequiresEntityError("Needs a comment key (ie. can't add new comments in the admin interface)")
+
+ # update and save this comment
+ item.set_derivatives()
+ item.put()
+
+ # don't need to item.node.regenerate() since the status is _not_ changing
+
+ self.redirect('.')
+ except Exception, err:
+ vals['item'] = self.request.POST
+ vals['err'] = err
+ vals['sections'] = Section.all()
+ vals['types'] = models.type_choices
+ self.template( 'comment-form.html', vals, 'admin' );
+
+
# Delete
class Del(webbase.WebBase):
def get(self):
View
@@ -0,0 +1,42 @@
+## ----------------------------------------------------------------------------
+# Lollysite is a website builder and blogging platform for Google App Engine.
+#
+# Copyright (c) 2009, 2010 Andrew Chilton <andy@chilts.org>.
+#
+# Homepage : http://www.chilts.org/project/lollysite/
+# Ohloh : https://www.ohloh.net/p/lollysite/
+# FreshMeat : http://freshmeat.net/projects/lollysite
+# Source : http://gitorious.org/lollysite/
+#
+# This file is part of Lollysite.
+#
+# Lollysite is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# Lollysite is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Lollysite. If not, see <http://www.gnu.org/licenses/>.
+#
+## ----------------------------------------------------------------------------
+
+# Errors for use throughout the site
+
+## ----------------------------------------------------------------------------
+# import standard modules
+
+## ----------------------------------------------------------------------------
+# local modules
+
+class RequiresEntityError(Exception):
+ def __init__(self, type):
+ self.type = type
+ def __str__(self):
+ return repr(type)
+
+## ----------------------------------------------------------------------------
View
@@ -1,10 +1,10 @@
Summary: Add ability to edit comments
-Status: New
+Status: Finished
CreatedBy: Andrew Chilton <andychilton@gmail.com>
AssignedTo: Andrew Chilton <andychilton@gmail.com>
Label: Milestone-v0.05
Inserted: 2009-12-07T23:41:50
-Updated: 2010-01-07T08:44:26
+Updated: 2010-02-13T23:06:16
Mostly, we don't want to edit comments, but sometimes people make mistakes (and
don't realise and don't correct them). Having the ability to edit comments from
View
@@ -50,6 +50,7 @@
type_choices = ["text", "code", "phliky", "textile", "html", "markdown"]
node_choices = ['page', 'recipe']
layout_choices = ['content', 'blog', 'faq']
+comment_choices = ['new', 'approved', 'rejected']
## ----------------------------------------------------------------------------
# normal models
@@ -215,11 +216,7 @@ class Comment(BaseModel):
email = db.StringProperty(multiline=False)
website = db.StringProperty(multiline=False)
comment = db.TextProperty()
- status = db.StringProperty(
- required=True,
- default='new',
- choices=['new', 'approved', 'rejected']
- )
+ status = db.StringProperty(required=True, default='new', choices=set(comment_choices))
# Derivative Properties
comment_html = db.TextProperty()
@@ -11,6 +11,7 @@
<thead>
<tr>
<th class="c"><input class="select-all" type="checkbox" /></th>
+ <th class="thin">Edit</th>
<th>Info</th>
<th>Page / Comment</th>
<th class="thin">Approve</th>
@@ -24,6 +25,9 @@
<td class="c">
<input type="checkbox" class="keys" name="keys" value="{{ comment.key|escape }}" />
</td>
+ <td class="c">
+ <a href="edit.html?key={{ comment.key|urlencode }}"><img title="Edit Comment" src="/s/i/layout_edit.png" /></a>
+ </td>
<td>
<strong>{{ comment.name|escape }} &lt;{{ comment.email|escape }}&gt;</strong>
<br />

0 comments on commit e92594a

Please sign in to comment.