add 'delete' action to comments
This commit is contained in:
parent
8ab637c402
commit
21ac74f764
4 changed files with 47 additions and 5 deletions
|
@ -561,6 +561,14 @@
|
||||||
factory="loops.browser.concept.TabbedPage"
|
factory="loops.browser.concept.TabbedPage"
|
||||||
permission="zope.View" />
|
permission="zope.View" />
|
||||||
|
|
||||||
|
<!-- delete object action -->
|
||||||
|
|
||||||
|
<page
|
||||||
|
name="delete_object"
|
||||||
|
for="loops.interfaces.INode"
|
||||||
|
class="loops.browser.form.DeleteObject"
|
||||||
|
permission="zope.ManageContent" />
|
||||||
|
|
||||||
<!-- dialogs/forms (end-user views) -->
|
<!-- dialogs/forms (end-user views) -->
|
||||||
|
|
||||||
<page
|
<page
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2014 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -20,12 +20,13 @@
|
||||||
Classes for form presentation and processing.
|
Classes for form presentation and processing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from urllib import urlencode
|
||||||
|
from zope.app.container.contained import ObjectRemovedEvent
|
||||||
from zope import component, interface, schema
|
from zope import component, interface, schema
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.event import notify
|
from zope.event import notify
|
||||||
from zope.interface import Interface
|
from zope.interface import Interface
|
||||||
from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
|
from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
|
||||||
|
|
||||||
from zope.app.container.interfaces import INameChooser
|
from zope.app.container.interfaces import INameChooser
|
||||||
from zope.app.container.contained import ObjectAddedEvent
|
from zope.app.container.contained import ObjectAddedEvent
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
|
@ -35,7 +36,7 @@ from zope.publisher.browser import FileUpload
|
||||||
from zope.publisher.interfaces import BadRequest
|
from zope.publisher.interfaces import BadRequest
|
||||||
from zope.security.interfaces import ForbiddenAttribute, Unauthorized
|
from zope.security.interfaces import ForbiddenAttribute, Unauthorized
|
||||||
from zope.security.proxy import isinstance, removeSecurityProxy
|
from zope.security.proxy import isinstance, removeSecurityProxy
|
||||||
from zope.traversing.api import getName
|
from zope.traversing.api import getName, getParent
|
||||||
|
|
||||||
from cybertools.ajax import innerHtml
|
from cybertools.ajax import innerHtml
|
||||||
from cybertools.browser.form import FormController
|
from cybertools.browser.form import FormController
|
||||||
|
@ -68,6 +69,25 @@ from loops.util import _
|
||||||
from loops.versioning.interfaces import IVersionable
|
from loops.versioning.interfaces import IVersionable
|
||||||
|
|
||||||
|
|
||||||
|
# delete object
|
||||||
|
|
||||||
|
class DeleteObject(NodeView):
|
||||||
|
|
||||||
|
isTopLevel = True
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
# todo: check permission; check security code
|
||||||
|
form = self.request.form
|
||||||
|
obj = util.getObjectForUid(form['uid'])
|
||||||
|
container = getParent(obj)
|
||||||
|
notify(ObjectRemovedEvent(obj))
|
||||||
|
del container[getName(obj)]
|
||||||
|
message = 'The object requested has been deleted.'
|
||||||
|
params = [('loops.message', message.encode('UTF-8'))]
|
||||||
|
nextUrl = '%s?%s' % (self.request.URL[-1], urlencode(params))
|
||||||
|
return self.request.response.redirect(nextUrl)
|
||||||
|
|
||||||
|
|
||||||
# forms
|
# forms
|
||||||
|
|
||||||
class ObjectForm(NodeView):
|
class ObjectForm(NodeView):
|
||||||
|
|
|
@ -27,7 +27,7 @@ from zope.security import checkPermission
|
||||||
|
|
||||||
from cybertools.browser.action import actions
|
from cybertools.browser.action import actions
|
||||||
from cybertools.tracking.btree import TrackingStorage
|
from cybertools.tracking.btree import TrackingStorage
|
||||||
from loops.browser.action import DialogAction
|
from loops.browser.action import Action, DialogAction
|
||||||
from loops.browser.common import BaseView
|
from loops.browser.common import BaseView
|
||||||
from loops.browser.form import ObjectForm, EditObject
|
from loops.browser.form import ObjectForm, EditObject
|
||||||
from loops.browser.node import NodeView
|
from loops.browser.node import NodeView
|
||||||
|
@ -101,7 +101,20 @@ class CommentsView(NodeView):
|
||||||
stateful=comment.track,
|
stateful=comment.track,
|
||||||
url=url,
|
url=url,
|
||||||
onClick=onClick)
|
onClick=onClick)
|
||||||
return [stateAct]
|
actions = [stateAct]
|
||||||
|
if not checkPermission('loops.EditRestricted', self.context):
|
||||||
|
return actions
|
||||||
|
baseUrl = self.page.virtualTargetUrl
|
||||||
|
url = '%s/delete_object?uid=%s' % (baseUrl, trackUid)
|
||||||
|
onClick = _("return confirm('Do you really want to delete this object?')")
|
||||||
|
delAct = Action(self,
|
||||||
|
url=url,
|
||||||
|
description=_('Delete Comment'),
|
||||||
|
icon='cybertools.icons/delete.png',
|
||||||
|
cssClass='icon-action',
|
||||||
|
onClick=onClick)
|
||||||
|
actions.append(delAct)
|
||||||
|
return actions
|
||||||
|
|
||||||
|
|
||||||
class CommentDetails(TrackDetails):
|
class CommentDetails(TrackDetails):
|
||||||
|
|
|
@ -62,6 +62,7 @@ class StateAction(Action):
|
||||||
|
|
||||||
url = None
|
url = None
|
||||||
definition = None
|
definition = None
|
||||||
|
cssClass = 'icon-action'
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def stateful(self):
|
def stateful(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue