1501cb5551dc072d5131fcc7dcdc846fc66809b6
1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2005-2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
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 """ container classes for photo storage.
12 $Id: container.py 622 2008-11-16 23:38:18Z pin $
13 $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/container.py $
16 from AccessControl
import ClassSecurityInfo
, Unauthorized
17 from Globals
import InitializeClass
18 from zExceptions
import NotFound
19 from zope
.component
.factory
import Factory
20 from BTrees
.OOBTree
import OOSet
21 from Products
.CMFCore
.permissions
import ModifyPortalContent
, View
22 from Products
.CMFCore
.utils
import getToolByName
23 from Products
.Plinn
.HugePlinnFolder
import HugePlinnFolder
24 from random
import randrange
27 class Portfolio(HugePlinnFolder
) :
28 """ Container for photos """
30 security
= ClassSecurityInfo()
32 def __init__( self
, id, title
='' ) :
33 super__init__
= super(Portfolio
, self
).__init
__
34 super__init__(id, title
=title
)
35 self
.samplePhotoPath
= None
36 self
.presentation_page
= None
39 security
.declareProtected(View
, 'randomPhoto')
40 def randomPhoto(self
):
41 " return a ramdom photo or None "
42 ctool
= getToolByName(self
, 'portal_catalog')
43 res
= ctool(path
= '/'.join(self
.getPhysicalPath()),
47 brain
= res
[randrange(length
)]
48 infos
= { 'src' : '%s/getThumbnail' % brain
.getURL()
49 , 'alt' : brain
.Title
}
50 size
= brain
.getThumbnailSize
56 security
.declareProtected(ModifyPortalContent
, 'setSamplePhoto')
57 def setSamplePhoto(self
, photoPath
):
58 """ set photo used to represents portfolio content.
60 self
.samplePhotoPath
= photoPath
63 security
.declareProtected(View
, 'samplePhoto')
64 def samplePhoto(self
):
65 """ returns sample photo or random photo if not found.
67 if self
.samplePhotoPath
is None :
68 return self
.randomPhoto()
71 sample
= self
.restrictedTraverse(self
.samplePhotoPath
)
72 infos
= { 'src' : '%s/getThumbnail' % sample
.absolute_url()
73 , 'alt' : sample
.Title()}
74 size
= sample
.getThumbnailSize()
78 except (KeyError, NotFound
) :
79 self
.samplePhotoPath
= None
80 return self
.randomPhoto()
82 return self
.randomPhoto()
84 security
.declareProtected(View
, 'hasPresentationPage')
85 def hasPresentationPage(self
):
86 return self
.presentation_page
is not None
89 security
.declareProtected(ModifyPortalContent
, 'createPresentationPage')
90 def createPresentationPage(self
):
91 #create a presentation page
92 self
.presentation_page
= ''
95 security
.declareProtected(ModifyPortalContent
, 'deletePresentationPage')
96 def deletePresentationPage(self
):
97 self
.presentation_page
= None
101 security
.declareProtected(ModifyPortalContent
, 'editPresentationPage')
102 def editPresentationPage(self
, text
):
103 """editPresentationPage documentation
105 self
.presentation_page
= text
109 security
.declareProtected(View
, 'SearchableText')
110 def SearchableText(self
):
111 base
= super(Portfolio
, self
).SearchableText()
112 if self
.hasPresentationPage() :
113 return '%s %s' % (base
, self
.presentation_page
)
119 InitializeClass(Portfolio
)
121 PortfolioFactory
= Factory(Portfolio
)