| 1 | ################################################################################
|
|---|
| 2 | # zmstrashcan.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | from App.special_dtml import HTMLFile
|
|---|
| 21 | import copy
|
|---|
| 22 | import string
|
|---|
| 23 | import time
|
|---|
| 24 | import urllib
|
|---|
| 25 | # Product Imports.
|
|---|
| 26 | from zmscontainerobject import ZMSContainerObject
|
|---|
| 27 | import _globals
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | ################################################################################
|
|---|
| 31 | ################################################################################
|
|---|
| 32 | ###
|
|---|
| 33 | ### Class
|
|---|
| 34 | ###
|
|---|
| 35 | ################################################################################
|
|---|
| 36 | ################################################################################
|
|---|
| 37 | class ZMSTrashcan(ZMSContainerObject):
|
|---|
| 38 |
|
|---|
| 39 | # Properties.
|
|---|
| 40 | # -----------
|
|---|
| 41 | meta_type = meta_id = "ZMSTrashcan"
|
|---|
| 42 | icon = "misc_/zms/ZMSTrashcan.gif"
|
|---|
| 43 | icon_disabled = "misc_/zms/ZMSTrashcan_disabled.gif"
|
|---|
| 44 |
|
|---|
| 45 | # Management Options.
|
|---|
| 46 | # -------------------
|
|---|
| 47 | manage_options = (
|
|---|
| 48 | {'label': 'TYPE_ZMSTRASHCAN', 'action': 'manage_main'},
|
|---|
| 49 | {'label': 'TAB_PROPERTIES', 'action': 'manage_properties'},
|
|---|
| 50 | )
|
|---|
| 51 |
|
|---|
| 52 | # Management Permissions.
|
|---|
| 53 | # -----------------------
|
|---|
| 54 | __authorPermissions__ = (
|
|---|
| 55 | 'manage','manage_main','manage_workspace',
|
|---|
| 56 | 'manage_eraseObjs','manage_moveObjUp','manage_moveObjDown','manage_cutObjects',
|
|---|
| 57 | 'manage_ajaxDragDrop','manage_ajaxZMIActions',
|
|---|
| 58 | 'manage_userForm','manage_user',
|
|---|
| 59 | )
|
|---|
| 60 | __ac_permissions__=(
|
|---|
| 61 | ('ZMS Author', __authorPermissions__),
|
|---|
| 62 | )
|
|---|
| 63 |
|
|---|
| 64 | # Management Interface.
|
|---|
| 65 | # ---------------------
|
|---|
| 66 | manage_properties = HTMLFile('dtml/ZMSTrashcan/manage_properties', globals())
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | """
|
|---|
| 70 | ############################################################################
|
|---|
| 71 | ###
|
|---|
| 72 | ### Constructor
|
|---|
| 73 | ###
|
|---|
| 74 | ############################################################################
|
|---|
| 75 | """
|
|---|
| 76 |
|
|---|
| 77 | ############################################################################
|
|---|
| 78 | # ZMSTrashcan.__init__:
|
|---|
| 79 | #
|
|---|
| 80 | # Constructor (initialise a new instance of ZMSTrashcan).
|
|---|
| 81 | ############################################################################
|
|---|
| 82 | def __init__(self):
|
|---|
| 83 | """ ZMSTrashcan.__init__ """
|
|---|
| 84 | id = 'trashcan'
|
|---|
| 85 | sort_id = 0
|
|---|
| 86 | ZMSContainerObject.__init__(self,id,sort_id)
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | # --------------------------------------------------------------------------
|
|---|
| 90 | # ZMSTrashcan.display_icon:
|
|---|
| 91 | #
|
|---|
| 92 | # @param REQUEST
|
|---|
| 93 | # --------------------------------------------------------------------------
|
|---|
| 94 | def display_icon(self, REQUEST, meta_type=None, key='icon'):
|
|---|
| 95 | obj_type = meta_type
|
|---|
| 96 | if obj_type is None:
|
|---|
| 97 | if not self.isActive(REQUEST):
|
|---|
| 98 | key = 'icon_disabled'
|
|---|
| 99 | obj_type = self.meta_id
|
|---|
| 100 | return getattr(self,key)
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | """
|
|---|
| 104 | ############################################################################
|
|---|
| 105 | ###
|
|---|
| 106 | ### Properties
|
|---|
| 107 | ###
|
|---|
| 108 | ############################################################################
|
|---|
| 109 | """
|
|---|
| 110 |
|
|---|
| 111 | ############################################################################
|
|---|
| 112 | # ZMSTrashcan.manage_changeProperties:
|
|---|
| 113 | #
|
|---|
| 114 | # Change properties.
|
|---|
| 115 | ############################################################################
|
|---|
| 116 | def manage_changeProperties(self, lang, REQUEST=None):
|
|---|
| 117 | """ ZMSTrashcan.manage_changeProperties """
|
|---|
| 118 |
|
|---|
| 119 | if REQUEST.get('btn','') in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
|
|---|
| 120 | return REQUEST.RESPONSE.redirect('manage_main?lang=%s'%lang)
|
|---|
| 121 |
|
|---|
| 122 | ##### Garbage Collection #####
|
|---|
| 123 | setattr(self,'garbage_collection',REQUEST.get('garbage_collection',''))
|
|---|
| 124 | self.run_garbage_collection(forced=1)
|
|---|
| 125 |
|
|---|
| 126 | # Return with message.
|
|---|
| 127 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 128 | if REQUEST and hasattr(REQUEST,'RESPONSE'):
|
|---|
| 129 | if REQUEST.RESPONSE:
|
|---|
| 130 | return REQUEST.RESPONSE.redirect('manage_properties?lang=%s&manage_tabs_message=%s'%(lang,urllib.quote(message)))
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 | # --------------------------------------------------------------------------
|
|---|
| 134 | # ZMSTrashcan.run_garbage_collection:
|
|---|
| 135 | #
|
|---|
| 136 | # Runs garbage collection.
|
|---|
| 137 | # --------------------------------------------------------------------------
|
|---|
| 138 | def run_garbage_collection(self, forced=0):
|
|---|
| 139 | now = time.time()
|
|---|
| 140 | last_run = getattr(self,'last_garbage_collection',None)
|
|---|
| 141 | if forced or \
|
|---|
| 142 | last_run is None or \
|
|---|
| 143 | _globals.daysBetween(last_run,now)>1:
|
|---|
| 144 | #-- Get days.
|
|---|
| 145 | days = getattr(self,'garbage_collection','2')
|
|---|
| 146 | try: days = int(days)
|
|---|
| 147 | except: return
|
|---|
| 148 | #-- Get IDs.
|
|---|
| 149 | ids = []
|
|---|
| 150 | for ob in self.objectValues(self.dGlobalAttrs.keys()):
|
|---|
| 151 | delete = True
|
|---|
| 152 | for lang in self.getLangIds():
|
|---|
| 153 | req = {'lang':lang,'preview':'preview'}
|
|---|
| 154 | change_dt = ob.getObjProperty('change_dt',req)
|
|---|
| 155 | if change_dt is not None:
|
|---|
| 156 | try:
|
|---|
| 157 | delete = delete and _globals.daysBetween(change_dt,now)>days
|
|---|
| 158 | except:
|
|---|
| 159 | delete = True
|
|---|
| 160 | if delete:
|
|---|
| 161 | ids.append(ob.id)
|
|---|
| 162 | #-- Delete objects.
|
|---|
| 163 | self.manage_delObjects(ids=ids)
|
|---|
| 164 | #-- Update time-stamp.
|
|---|
| 165 | setattr(self,'last_garbage_collection',now)
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | # --------------------------------------------------------------------------
|
|---|
| 169 | # ZMSTrashcan._verifyObjectPaste:
|
|---|
| 170 | #
|
|---|
| 171 | # Overrides _verifyObjectPaste of OFS.CopySupport.
|
|---|
| 172 | # --------------------------------------------------------------------------
|
|---|
| 173 | def _verifyObjectPaste(self, object, validate_src=1):
|
|---|
| 174 | return
|
|---|
| 175 |
|
|---|
| 176 | # --------------------------------------------------------------------------
|
|---|
| 177 | # ZMSTrashcan.getDCCoverage:
|
|---|
| 178 | #
|
|---|
| 179 | # Overrides getDCCoverage of ZMSObject.
|
|---|
| 180 | # --------------------------------------------------------------------------
|
|---|
| 181 | def getDCCoverage(self, REQUEST={}):
|
|---|
| 182 | return 'global.'+self.getPrimaryLanguage()
|
|---|
| 183 |
|
|---|
| 184 | # --------------------------------------------------------------------------
|
|---|
| 185 | # ZMSTrashcan.isActive
|
|---|
| 186 | # --------------------------------------------------------------------------
|
|---|
| 187 | def isActive(self, REQUEST):
|
|---|
| 188 | return len(self.getChildNodes(REQUEST))>0
|
|---|
| 189 |
|
|---|
| 190 | # --------------------------------------------------------------------------
|
|---|
| 191 | # ZMSTrashcan.isPage
|
|---|
| 192 | # --------------------------------------------------------------------------
|
|---|
| 193 | def isPage(self):
|
|---|
| 194 | return False
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | # --------------------------------------------------------------------------
|
|---|
| 198 | # ZMSObject.isPageContainer:
|
|---|
| 199 | # --------------------------------------------------------------------------
|
|---|
| 200 | def isPageContainer(self):
|
|---|
| 201 | return True
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 | # --------------------------------------------------------------------------
|
|---|
| 205 | # ZMSTrashcan.getObjProperty
|
|---|
| 206 | # --------------------------------------------------------------------------
|
|---|
| 207 | def getObjProperty(self, key, REQUEST={}, par=None):
|
|---|
| 208 | return ''
|
|---|
| 209 |
|
|---|
| 210 | # --------------------------------------------------------------------------
|
|---|
| 211 | # ZMSTrashcan.getTitle
|
|---|
| 212 | # --------------------------------------------------------------------------
|
|---|
| 213 | def getTitle(self, REQUEST):
|
|---|
| 214 | return self.display_type(REQUEST) + " (" + str(len(self.getChildNodes(REQUEST))) + " " + self.getLangStr('ATTR_OBJECTS',REQUEST['lang']) + ")"
|
|---|
| 215 |
|
|---|
| 216 | ################################################################################ |
|---|