示例#1
0
文件: forms.py 项目: jace/zine-main
def delete_comment(comment):
    """
    Deletes or marks for deletion the specified comment, depending on the
    comment's position in the comment thread. Comments are not pruned from
    the database until all their children are.
    """
    if comment.children:
        # We don't have to check if the children are also marked deleted or not
        # because if they still exist, it means somewhere down the tree is a
        # comment that is not deleted.
        comment.status = COMMENT_DELETED
        comment.text = u''
        comment.user = None
        comment._author = comment._email = comment._www = None
    else:
        parent = comment.parent
        #! plugins can use this to react to comment deletes.  They can't
        #! stop the deleting of the comment but they can delete information
        #! in their own tables so that the database is consistent
        #! afterwards.
        emit_event('before-comment-deleted', comment)
        db.delete(comment)
        while parent is not None and parent.is_deleted:
            if not parent.children:
                newparent = parent.parent
                emit_event('before-comment-deleted', parent)
                db.delete(parent)
                parent = newparent
            else:
                parent = None
示例#2
0
文件: forms.py 项目: jace/zine-main
 def delete_category(self):
     """Delete the category from the database."""
     #! plugins can use this to react to category deletes.  They can't stop
     #! the deleting of the category but they can delete information in
     #! their own tables so that the database is consistent afterwards.
     emit_event('before-category-deleted', self.category)
     db.delete(self.category)
示例#3
0
文件: forms.py 项目: jace/zine-main
 def approve_selection(self, comment=None):
     if comment:
         emit_event('before-comment-approved', comment)
         comment.status = COMMENT_MODERATED
         comment.blocked_msg = u''
     else:
         for comment in self.iter_selection():
             emit_event('before-comment-approved', comment)
             comment.status = COMMENT_MODERATED
             comment.blocked_msg = u''
示例#4
0
文件: forms.py 项目: jace/zine-main
 def delete_user(self):
     """Deletes the user."""
     if self.data['action'] == 'reassign':
         db.execute(posts.update(posts.c.author_id == self.user.id), dict(
             author_id=self.data['reassign_to'].id
         ))
     #! plugins can use this to react to user deletes.  They can't stop
     #! the deleting of the user but they can delete information in
     #! their own tables so that the database is consistent afterwards.
     #! Additional to the user object the form data is submitted.
     emit_event('before-user-deleted', self.user, self.data)
     db.delete(self.user)
示例#5
0
文件: forms.py 项目: jace/zine-main
    def delete_group(self):
        """Deletes a group."""
        if self.data['action'] == 'relocate':
            new_group = Group.query.filter_by(data['reassign_to'].id).first()
            for user in self.group.users:
                if not new_group in user.groups:
                    user.groups.append(new_group)
        db.commit()

        #! plugins can use this to react to user deletes.  They can't stop
        #! the deleting of the group but they can delete information in
        #! their own tables so that the database is consistent afterwards.
        #! Additional to the group object the form data is submitted.
        emit_event('before-group-deleted', self.group, self.data)
        db.delete(self.group)
示例#6
0
文件: forms.py 项目: jace/zine-main
    def create_if_valid(self, req):
        """The one-trick pony for commenting.  Passed a req it tries to
        use the req data to submit a comment to the post.  If the req
        is not a post req or the form is invalid the return value is None,
        otherwise a redirect response to the new comment.
        """
        if req.method != 'POST' or not self.validate(req.form):
            return

        # if we don't have errors let's save it and emit an
        # `before-comment-saved` event so that plugins can do
        # block comments so that administrators have to approve it
        comment = self.make_comment()

        #! use this event to block comments before they are saved.  This
        #! is useful for antispam and other ways of moderation.
        emit_event('before-comment-saved', req, comment)

        # Moderate Comment?  Now that the spam check any everything
        # went through the processing we explicitly set it to
        # unmodereated if the blog configuration demands that
        if not comment.blocked and comment.requires_moderation:
            comment.status = COMMENT_UNMODERATED
            comment.blocked_msg = _(u'Comment waiting for approval')

        #! this is sent directly after the comment was saved.  Useful if
        #! you want to send mail notifications or whatever.
        emit_event('after-comment-saved', req, comment)

        # Commit so that make_visible_for_request can access the comment id.
        db.commit()

        # Still allow the user to see his comment if it's blocked
        if comment.blocked:
            comment.make_visible_for_request(req)

        return redirect_to(self.post)
示例#7
0
文件: config.py 项目: peicheng/zine
 def get_public_list(self, hide_insecure=False):
     """Return a list of publicly available information about the
     configuration.  This list is safe to share because dangerous keys
     are either hidden or cloaked.
     """
     from zine.application import emit_event
     from zine.database import secure_database_uri
     result = []
     for key, field in self.config_vars.iteritems():
         value = self[key]
         if hide_insecure:
             if key in HIDDEN_KEYS:
                 value = '****'
             elif key == 'database_uri':
                 value = repr(secure_database_uri(value))
             else:
                 #! this event is emitted if the application wants to
                 #! display a configuration value in a publicly.  The
                 #! return value of the listener is used as new value.
                 #! A listener should return None if the return value
                 #! is not used.
                 for rv in emit_event('cloak-insecure-configuration-var',
                                      key, value):
                     if rv is not None:
                         value = rv
                         break
                 else:
                     value = repr(value)
         else:
             value = repr(value)
         result.append({
             'key':          key,
             'default':      repr(field.get_default()),
             'value':        value
         })
     result.sort(key=lambda x: x['key'].lower())
     return result
示例#8
0
文件: forms.py 项目: jace/zine-main
 def mark_selection_as_ham(self):
     for comment in self.iter_selection():
         emit_event('before-comment-mark-ham', comment)
         self.approve_selection(comment)
示例#9
0
文件: forms.py 项目: jace/zine-main
 def mark_selection_as_spam(self):
     for comment in self.iter_selection():
         emit_event('before-comment-mark-spam', comment)
         comment.status = COMMENT_BLOCKED_SPAM
         comment.blocked_msg = _("Comment marked as spam by %s" %
                                 get_request().user.display_name)
示例#10
0
文件: forms.py 项目: jace/zine-main
 def block_selection(self):
     for comment in self.iter_selection():
         emit_event('before-comment-blocked', comment)
         comment.status = COMMENT_BLOCKED_USER
         comment.blocked_msg = _("Comment blocked by %s" %
                                 get_request().user.display_name)
示例#11
0
文件: forms.py 项目: jace/zine-main
 def mark_as_ham(self):
     emit_event('before-comment-mark-ham', self.comment)
     emit_event('before-comment-approved', self.comment)
     self.comment.status = COMMENT_MODERATED
     self.comment.blocked_msg = u''
示例#12
0
文件: forms.py 项目: jace/zine-main
 def mark_as_spam(self):
     emit_event('before-comment-mark-spam', self.comment)
     self.comment.status = COMMENT_BLOCKED_SPAM
     self.comment.blocked_msg = _("Comment reported as spam by %s" %
                                 get_request().user.display_name)
示例#13
0
文件: forms.py 项目: jace/zine-main
 def approve_comment(self):
     """Approve the comment."""
     #! plugins can use this to react to comment approvals.
     emit_event('before-comment-approved', self.comment)
     self.comment.status = COMMENT_MODERATED
     self.comment.blocked_msg = u''
示例#14
0
文件: forms.py 项目: jace/zine-main
 def delete_post(self):
     """Deletes the post from the db."""
     emit_event('before-post-deleted', self.post)
     db.delete(self.post)