VC: Fix error on clone page for legacy-ID events
[cds-indico.git] / indico / MaKaC / trashCan.py
blobb876aaedf00979753d32c7ff40fd4050a79f52bf
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 import time
18 from MaKaC.common.ObjectHolders import ObjectHolder
19 from MaKaC.i18n import _
20 from indico.util.contextManager import ContextManager
22 class TrashCanManager(ObjectHolder):
23 idxName = "trashcan"
25 def add(self, newItem):
26 oid = ""
27 try:
28 oid = newItem._p_oid
29 except:
30 raise MaKaCError( _("Cannot put an object which is not persistent in the trash can."))
31 tree = self._getIdx()
32 if not (ContextManager.get('test_env')):
33 tree[oid] = newItem
35 def remove(self, item):
36 oid = ""
37 try:
38 oid = item._p_oid
39 except:
40 return
41 tree = self._getIdx()
42 if not tree.has_key(oid):
43 return
44 del tree[oid]
46 def emptyTrashCan(self, dt):
47 # Remove all the objects whose modification date is less than dt.
48 ts = time.mktime(dt.timetuple())
49 for i in self.getValuesToList():
50 if i._p_mtime < ts:
51 self.remove(i)