Added support for deleting assets to trash
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from .connection import Connection, CrxException, CrxNodeNotFound
|
from .connection import Connection, CrxException, CrxNodeNotFound, CrxCantDeleteAsset
|
||||||
from .simplenode import SimpleNode
|
from .simplenode import SimpleNode
|
||||||
from .util import get_simple_con
|
from .util import get_simple_con
|
||||||
|
|
||||||
__version__ = (1, 0, 0, 0)
|
__version__ = (1, 0, 0, 0)
|
||||||
|
|
||||||
__all__ = ["Connection", "CrxException", "CrxNodeNotFound", "SimpleNode", "get_simple_con"]
|
__all__ = ["Connection", "CrxException", "CrxNodeNotFound", "SimpleNode", "get_simple_con", "CrxCantDeleteAsset"]
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ Download:
|
|||||||
http://app30-prd-asd.sbnl.vancis.nl:4502/crx/server/crx.default/jcr:root/content/dam/beeldbank/vrouw-direct-naar.jpg/jcr:content/renditions/original/jcr:content/jcr:data
|
http://app30-prd-asd.sbnl.vancis.nl:4502/crx/server/crx.default/jcr:root/content/dam/beeldbank/vrouw-direct-naar.jpg/jcr:content/renditions/original/jcr:content/jcr:data
|
||||||
OR
|
OR
|
||||||
download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Acontent%2Frenditions%2Foriginal%2Fjcr%3Acontent%2Fjcr%3Adata&index=0
|
download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Acontent%2Frenditions%2Foriginal%2Fjcr%3Acontent%2Fjcr%3Adata&index=0
|
||||||
|
|
||||||
|
Delete asset via trash
|
||||||
|
/bin/wcmcommand --data "path="%"2Fcontent"%"2Fdam"%"2Flandelijk"%"2Fjeugdbibliotheek15-18"%"2F615.swf&_charset_=utf-8&cmd=deletePage&force=true"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
||||||
@@ -28,6 +31,7 @@ CRX_QUERY = '/crx/de/query.jsp'
|
|||||||
PACKMGR_EXEC = '/crx/packmgr/service/exec.json'
|
PACKMGR_EXEC = '/crx/packmgr/service/exec.json'
|
||||||
PACKMGR_UPDATE = '/crx/packmgr/update.jsp'
|
PACKMGR_UPDATE = '/crx/packmgr/update.jsp'
|
||||||
|
|
||||||
|
WCM_COMMAND = '/bin/wcmcommand'
|
||||||
WCM_REFERENCES = '/bin/wcm/references.json'
|
WCM_REFERENCES = '/bin/wcm/references.json'
|
||||||
WCM_PAGE_REFERENCES = '/libs/wcm/core/content/reference.json'
|
WCM_PAGE_REFERENCES = '/libs/wcm/core/content/reference.json'
|
||||||
WCM_REPLICATE = '/bin/replicate.json'
|
WCM_REPLICATE = '/bin/replicate.json'
|
||||||
@@ -56,6 +60,12 @@ class CrxNodeNotFound(CrxException):
|
|||||||
self.response = response
|
self.response = response
|
||||||
|
|
||||||
|
|
||||||
|
class CrxCantDeleteAsset(CrxException):
|
||||||
|
def __init__(self, response_body: str, message: str):
|
||||||
|
super(CrxCantDeleteAsset, self).__init__(message)
|
||||||
|
self.response = response_body
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
host: str = 'localhost',
|
host: str = 'localhost',
|
||||||
@@ -177,6 +187,26 @@ class Connection:
|
|||||||
resp = self._session.post(url, files=files)
|
resp = self._session.post(url, files=files)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
def delete_asset(self, dam_path: str, force: bool = False):
|
||||||
|
"""
|
||||||
|
Delete an asset to the trash. If force is False (default) don't delete it if it has remaining references
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dam_path: The path of the asset to delete
|
||||||
|
force: Whether or not to force delete it.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True when the asset has been deleted
|
||||||
|
|
||||||
|
Raises CrxCantDeleteAsset:
|
||||||
|
When the asset can't be deleted (for example, insufficient rights or remaining references without force)
|
||||||
|
"""
|
||||||
|
url: str = self._host + WCM_COMMAND
|
||||||
|
response = self._session.post(url, data={'path': dam_path, 'cmd': 'deletePage', 'force': json.dumps(force)})
|
||||||
|
if not response.ok:
|
||||||
|
raise CrxCantDeleteAsset(response.text, response.reason)
|
||||||
|
return True
|
||||||
|
|
||||||
def get_node_raw(self, path: str):
|
def get_node_raw(self, path: str):
|
||||||
"""
|
"""
|
||||||
Get the raw JSON dictionary of a node.
|
Get the raw JSON dictionary of a node.
|
||||||
|
|||||||
Reference in New Issue
Block a user