bugfix : « Il en manque une ! ».
[Portfolio.git] / lightbox.py
1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2005-2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
5 # #
6 # This program is free software; you can redistribute it #
7 # and/or modify it under the terms of the Creative Commons #
8 # "Attribution-Noncommercial 2.0 Generic" #
9 # http://creativecommons.org/licenses/by-nc/2.0/ #
10 ############################################################
11 """ Lightboxes contains references to images.
12 References are made with CMFUid stuff.
13 """
14
15 from Globals import InitializeClass
16 from AccessControl import ClassSecurityInfo
17 from Products.CMFCore.permissions import View, ModifyPortalContent
18 from Products.CMFCore.PortalContent import PortalContent
19 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
20 from zope.component.factory import Factory
21
22 class Lightbox( PortalContent, DefaultDublinCoreImpl):
23 "lightbox holds references to photos"
24
25 security = ClassSecurityInfo()
26
27 def __init__( self, id, title='', uids=[], description=''):
28 DefaultDublinCoreImpl.__init__(self)
29 self.id=id
30 self.uids = tuple(uids)
31 self._editMetadata(title=title, description=description)
32
33 security.declareProtected(View, 'getUidList')
34 def getUidList(self):
35 return list(self.uids)
36
37 security.declareProtected(ModifyPortalContent, 'append')
38 def append(self, uid):
39 if uid not in self.uids :
40 self.uids = self.uids + (uid,)
41 self.notifyModified()
42 self.reindexObject(idxs=['modified'])
43 return True
44 else :
45 return False
46
47 security.declareProtected(ModifyPortalContent, 'extend')
48 def extend(self, uids):
49 already = 0
50 new = []
51 for uid in uids :
52 if uid not in self.uids :
53 new.append(uid)
54 else :
55 already = already + 1
56 self.uids = self.uids + tuple(new)
57 if len(already < uids) :
58 self.notifyModified()
59 self.reindexObject(idxs=['modified'])
60 return already
61
62 security.declareProtected(ModifyPortalContent, 'pop')
63 def pop(self, index=None):
64 i = index
65 if i is None :
66 i = len(self.uids) -1
67
68 self.uids = self.uids[:i] + self.uids[i+1:]
69
70 self.notifyModified()
71 self.reindexObject(idxs=['modified'])
72
73 security.declareProtected(ModifyPortalContent, 'remove')
74 def remove(self, value):
75 for i, v in enumerate(self.uids) :
76 if value == v :
77 self.pop(i)
78 break
79 else :
80 return
81 self.notifyModified()
82 self.reindexObject(idxs=['modified'])
83
84 InitializeClass(Lightbox)
85
86 LightboxFactory = Factory(Lightbox)