962d913eeba19f8eb1df8cc457aaadb13ebe65f1
[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 $Id: lightbox.py 622 2008-11-16 23:38:18Z pin $
14 $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/lightbox.py $
15 """
16
17 from Globals import InitializeClass
18 from AccessControl import ClassSecurityInfo
19 from Products.CMFCore.permissions import View, ModifyPortalContent
20 from Products.CMFCore.PortalContent import PortalContent
21 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
22 from zope.component.factory import Factory
23
24 class Lightbox( PortalContent, DefaultDublinCoreImpl):
25 "lightbox holds references to photos"
26
27 security = ClassSecurityInfo()
28
29 def __init__( self, id, title='', uids=[], description=''):
30 DefaultDublinCoreImpl.__init__(self)
31 self.id=id
32 self.uids = tuple(uids)
33 self._editMetadata(title=title, description=description)
34
35 security.declareProtected(View, 'getUidList')
36 def getUidList(self):
37 return list(self.uids)
38
39 security.declareProtected(ModifyPortalContent, 'append')
40 def append(self, uid):
41 if uid not in self.uids :
42 self.uids = self.uids + (uid,)
43 self.notifyModified()
44 self.reindexObject(idxs=['modified'])
45 return True
46 else :
47 return False
48
49 security.declareProtected(ModifyPortalContent, 'extend')
50 def extend(self, uids):
51 already = 0
52 new = []
53 for uid in uids :
54 if uid not in self.uids :
55 new.append(uid)
56 else :
57 already = already + 1
58 self.uids = self.uids + tuple(new)
59 if len(already < uids) :
60 self.notifyModified()
61 self.reindexObject(idxs=['modified'])
62 return already
63
64 security.declareProtected(ModifyPortalContent, 'pop')
65 def pop(self, index=None):
66 i = index
67 if i is None :
68 i = len(self.uids) -1
69
70 self.uids = self.uids[:i] + self.uids[i+1:]
71
72 self.notifyModified()
73 self.reindexObject(idxs=['modified'])
74
75 security.declareProtected(ModifyPortalContent, 'remove')
76 def remove(self, value):
77 for i, v in enumerate(self.uids) :
78 if value == v :
79 self.pop(i)
80 break
81 else :
82 return
83 self.notifyModified()
84 self.reindexObject(idxs=['modified'])
85
86 InitializeClass(Lightbox)
87
88 LightboxFactory = Factory(Lightbox)