The document title or folder title or the example title
The title
Welcome to Zope. We've collected some example applications
that demonstrate simple Zope features. You can examine how
these applications work by looking at them in the
management interface. If you'd like to
contribute an example application to add to this collection,
write to us. Enjoy!
You can delete the Examples folder if you wish. You
can also reload the examples by importing the import/Examples.zexp
file.
qUcontent_typeqU text/htmlqUtitleqU u. ] ’((U
OFS.FolderqUFolderqtqNt.}q(UidqUFileLibraryqU__ac_local_roles__q}qUamosq ]q
UOwnerqasU_objectsq(}q
(U meta_typeqU
Page TemplateqhU
index_htmlqu}q(hUFolderqhUFilesqu}q(hUScript (Python)qhUgetFilesqu}q(hhhUgetLinkqu}q(hhhUgetSizequ}q(hhhUaddFilequtUgetLinkq(U iq(U#Products.PythonScripts.PythonScriptqUPythonScriptq ttQUgetSizeq!(U jq"(hUPythonScriptq#ttQU
index_htmlq$(U lq%(U'Products.PageTemplates.ZopePageTemplateq&UZopePageTemplateq'ttQh(U kq((hUPythonScriptq)ttQUtitleq*UFile Libraryq+h(U hq,(hUPythonScriptq-ttQh(U gq.(hUFolderq/ttQu. [ ¬((U
OFS.FolderqUFolderqtqNt.}q(UaddItemsq(U fq(U#Products.PythonScripts.PythonScriptqUPythonScriptqttQUidq UShoppingCartq
U__ac_local_roles__q}qUamosq
]qUOwnerqasU_objectsq(}q(U meta_typeqUScript (Python)qh UcurrentItemsqu}q(hhh UgetItemqu}q(hhh UgetTotalqu}q(hU
Page Templateqh U
index_htmlqu}q(U meta_typeqUScript (Python)qUidqUdeleteItemsq u}q!(hhhhuth(U cq"(hUPythonScriptq#ttQU
index_htmlq$(U eq%(U'Products.PageTemplates.ZopePageTemplateq&UZopePageTemplateq'ttQh(U dq((hUPythonScriptq)ttQUtitleq*U
Shopping Cartq+h (U bq,(hUPythonScriptq-ttQh(U aq.(hUPythonScriptq/ttQu. ` ž((U
OFS.FolderqUFolderqtqNt.}q(UidqU GuestBookqU__ac_local_roles__q}qUamosq ]q
UOwnerqasU_objectsq(}q
(U meta_typeqU
Page TemplateqhU
index_htmlqu}q(hUFolderqhUEntriesqu}q(hhhU
addEntry.htmlqu}q(U meta_typeqUScript (Python)qUidqUaddEntryqu}q(hhhUformatEntryqu}q(hhhU
getEntriesquth(U vq(hUFolderq ttQU
index_htmlq!(U wq"(U'Products.PageTemplates.ZopePageTemplateq#UZopePageTemplateq$ttQh(U xq%(h#UZopePageTemplateq&ttQUtitleq'U
Guest Bookq(h(U tq)(U#Products.PythonScripts.PythonScriptq*UPythonScriptq+ttQh(U sq,(h*UPythonScriptq-ttQh(U uq.(h*UPythonScriptq/ttQu. p ((U
OFS.FolderqUFolderqtqNt.}q(UidqUBirdsqU__ac_local_roles__q}qUamosq ]q
UOwnerqasUPigeonsq(U q
(hUFolderqtqtqQU_objectsq(}q(U meta_typeqUFolderqhUCrowsqu}q(hhhhutUtitleqU h(U ~q(hUFolderqtqtqQu. m r((U
OFS.FolderqUFolderqtqNt.}q(UtitleqU UidqUReptilesqU__ac_local_roles__q}q Uamosq
]qUOwnerqasu. r œ((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_argcountq K Uco_varnamesq
(U _getitem_qU_getitemqU _getattr_q
U_getattrqUProducts.PythonScripts.standardqU
html_quoteqUlinksqUcontextqUparentqtubU_paramsqU UidqUbreadcrumbs.pyqU__ac_local_roles__q}qUamosq]qUOwnerqasU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq }q!(Uname_containerq"U containerq#Uname_subpathq$Utraverse_subpathq%Uname_m_selfq&Uscriptq'Uname_contextq(Ucontextq)usbU
func_defaultsq*NU_codeq+Tð c s d „ Z d S( s°
This script creates breadcrumb style navigation links.
It walks the REQUEST.PARENTS list of parents and creates
a hyperlink for each parent. It stops at the Examples folder.
c
sñ t } t } d d k l } g }
x¢ | | | t d ƒ d ƒ d d … ƒ d
rt } | | d ƒ d d | | | d ƒ ƒ ƒ | | | d
ƒ ƒ ƒ f ƒ
| | d
ƒ ƒ d j o Pn q\ W | d d
ƒ | ƒ Sd S( s°
This script creates breadcrumb style navigation links.
It walks the REQUEST.PARENTS list of parents and creates
a hyperlink for each parent. It stops at the Examples folder.
( s
html_quotes REQUESTs PARENTSi Ni s inserts %ss absolute_urls getIds Exampless /s join( s _getitem_s _getitems _getattr_s _getattrs Products.PythonScripts.standards
html_quotes linkss contexts parent( s _getitem_s _getitems _getattr_s _getattrs Products.PythonScripts.standards
html_quotes linkss contexts parent( ( s Script (Python)s breadcrumbs.py s 95N( s breadcrumbs.py( s breadcrumbs.py( ( s Script (Python)s s q,U_bodyq-Tñ """
This script creates breadcrumb style navigation links.
It walks the REQUEST.PARENTS list of parents and creates
a hyperlink for each parent. It stops at the Examples folder.
"""
from Products.PythonScripts.standard import html_quote
links=[]
for parent in context.REQUEST.PARENTS[1:]:
links.insert(0, """%s""" % \
(html_quote(parent.absolute_url()), html_quote(parent.getId())))
if parent.getId() == "Examples":
break
return "/".join(links)
q.UScript_magicq/KUwarningsq0)Uerrorsq1)UPython_magicq2U*ë
q3u. q q((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UexpandqKUidqU
index_htmlqU__ac_local_roles__q}q Uamosq
]qUOwnerqasU_textq
T%
The document title or container title
breadcrumbs
navigation
The title
This example shows how to create simple automatic navigation
devices. Take a look at the Navigation folder to see how
it was built. The automatically created links on this page allow you
to traverse a collection of folders and sub-folders.
Current Folder: Folder ID
Parent Links
The links you see across the top of the page are called breadcrumbs.
They show you where you are in the site and let you navigate up
the site tree. They are created with a Python-based script,
breadcrumbs.py.
Child Links
These automatic links allow you to navigate deeper into the
site. These links are created with a Python expression in a
Page Template. You could also use a Python-based Script to
create the links.
You could customize these links to only show certain
sub-folders,
rather than listing all sub-folders.
This navigation device allows you to go to sibling folders.
A sibling folder is one that is in the same parent as the
current folder. The list of siblings is generated by the
siblings.py script.
qU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq}qUname_subpathqUtraverse_subpathqssbUtitleqU Ucontent_typeqU text/htmlqu. o :((U
OFS.FolderqUFolderqtqNt.}q(UidqUMammalsqU__ac_local_roles__q}qUamosq ]q
UOwnerqasUPrimatesq(U }q
(hUFolderqtqtqQU_objectsq(}q(U meta_typeqUFolderqhhu}q(hhhUBatsqu}q(hhhUWhalesquth(U |q(hUFolderqtqtqQUtitleqU h(U {q(hUFolderqtq tq!Qu. n e((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_varnamesq (U _getattr_q
U_getattrqUcontextqUfoldersq
tUco_argcountqK ubU_paramsqU UidqUsiblings.pyqU__ac_local_roles__q}qUamosq]qUOwnerqasU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq}q(Uname_containerqU containerqUname_subpathqUtraverse_subpathq Uname_m_selfq!Uscriptq"Uname_contextq#Ucontextq$usbU
func_defaultsq%NU_codeq&T3 c s d „ Z d S( s/
This script returns a list of sibling folders
c sR t } d | | t d ƒ d ƒ d ƒ } | | d ƒ t ƒ | Sd S( s/
This script returns a list of sibling folders
s aq_parents objectValuess Folders removeN( s _getattr_s _getattrs contexts folders( s _getattr_s _getattrs contexts folders( ( s Script (Python)s siblings.py s $N( s siblings.py( s siblings.py( ( s Script (Python)s s q'U_bodyq(UÏ"""
This script returns a list of sibling folders
"""
# get my parent's children
folders=context.aq_parent.objectValues('Folder')
# remove me from the list of children
folders.remove(context)
return folders
q)UScript_magicq*KUwarningsq+)Uerrorsq,)UPython_magicq-U*ë
q.u. i T((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_varnamesq (Unew_sortq
UsortqUreverseqU _getattr_q
U_getattrqUcontextqUurlqUnew_reverseqtUco_argcountqKubU_paramsqUnew_sort, sort, reverseqUidqUgetLinkqU__ac_local_roles__q}qUamosq]qUOwnerqasU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq }q!(Uname_containerq"U containerq#Uname_subpathq$Utraverse_subpathq%Uname_contextq&Ucontextq'Uname_m_selfq(Uscriptq)usbU
func_defaultsq*NU_codeq+TÆ c s d „ Z d S( sA
Returns a URL which gives sorting commands in the query string.
c sj t } d | | t d ƒ d ƒ } | | j o
d } n | } d | | | f Sd S( sA
Returns a URL which gives sorting commands in the query string.
s REQUESTs URL0i s %s?sort=%s&reverse:int=%sN( s _getattr_s _getattrs contexts urls new_sorts sorts new_reverses reverse( s new_sorts sorts reverses _getattr_s _getattrs contexts urls new_reverse( ( s Script (Python)s getLink s
N( s getLink( s getLink( ( s Script (Python)s s q,U_bodyq-Uì"""
Returns a URL which gives sorting commands in the query string.
"""
url=context.REQUEST.URL0
if new_sort != sort:
new_reverse=0
else:
new_reverse=not reverse
return "%s?sort=%s&reverse:int=%s" % (url, new_sort, new_reverse)
q.UScript_magicq/KUwarningsq0)Uerrorsq1)UPython_magicq2U*ë
q3u. j (((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_varnamesq (Ubytesq
UmegsqUktUco_argcountqKubU_paramsq
UbytesqUidqUgetSizeqU__ac_local_roles__q}qUamosq]qUOwnerqasU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq}q(Uname_containerqU containerqUname_subpathqUtraverse_subpathqUname_contextq Ucontextq!Uname_m_selfq"Uscriptq#usbU
func_defaultsq$NU_codeq%T c s d „ Z d S( s.
Format a number of bytes as bytes, K, or MB.
c sq d | d } | d j o d | Sn | d } | d j o d | Sn
d | Sd S( s.
Format a number of bytes as bytes, K, or MB.
f 1048576.0i s %.2f MBf1024.0s %d Ks %d bytesN( s bytess megss k( s bytess megss k( ( s Script (Python)s getSize s
N( s getSize( s getSize( ( s Script (Python)s s q&U_bodyq'UÀ"""
Format a number of bytes as bytes, K, or MB.
"""
megs=bytes / 1048576.0
if megs > 1:
return "%.2f MB" % megs
k=bytes / 1024.0
if k > 1:
return "%d K" % k
return "%d bytes" % bytes
q(UScript_magicq)KUwarningsq*)Uerrorsq+)UPython_magicq,U*ë
q-u. l ‹((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UexpandqKUidqU
index_htmlqU__ac_local_roles__q}q Uamosq
]qUOwnerqasU_bind_namesq
(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq}qUname_subpathqUtraverse_subpathqssbU_textqT?
The document title or folder title or the example title
The title
This example shows how to create a simple file library. It demonstrates
batching and sorting. You can click on the column names to sort the files.
If you click twice on a column then the files are sorted in reverse order.
If you upload more than eight files, then the results will be split up over
more than one page. This is called batching.
The files are located in the Files folder. The getFiles script
returns a sorted list of files. The getLink and getSize scripts
do small formatting tasks to build hyperlinks and format file sizes. The batching
is done in the index_html template. The template also makes use of the
test function to assign different CSS classes to elements depending on
conditions. This is how the sorted column name is bolded and alternate table
rows are made gray.
You can add a file to the library by uploading it from your local
computer. The addFile script accepts the file upload and creates a
new file object in the Files folder. It then returns this page
with a confirmation message. For demonstration purposes, only 10 files of
no larger than 2Kbytes may be uploaded.
Adding files is protected by the "Add Documents, Images and Files"
permission. If you want anonymous users to upload files, you could visit
the "Security" tab of the addFile script, and give it the
"Manager" proxy role.
qUcontent_typeqU text/htmlqUtitleqU u. k
¯((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_argcountq KUco_varnamesq
(UfileqU _getitem_qU_getitemq
U _getattr_qU_getattrqUProducts.PythonScripts.standardqU url_quoteqU ExceptionqU
LimitExceededqUhasattrqUsizeqUlenqU containerqUmessageqUcontextqtubU_paramsqUfileqUidqUaddFileqU__ac_local_roles__q}qUamosq ]q!UOwnerq"asU_bind_namesq#(cShared.DC.Scripts.Bindings
NameAssignments
q$oq%}q&U_asgnsq'}q((Uname_containerq)U containerq*Uname_subpathq+Utraverse_subpathq,Uname_contextq-Ucontextq.Uname_m_selfq/Uscriptq0usbU
func_defaultsq1NU_codeq2TÊ c s d „ Z d S( s
Adds a file to the library.
c s³ t } t } d d k l } d t f d „ ƒ Y}
t | d ƒ o
t | d ƒ o d d ‚ n | | d ƒ d d ƒ
| | d ƒ ƒ }
| | d ƒ d ƒ t | | t d
ƒ d ƒ d ƒ ƒ d
j od |
d j oD | | | | t d
ƒ d ƒ d ƒ d ƒ d d d d d | ƒ n
| d ‚ n
| d ‚ d | | d ƒ }
| | | t d ƒ d ƒ d ƒ d | t d ƒ ƒ | |
ƒ f ƒ Sd S( s
Adds a file to the library.
( s url_quotes
LimitExceededc s d RS( s$ raised when file limits are exceeded( ( ( ( s Script (Python)s
LimitExceeded s s seeks tells Bad Requests Invalid file specifiedi i s Filess objectValuess Filei
i s manage_addProducts OFSPs manage_addFiles ids s titles files( Uploaded file must be less than 2Kbytes.s% limit on number of files (5) exceededs File '%s' uploaded successfully.s filenames REQUESTs RESPONSEs redirects
%s?message=%ss absolute_urlN( s _getitem_s _getitems _getattr_s _getattrs Products.PythonScripts.standards url_quotes Exceptions
LimitExceededs hasattrs files sizes lens containers messages context( s files _getitem_s _getitems _getattr_s _getattrs Products.PythonScripts.standards url_quotes Exceptions
LimitExceededs hasattrs sizes lens containers messages context( ( s Script (Python)s addFile s $.8N( s addFile( s addFile( ( s Script (Python)s s q3U_proxy_rolesq4)U_bodyq5TÖ """
Adds a file to the library.
"""
from Products.PythonScripts.standard import url_quote
class LimitExceeded(Exception):
"""raised when file limits are exceeded"""
# create up to 10 files of 2k apiece
if not (hasattr(file, 'seek') and hasattr(file, 'tell')):
raise "Bad Request", "Invalid file specified"
file.seek(0,2)
size=file.tell()
file.seek(0) # rewind
if len(container.Files.objectValues('File')) < 10:
if size < 2048:
container.Files.manage_addProduct['OFSP'].manage_addFile(id='', title='', file=file)
else:
raise LimitExceeded, "Uploaded file must be less than 2Kbytes."
else:
raise LimitExceeded, "limit on number of files (5) exceeded"
# create a success message
message="File '%s' uploaded successfully." % file.filename
# redirect to main page - this is necessary to make all the URLs
# on the main page work correctly.
return context.REQUEST.RESPONSE.redirect("%s?message=%s" % (container.absolute_url(), url_quote(message)))
q6UScript_magicq7KUwarningsq8)Uerrorsq9)UPython_magicq:U*ë
q;u. h
?((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_varnamesq (Usortq
UreverseqU _getattr_qU_getattrq
U containerqUfilesqUargsqUsequenceqtUco_argcountqKubU_paramsqUsort='id', reverse=0qUidqUgetFilesqU__ac_local_roles__q}qUamosq]qUOwnerqasU_bind_namesq(cShared.DC.Scripts.Bindings
NameAssignments
qoq}qU_asgnsq }q!(Uname_containerq"U containerq#Uname_subpathq$Utraverse_subpathq%Uname_contextq&Ucontextq'Uname_m_selfq(Uscriptq)usbU
func_defaultsq*(Uidq+K tq,U_codeq-T‚ c s d d d „ Z d S( s;
Returns a list of files sorted by id, date, type or size.
s idi c s— t } d | | t d ƒ d ƒ d ƒ } f } | d j o7 | o
d f f } n d d d f f } nú
| d j oC | o d f d f f } n d d d f d f f } n§ | d
j oC | o d f d f f } n d d d f d f f } nT | d j oC | o d
d d f d f f } n d
f d f f } n | t d ƒ | | ƒ Sd S( s;
Returns a list of files sorted by id, date, type or size.
s Filess objectValuess Files ids getIds cmps descs dates bobobase_modification_times types getContentTypes sizes getSizes sortN( s _getattr_s _getattrs containers filess argss sorts reverses sequence( s sorts reverses _getattr_s _getattrs containers filess argss sequence( ( s Script (Python)s getFiles s( ! N( s getFiles( s getFiles( ( s Script (Python)s s q.U_bodyq/T """
Returns a list of files sorted by id, date, type or size.
"""
files=container.Files.objectValues('File')
args=()
# build arguments for sequence.sort
if sort=='id':
if not reverse:
args=(('getId',),)
else:
args=(('getId', 'cmp', 'desc'),)
elif sort=='date':
if not reverse:
args=(('bobobase_modification_time',), ('getId',))
else:
args=(('bobobase_modification_time', 'cmp', 'desc'), ('getId',))
elif sort=='type':
if not reverse:
args=(('getContentType',), ('getId',))
else:
args=(('getContentType', 'cmp', 'desc'), ('getId',))
elif sort=='size':
if not reverse:
args=(('getSize', 'cmp', 'desc'), ('getId',))
else:
args=(('getSize',), ('getId',))
return sequence.sort(files, args)
q0UScript_magicq1KUwarningsq2)Uerrorsq3)UPython_magicq4U*ë
q5u. g ((U
OFS.FolderqUFolderqtqNt.}q(UidqUFilesqU__ac_local_roles__q}qUamosq ]q
UOwnerqasUexample.htmlq(U zq
(U OFS.ImageqUFileqtqtqQU_objectsq(}q(U meta_typeqUFileqUidqUexample.txtqu}q(hhhhutUtitleqU h(U yq(hUFileqttqQu. f .((U#Products.PythonScripts.PythonScriptqUPythonScriptqtqNt.}q(U func_codeq(cShared.DC.Scripts.Signature
FuncCode
qoq}q(Uco_argcountq KUco_varnamesq
(UordersqUREQUESTqU_write_q
U_writeqU _getitem_qU_getitemqU _getattr_qU_getattrqUcontextqUsessionqUitemsqUappendqU$append0qU containerqUdUvalid_itemsqUorderqUhasattrqUintqUquantityqUNoneqtubU_paramsqUorders, REQUEST=Noneq Uidq!UaddItemsq"U__ac_local_roles__q#}q$Uamosq%]q&UOwnerq'asU_bind_namesq((cShared.DC.Scripts.Bindings
NameAssignments
q)oq*}q+U_asgnsq,}q-(Uname_containerq.U containerq/Uname_subpathq0Utraverse_subpathq1Uname_contextq2Ucontextq3Uname_m_selfq4Uscriptq5usbU
func_defaultsq6(Ntq7U_codeq8TÁ c s t d „ Z d S( sf
Adds one or more items to the shopping cart. Each
order is a record with an id and a quantity field.
c s§ t } t } t } d | | t d ƒ d ƒ } | | d ƒ d h ƒ }
g i } | t d ƒ ƒ d r } | | | d ƒ ƒ qq ~ }
xÊ | d
r½ } t | d ƒ o&