11391aa9a1ff6a9131c5781a2a2f9f03953b8dd7
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.
14 from AccessControl
import ClassSecurityInfo
, Unauthorized
15 from Globals
import InitializeClass
16 from zExceptions
import NotFound
17 from zope
.component
.factory
import Factory
18 from BTrees
.OOBTree
import OOSet
19 from Products
.CMFCore
.permissions
import ModifyPortalContent
, View
20 from Products
.CMFCore
.utils
import getToolByName
21 from Products
.Plinn
.HugePlinnFolder
import HugePlinnFolder
22 from random
import randrange
25 class Portfolio(HugePlinnFolder
) :
26 """ Container for photos """
28 security
= ClassSecurityInfo()
30 def __init__( self
, id, title
='' ) :
31 super__init__
= super(Portfolio
, self
).__init
__
32 super__init__(id, title
=title
)
33 self
.samplePhotoPath
= None
34 self
.presentation_page
= None
37 security
.declareProtected(View
, 'randomPhoto')
38 def randomPhoto(self
):
39 " return a ramdom photo or None "
40 ctool
= getToolByName(self
, 'portal_catalog')
41 res
= ctool(path
= '/'.join(self
.getPhysicalPath()),
45 brain
= res
[randrange(length
)]
46 infos
= { 'src' : '%s/getThumbnail' % brain
.getURL()
47 , 'alt' : brain
.Title
}
48 size
= brain
.getThumbnailSize
54 security
.declareProtected(ModifyPortalContent
, 'setSamplePhoto')
55 def setSamplePhoto(self
, photoPath
):
56 """ set photo used to represents portfolio content.
58 self
.samplePhotoPath
= photoPath
61 security
.declareProtected(View
, 'samplePhoto')
62 def samplePhoto(self
):
63 """ returns sample photo or random photo if not found.
65 if self
.samplePhotoPath
is None :
66 return self
.randomPhoto()
69 sample
= self
.restrictedTraverse(self
.samplePhotoPath
)
70 infos
= { 'src' : '%s/getThumbnail' % sample
.absolute_url()
71 , 'alt' : sample
.Title()}
72 size
= sample
.getThumbnailSize()
76 except (KeyError, NotFound
) :
77 self
.samplePhotoPath
= None
78 return self
.randomPhoto()
80 return self
.randomPhoto()
82 security
.declareProtected(View
, 'hasPresentationPage')
83 def hasPresentationPage(self
):
84 return self
.presentation_page
is not None
87 security
.declareProtected(ModifyPortalContent
, 'createPresentationPage')
88 def createPresentationPage(self
):
89 #create a presentation page
90 self
.presentation_page
= ''
93 security
.declareProtected(ModifyPortalContent
, 'deletePresentationPage')
94 def deletePresentationPage(self
):
95 self
.presentation_page
= None
99 security
.declareProtected(ModifyPortalContent
, 'editPresentationPage')
100 def editPresentationPage(self
, text
):
101 """editPresentationPage documentation
103 self
.presentation_page
= text
107 security
.declareProtected(View
, 'SearchableText')
108 def SearchableText(self
):
109 base
= super(Portfolio
, self
).SearchableText()
110 if self
.hasPresentationPage() :
111 return '%s %s' % (base
, self
.presentation_page
)
117 InitializeClass(Portfolio
)
119 PortfolioFactory
= Factory(Portfolio
)