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