ZEXP ˜Á((U OFS.FolderqUFolderqtqNt.}q(UtitleqUExample ApplicationsqU FileLibraryq(U œq(hUFolderq ttq QU Navigationq (U šq (hUFolderq ttqQU ShoppingCartq(U q(hUFolderqttqQU index_htmlq(U ›q(U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqttqQU_ownerq(]qU acl_usersqaUadminqtqU GuestBookq(U žq(hUFolderqtq tq!QU_objectsq"(}q#(U meta_typeq$U Page Templateq%Uidq&hu}q'(h$UFileq(h&U examples.cssq)u}q*(h$UFolderq+h&U Navigationq,u}q-(U meta_typeq.UFolderq/Uidq0hu}q1(U meta_typeq2UFolderq3Uidq4hu}q5(U meta_typeq6UFolderq7Uidq8hutq9U__ac_local_roles__q:}q;h&UExamplesqUFileq?ttq@Qu. œ¢((U OFS.FolderqUFolderqtqNt.}q(UFilesq(U ªq(hUFolderqtqtq QUgetFilesq (U ©q (U#Products.PythonScripts.PythonScriptq U PythonScriptq ttqQUtitleqU File LibraryqUaddFileq(U ¨q(h U PythonScriptqttqQU index_htmlq(U §q(U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqttqQUgetSizeq(U ¦q(h U PythonScriptqttqQUgetLinkq(U ¥q(h U PythonScriptq ttq!QU_objectsq"(}q#(U meta_typeq$U Page Templateq%Uidq&U index_htmlq'u}q((h$UFolderq)h&hu}q*(h$UScript (Python)q+h&h u}q,(h$h+h&UgetLinkq-u}q.(h$h+h&UgetSizeq/u}q0(h$h+h&hutq1U__ac_local_roles__q2}q3Uamosq4]q5UOwnerq6ash&U FileLibraryq7u. šË((U OFS.FolderqUFolderqtqNt.}q(UBirdsq(U Ÿq(hUFolderqttqQU siblings.pyq (U ¤q (U#Products.PythonScripts.PythonScriptq U PythonScriptq tq tqQUMammalsq(U £q(hUFolderqttqQUtitleqUAutomatic Navigation DevicesqU index_htmlq(U ¢q(U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqttqQUbreadcrumbs.pyq(U ¡q(h U PythonScriptqttqQUReptilesq(U  q(hUFolderq ttq!QU_objectsq"(}q#(U meta_typeq$UScript (Python)q%Uidq&hu}q'(h$UFolderq(h&hu}q)(h$h(h&hu}q*(h$h(h&hu}q+(U meta_typeq,UScript (Python)q-Uidq.U siblings.pyq/u}q0(h,U Page Templateq1h.U index_htmlq2utq3U__ac_local_roles__q4}q5Uamosq6]q7UOwnerq8ash&U Navigationq9u. ¼((U OFS.FolderqUFolderqtqNt.}q(UgetTotalq(U °q(U#Products.PythonScripts.PythonScriptqU PythonScriptqtq tq QU deleteItemsq (U ¯q (hU PythonScriptq ttqQUtitleqU Shopping CartqU currentItemsq(U ®q(hU PythonScriptqttqQU index_htmlq(U ­q(U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqttqQUgetItemq(U ¬q(hU PythonScriptqttqQU_objectsq(}q(U meta_typeq UScript (Python)q!Uidq"hu}q#(h h!h"hu}q$(h h!h"hu}q%(h U Page Templateq&h"U index_htmlq'u}q((U meta_typeq)UScript (Python)q*Uidq+h u}q,(h)h*h+UaddItemsq-utq.U__ac_local_roles__q/}q0Uamosq1]q2UOwnerq3ash"U ShoppingCartq4h-(U «q5(hU PythonScriptq6ttq7Qu. ›((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UtitleqUU content_typeqU text/htmlqU_textqTÐ 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.

q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }q U_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUidqU index_htmlqUexpandqKu. ž®((U OFS.FolderqUFolderqtqNt.}q(U formatEntryq(U µq(U#Products.PythonScripts.PythonScriptqU PythonScriptqttq QU getEntriesq (U ´q (hU PythonScriptq ttq QUtitleqU Guest BookqU addEntry.htmlq(U ³q(U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqttqQUaddEntryq(U ¶q(hU PythonScriptqtqtqQU index_htmlq(U ²q(hUZopePageTemplateqttqQUEntriesq(U ±q(hUFolderq ttq!QU_objectsq"(}q#(U meta_typeq$U Page Templateq%Uidq&U index_htmlq'u}q((h$UFolderq)h&hu}q*(h$h%h&hu}q+(U meta_typeq,UScript (Python)q-Uidq.hu}q/(h,h-h.hu}q0(h,h-h.h utq1U__ac_local_roles__q2}q3Uamosq4]q5UOwnerq6ash&U GuestBookq7u. ™;((U OFS.ImageqUFileqtqNt.}q(U preconditionqUUtitleqUU__ac_local_roles__q}qUamosq ]q UOwnerq asU content_typeq Utext/cssq U__name__qU examples.cssqU_EtagSupport__etagqU ts05767609.14qUdataqTSH1, H2, H3, H4, H5, H6 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #6699CC; } body, .normal { background: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; } .small{ background: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; } .grey{ background: #DDDDDD; } .white{ background: #FFFFFF; } .bold{ font-weight:bold; } .normal{ font-weight:normal; } .message{ background: #FFFFAA; border-width: thin; border-style: solid; padding: 10pt; font-weight:bold; } qUsizeqMSu. ª((U OFS.FolderqUFolderqtqNt.}q(UtitleqUU example.txtq(U ½q(U OFS.ImageqUFileq tq tq QU_objectsq (}q (U meta_typeqUFileqUidqhu}q(hhhU example.htmlqutqh(U ¼q(hUFileqtqtqQU__ac_local_roles__q}qUamosq]qUOwnerqasUidqUFilesqu. © A((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_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) q U_codeq T‚csddd„ZdS(s; Returns a list of files sorted by id, date, type or size. sidic s—t}d||tdƒdƒdƒ}f}|djo7 | o dff}n dddff}nú |djoC| od fdff}nd ddfdff}n§|d joC| od fdff}nd ddfdff}nT|d joC| od ddfdff}nd fdff}n|tdƒ||ƒSdS(s; Returns a list of files sorted by id, date, type or size. sFiless objectValuessFilesidsgetIdscmpsdescsdatesbobobase_modification_timestypesgetContentTypessizesgetSizessortN(s _getattr_s_getattrs containersfilessargsssortsreversessequence(ssortsreverses _getattr_s_getattrs containersfilessargsssequence((sScript (Python)sgetFiless( !     N(sgetFiles(sgetFiles((sScript (Python)ssq U func_defaultsq(UidqKtqU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}q Uamosq!]q"UOwnerq#asUidq$UgetFilesq%U_paramsq&Usort='id', reverse=0q'U func_codeq((cShared.DC.Scripts.Signature FuncCode q)oq*}q+(U co_varnamesq,(Usortq-Ureverseq.U _getattr_q/U_getattrq0U containerq1Ufilesq2Uargsq3Usequenceq4tq5U co_argcountq6Kubu. ¨ ±((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qU _proxy_rolesq)Uwarningsq)U Script_magicq KU_bodyq TÖ""" 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))) q U_codeq TÊcsd„ZdS(s Adds a file to the library. cs³t}t}ddkl}dtfd„ƒY} t|dƒo t|dƒ o dd‚n| |dƒdd ƒ ||dƒƒ} ||dƒdƒt ||t d ƒd ƒd ƒƒd jod| djoD||||t d ƒdƒdƒdƒddddd|ƒn |d‚n |d‚d||dƒ} |||tdƒdƒdƒd|t dƒƒ|| ƒfƒSdS( s Adds a file to the library. (s url_quotes LimitExceededcs dRS(s$raised when file limits are exceeded((((sScript (Python)s LimitExceededssseekstells Bad RequestsInvalid file specifiediisFiless objectValuessFilei ismanage_addProductsOFSPsmanage_addFilesidsstitlesfiles(Uploaded file must be less than 2Kbytes.s%limit on number of files (5) exceededs File '%s' uploaded successfully.sfilenamesREQUESTsRESPONSEsredirects %s?message=%ss absolute_urlN(s _getitem_s_getitems _getattr_s_getattrsProducts.PythonScripts.standards url_quotes Exceptions LimitExceededshasattrsfilessizeslens containersmessagescontext(sfiles _getitem_s_getitems _getattr_s_getattrsProducts.PythonScripts.standards url_quotes Exceptions LimitExceededshasattrssizeslens containersmessagescontext((sScript (Python)saddFiles$.8 N(saddFile(saddFile((sScript (Python)ssq U func_defaultsqNUerrorsq)U _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asUidq#UaddFileq$U_paramsq%Ufileq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_argcountq+KU co_varnamesq,(Ufileq-U _getitem_q.U_getitemq/U _getattr_q0U_getattrq1UProducts.PythonScripts.standardq2U url_quoteq3U Exceptionq4U LimitExceededq5Uhasattrq6Usizeq7Ulenq8U containerq9Umessageq:Ucontextq;tq 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.

Files

message goes here

Files 1 to 10 of 17.
< previous 10 next 10 >

ID Type Size Last Modified
example.zip application/x-zip-compressed 12 K Nov 14, 2001 9:31 am

There are no files currently available.

Upload a File

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.


q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }q U_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUamosq]qUOwnerqasUidqU index_htmlqUexpandqKu. ¦*((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_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 U_codeq Tcsd„ZdS(s. Format a number of bytes as bytes, K, or MB. csqd|d}|djod|Sn|d}|djo d|Sn d|SdS(s. Format a number of bytes as bytes, K, or MB. f 1048576.0is%.2f MBf1024.0s%d Ks%d bytesN(sbytessmegssk(sbytessmegssk((sScript (Python)sgetSizes  N(sgetSize(sgetSize((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"UgetSizeq#U_paramsq$Ubytesq%U func_codeq&(cShared.DC.Scripts.Signature FuncCode q'oq(}q)(U co_varnamesq*(Ubytesq+Umegsq,Uktq-U co_argcountq.Kubu. ¥€(cProducts.PythonScripts.PythonScript PythonScript q)tq.}q(U Python_magicqUmò qUerrorsq)Uwarningsq)U Script_magicqKU_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=1 return "%s?sort=%s&reverse:int=%s" % (url, new_sort, new_reverse) q Uidq UgetLinkq U_codeq TÍc@s d„ZdS(Nc CsJtttdƒdƒ}||jo d}nd}d|||fSdS(NtREQUESTtURL0iis%s?sort=%s&reverse:int=%s(t _getattr_tcontextturltnew_sorttsortt new_reverse(RRtreverseRRRR((sScript (Python)tgetLinks   (R (R ((sScript (Python)stqU func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(Uname_containerqU containerqU name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asU _filepathq#U-Script (Python):/Examples/FileLibrary/getLinkq$U_paramsq%Unew_sort, sort, reverseq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_argcountq+KU co_varnamesq,(Unew_sortq-Usortq.Ureverseq/U _getattr_q0Ucontextq1Uurlq2U new_reverseq3tq4ubu. Ÿ((U OFS.FolderqUFolderqtqNt.}q(UtitleqUUPigeonsq(U ·q(hUFolderqtq tq QUCrowsq (U ¸q (hUFolderq tqtqQU_objectsq(}q(U meta_typeqUFolderqUidqh u}q(hhhhutqU__ac_local_roles__q}qUamosq]qUOwnerqashUBirdsqu. ¤g((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_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 U_codeq T3csd„ZdS(s/ This script returns a list of sibling folders csRt}d||tdƒdƒdƒ}||dƒtƒ|SdS(s/ This script returns a list of sibling folders s aq_parents objectValuessFoldersremoveN(s _getattr_s_getattrscontextsfolders(s _getattr_s_getattrscontextsfolders((sScript (Python)s siblings.pys $N(s siblings.py(s siblings.py((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_m_selfqUscriptqU name_contextqUcontextqU name_subpathqUtraverse_subpathqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"U siblings.pyq#U_paramsq$UU func_codeq%(cShared.DC.Scripts.Signature FuncCode q&oq'}q((U co_varnamesq)(U _getattr_q*U_getattrq+Ucontextq,Ufoldersq-tq.U co_argcountq/Kubu. £<((U OFS.FolderqUFolderqtqNt.}q(UtitleqUUWhalesq(U ºq(hUFolderqtq tq QUBatsq (U »q (hUFolderq tqtqQU_objectsq(}q(U meta_typeqUFolderqUidqUPrimatesqu}q(hhhh u}q(hhhhutqh(U ¹q(hUFolderqtqtqQU__ac_local_roles__q}qUamosq]q UOwnerq!ashUMammalsq"u. ¢ q((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UtitleqUU content_typeqU text/htmlqU_textqT% 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.

There are no sub-folders here.

Sibling Links

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.

There are no sibling folders here.

q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }q U_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUamosq]qUOwnerqasUidqU index_htmlqUexpandqKu. ¡ ž((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_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 U_codeq Tðcsd„ZdS(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}ddkl} g} x¢|||tdƒdƒdd…ƒd rt}| |dƒdd |||d ƒƒƒ|||d ƒƒƒfƒ ||d ƒƒd joPnq\W|d d ƒ|ƒSdS(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_quotesREQUESTsPARENTSiNisinserts%ss absolute_urlsgetIdsExampless/sjoin( s _getitem_s_getitems _getattr_s_getattrsProducts.PythonScripts.standards html_quoteslinksscontextsparent( s _getitem_s_getitems _getattr_s_getattrsProducts.PythonScripts.standards html_quoteslinksscontextsparent((sScript (Python)sbreadcrumbs.pys 95 N(sbreadcrumbs.py(sbreadcrumbs.py((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_m_selfqUscriptqU name_contextqUcontextqU name_subpathqUtraverse_subpathqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"Ubreadcrumbs.pyq#U_paramsq$UU func_codeq%(cShared.DC.Scripts.Signature FuncCode q&oq'}q((U co_argcountq)KU co_varnamesq*(U _getitem_q+U_getitemq,U _getattr_q-U_getattrq.UProducts.PythonScripts.standardq/U html_quoteq0Ulinksq1Ucontextq2Uparentq3tq4ubu.  r((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UReptilesq Utitleq Uu. °;((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq Uuitems=container.currentItems() total=0.0 for item in items: total+=item['price'] * item['quantity'] return total q U_codeq T:csd„ZdS(Ncsqt}t}|tdƒƒ}d}x6|dr)}|||dƒ||dƒ7}q6W|SdS(Ns currentItemsf0.0ispricesquantity(s _getitem_s_getitems _getattr_s_getattrs containersitemsstotalsitem(s _getitem_s_getitems _getattr_s_getattrs containersitemsstotalsitem((sScript (Python)sgetTotals! '(sgetTotal(sgetTotal((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"UgetTotalq#U_paramsq$UU func_codeq%(cShared.DC.Scripts.Signature FuncCode q&oq'}q((U co_varnamesq)(U _getitem_q*U_getitemq+U _getattr_q,U_getattrq-U containerq.Uitemsq/Utotalq0Uitemq1tq2U co_argcountq3Kubu. ¯è((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq T""" Remove one or more items from the shopping cart. """ session=context.REQUEST.SESSION # get the items items=session.get('items',{}) # remove the items for id in ids: if items.has_key(id): del items[id] # save changes back to the session session['items']=items # if this script is called from the web return a response page if REQUEST is not None: return container.index_html(REQUEST) q U_codeq Tcstd„ZdS(s2 Remove one or more items from the shopping cart. c sÐt}t}d||tdƒdƒ}||dƒdhƒ} x=|d r0} | |dƒ| ƒo||ƒ| =nqXW|||ƒd<|t j o|t dƒ|ƒSndS( s2 Remove one or more items from the shopping cart. sREQUESTsSESSIONsgetsitemsishas_keys index_htmlN( s_write_s_writes _getattr_s_getattrscontextssessionsitemssidssidsREQUESTsNones container( sidssREQUESTs_write_s_writes _getattr_s_getattrscontextssessionsitemssidsNones container((sScript (Python)s deleteItemss+N(sNones deleteItems(sNones deleteItems((sScript (Python)ssq U func_defaultsq(NtqU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asUidq#U deleteItemsq$U_paramsq%Uids, REQUEST=Noneq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_varnamesq+(Uidsq,UREQUESTq-U_write_q.U_writeq/U _getattr_q0U_getattrq1Ucontextq2Usessionq3Uitemsq4Uidq5UNoneq6U containerq7tq8U co_argcountq9Kubu. ®Ä((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq TŒ""" Returns a list of items that are in the shopping cart. Each item has a 'quantity' field as well as the normal 'id' and 'description' fields. """ session=context.REQUEST.SESSION quantities=session.get('items', {}) items=[] for id, quantity in quantities.items(): item=container.getItem(id) if item is not None: item['quantity']=quantity items.append(item) return items q U_codeq Ttcsd„ZdS(sŽ Returns a list of items that are in the shopping cart. Each item has a 'quantity' field as well as the normal 'id' and 'description' fields. c sàt}t}d||tdƒdƒ}||dƒdhƒ}g}xz||dƒƒdra\}}  |t dƒ|ƒ}  | t j o- | || ƒd<| |dƒ| ƒnqmW |Sd S( sŽ Returns a list of items that are in the shopping cart. Each item has a 'quantity' field as well as the normal 'id' and 'description' fields. sREQUESTsSESSIONsgetsitemsisgetItemsquantitysappendN( s_write_s_writes _getattr_s_getattrscontextssessions quantitiessitemssidsquantitys containersitemsNone( s_write_s_writes _getattr_s_getattrscontextssessions quantitiessitemssidsquantitys containersitemsNone((sScript (Python)s currentItemss 'N(s currentItems(s currentItems((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"U currentItemsq#U_paramsq$UU func_codeq%(cShared.DC.Scripts.Signature FuncCode q&oq'}q((U co_argcountq)KU co_varnamesq*(U_write_q+U_writeq,U _getattr_q-U_getattrq.Ucontextq/Usessionq0U quantitiesq1Uitemsq2Uidq3Uquantityq4U containerq5Uitemq6UNoneq7tq8ubu. ­((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UtitleqUU content_typeqU text/htmlqU_textqTÉ The document title or folder title or the example title

The title

This example shows how to use sessions. Notice that Zope remembers the contents of your shopping cart until you close your browser.

The contents of the cart are stored in a session. The session variable items keeps track of the item ids and quantities of items in your shopping cart. The currentItems script uses this information to retrieve records describing the items in the shopping card. The deleteItems script removes items from the shopping cart.

Your Shopping Cart

Item Price Quantity
Item $10.00 2
Total
$25.00

There are currently no items in your shopping cart.

Add Items

Item Description Price Quantity
Item Description $10.00

The addItems script adds items to your shopping cart. The above form uses records to build an order list of to pass to the script. Each item in the order list has a id and a quantity field.

q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }q U_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUamosq]qUOwnerqasUidqU index_htmlqUexpandqKu. ¬r((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq TZ""" Returns an item given its id. If no id is provided, returns all available items. In a real shopping cart application, this script would probably consult a database of some sort. Each item is a dictionary with an id, title, description, and price. """ items={ '510-115' : {'title' : 'Econo Feeder', 'description' : 'These feeders are made in Taiwan from a light-weight metal with plastic ends, and have an anti-spill edge to prevent the birds from kicking the feed out of the tray. They have a wooden rollbar to prevent the birds from sitting on them.', 'price' : 7.95}, '510-122' : {'title' : 'Hopper Feeder', 'description' : 'Need to go out of town for a few days, and no one can feed your pigeons? Don\'t worry, we now have the virtually spillproof hopper feeder. Made from birch plywood it holds from 30 to 35 pounds of grain. Pigeons can get at the feed through holes in the plexiglass cover, but will not be able to kick out any feed.', 'price' : 55.0}, '510-007' : {'title' : 'Dust Free Bullet Waterer', 'description' : 'A favorite with many fanciers, this drinker has a dust cover over each individual drinking hole, to keep out the dirt and dust.', 'price' : 16.0}, } # return requested item if id is not None: item=items.get(id) if item is None: # no item by that id return None # add an id field to the record item['id']=id return item # return all items results=[] for id, item in items.items(): item['id']=id results.append(item) return results q U_codeq T~cstd„ZdS(sù Returns an item given its id. If no id is provided, returns all available items. In a real shopping cart application, this script would probably consult a database of some sort. Each item is a dictionary with an id, title, description, and price. c sTt}t}dhhdd<dd<dd<d<hdd<d d<d d<d <hd d<d d<dd<d<}|tj oQ||dƒ|ƒ}|tjo tSn|||ƒd<|Sng}xN||dƒƒdr5\}} |||ƒd<|!|dƒ|ƒq W"|SdS(sù Returns an item given its id. If no id is provided, returns all available items. In a real shopping cart application, this script would probably consult a database of some sort. Each item is a dictionary with an id, title, description, and price. s Econo FeederstitlesëThese feeders are made in Taiwan from a light-weight metal with plastic ends, and have an anti-spill edge to prevent the birds from kicking the feed out of the tray. They have a wooden rollbar to prevent the birds from sitting on them.s descriptionf7.95sprices510-115s Hopper Feeders7Need to go out of town for a few days, and no one can feed your pigeons? Don't worry, we now have the virtually spillproof hopper feeder. Made from birch plywood it holds from 30 to 35 pounds of grain. Pigeons can get at the feed through holes in the plexiglass cover, but will not be able to kick out any feed.f55.0s510-122sDust Free Bullet WaterersA favorite with many fanciers, this drinker has a dust cover over each individual drinking hole, to keep out the dirt and dust.f16.0s510-007sgetsidsitemsisappendN( s_write_s_writes _getattr_s_getattrsitemssidsNonesitemsresults( sids_write_s_writes _getattr_s_getattrsitemssNonesitemsresults((sScript (Python)sgetItemsu    'N(sNonesgetItem(sNonesgetItem((sScript (Python)ssq U func_defaultsq(NtqU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_m_selfqUscriptqU name_contextqUcontextqU name_subpathqUtraverse_subpathqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asUidq#UgetItemq$U_paramsq%Uid=Noneq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_varnamesq+(Uidq,U_write_q-U_writeq.U _getattr_q/U_getattrq0Uitemsq1UNoneq2Uitemq3Uresultsq4tq5U co_argcountq6Kubu. « 0((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq T@""" Adds one or more items to the shopping cart. Each order is a record with an id and a quantity field. """ session=context.REQUEST.SESSION # get the items, items is a dictionary that maps item ids to quantities items=session.get('items',{}) # get the valid item names for form validation valid_items=[d['id'] for d in container.getItem()] for order in orders: quantity=hasattr(order, 'quantity') and order.quantity and \ int(order.quantity) or 0 if quantity != 0 and hasattr(order, 'id') and order.id in valid_items: items[order.id]=items.get(order.id, 0) + quantity # save items back to session (this is necessary # since items is a mutable non-persistent object) session['items']=items # if called from the web return a response page if REQUEST is not None: return container.index_html(REQUEST) q U_codeq TÁcstd„ZdS(sf Adds one or more items to the shopping cart. Each order is a record with an id and a quantity field. cs§t}t}t}d||tdƒdƒ} || dƒdhƒ}  gi } |t dƒƒd r}| ||dƒƒqq~ } xÊ|d r½}t|dƒo&||dƒot||dƒƒpd}|djo#t|dƒo||dƒ|jo?|| dƒ||dƒdƒ||| ƒ||dƒsq U func_defaultsq(NtqU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asUidq#UaddItemsq$U_paramsq%Uorders, REQUEST=Noneq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_argcountq+KU co_varnamesq,(Uordersq-UREQUESTq.U_write_q/U_writeq0U _getitem_q1U_getitemq2U _getattr_q3U_getattrq4Ucontextq5Usessionq6Uitemsq7Uappendq8U$append0q9U containerq:UdU valid_itemsq;UorderqUquantityq?UNoneq@tqAubu. µÍ((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq Unfrom Products.PythonScripts.standard import html_quote, newline_to_br return newline_to_br(html_quote(entry)) q U_codeq TÉcsd„ZdS(Ncs-dkl}l}|||ƒƒSdS(N(s html_quotes newline_to_br(sProducts.PythonScripts.standards html_quotes newline_to_brsentry(sentrysProducts.PythonScripts.standards html_quotes newline_to_br((sScript (Python)s formatEntrys(s formatEntry(s formatEntry((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqUname_nsqU_U name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq ]q!UOwnerq"asUidq#U formatEntryq$U_paramsq%Uentryq&U func_codeq'(cShared.DC.Scripts.Signature FuncCode q(oq)}q*(U co_varnamesq+(Uentryq,UProducts.PythonScripts.standardq-U html_quoteq.U newline_to_brq/tq0U co_argcountq1Kubu. ´=((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq T""" Returns a list of entries (file objects) in order from newest to oldest. """ files=container.Entries.objectValues('File') # sort the files based on modification time, with the most recent files first return sequence.sort(files, (('bobobase_modification_time', 'cmp', 'desc'),)) q U_codeq T°csd„ZdS(sJ Returns a list of entries (file objects) in order from newest to oldest. csZt}d||tdƒdƒdƒ}|tdƒ|dddffƒSdS( sJ Returns a list of entries (file objects) in order from newest to oldest. sEntriess objectValuessFilessortsbobobase_modification_timescmpsdescN(s _getattr_s_getattrs containersfilesssequence(s _getattr_s_getattrs containersfilesssequence((sScript (Python)s getEntriess !N(s getEntries(s getEntries((sScript (Python)ssq U func_defaultsqNU _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q}qUamosq]q UOwnerq!asUidq"U getEntriesq#U_paramsq$UU func_codeq%(cShared.DC.Scripts.Signature FuncCode q&oq'}q((U co_varnamesq)(U _getattr_q*U_getattrq+U containerq,Ufilesq-Usequenceq.tq/U co_argcountq0Kubu. ³¹((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UtitleqUSign the Guest BookqU content_typeqU text/htmlqU_textq TU The document title or folder title or the example title

The document title

You can sign the guest book by filling out this form. You cannot include HTML in your comments, however, Zope will preserve your linebreaks.

Your Name
Comments
q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }qU_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUamosq]qUOwnerqasUidqU addEntry.htmlqUexpandqKu. ¶ Y((U#Products.PythonScripts.PythonScriptqU PythonScriptqtqNt.}q(U Python_magicqU*ë qUerrorsq)Uwarningsq)U Script_magicq KU_bodyq T<""" Create a guest book entry. """ class LimitExceeded(Exception): """raised when too many entries are submitted""" entries_folder=container.Entries # create up-to 5 unique entry ids, a real app might not impose such a # small limit, but we do because this is just an example after all n=len(entries_folder.objectIds()) if n > 4: raise LimitExceeded, "limit on number of entries (5) exceeded" id='entry_%d' % n # create the entry, limit body to 128 bytes entries_folder.manage_addProduct['OFSP'].manage_addFile(id, title="", content_type="text/plain", file=comments[:128]) # add a guest_name string property, limited to 32 bytes entry=getattr(entries_folder, id) entry.manage_addProperty('guest_name', guest_name[:32], 'string') # return a response page if REQUEST is not None: return container.index_html(REQUEST) q U_codeq TÕcsdtd„ZdS(s Create a guest book entry. s Anonymouscs:t}t}ddtfd„ƒY}|tdƒ}  t|| dƒƒƒ}  | djo |d‚n d| } |||| dƒd ƒd ƒ| d d d dd||dd…ƒƒt | | ƒ}||dƒd||dd…ƒdƒ|tj o|tdƒ|ƒSndS(s Create a guest book entry. s LimitExceededcs dRS(s*raised when too many entries are submitted((((sScript (Python)s LimitExceededssEntriess objectIdsis'limit on number of entries (5) exceededsentry_%dsmanage_addProductsOFSPsmanage_addFilestitless content_types text/plainsfileNi€smanage_addPropertys guest_namei sstrings index_html(s _getitem_s_getitems _getattr_s_getattrs Exceptions LimitExceededs containersentries_folderslensnsidscommentssgetattrsentrys guest_namesREQUESTsNone(scommentss guest_namesREQUESTs _getitem_s_getitems _getattr_s_getattrs Exceptions LimitExceededs containersentries_folderslensnsidsgetattrsentrysNone((sScript (Python)saddEntrys@(N(sNonesaddEntry(sNonesaddEntry((sScript (Python)ssq U func_defaultsq(U AnonymousqNtqU _proxy_rolesq)U _bind_namesq(cShared.DC.Scripts.Bindings NameAssignments qoq}qU_asgnsq}q(U name_contextqUcontextqU name_subpathqUtraverse_subpathqU name_m_selfqUscriptqUname_containerqU containerqusbU__ac_local_roles__q }q!Uamosq"]q#UOwnerq$asUidq%UaddEntryq&U_paramsq'U.comments, guest_name='Anonymous', REQUEST=Noneq(U func_codeq)(cShared.DC.Scripts.Signature FuncCode q*oq+}q,(U co_argcountq-KU co_varnamesq.(Ucommentsq/U guest_nameq0UREQUESTq1U _getitem_q2U_getitemq3U _getattr_q4U_getattrq5U Exceptionq6U LimitExceededq7U containerq8Uentries_folderq9Ulenq:UnUidq;Ugetattrqtq?ubu. ² 9((U'Products.PageTemplates.ZopePageTemplateqUZopePageTemplateqtqNt.}q(UtitleqUU content_typeqU text/htmlqU_textqTí The document title or folder title or the example title

The title

This example shows how to create a simple guest book.

The guest book stores its entries as file objects in the Entries folder. This page displays the entries by looping over a sorted list of entries and displaying each one. The list of entries is created by the getEntries script. The formatEntry script formats each guest book entry. To remove an entry, remove its file from the Entries folder. An alternate version of this application could use ZSQL Methods to store guest book entries in a relational database.

The addEntry.html template provides a form that allows you to sign the guest book. The form is processed by the addEntry script. The addEntry script stores the entry as a file. Adding files is protected by the "Add Documents, Images and Files" permission; if you want anonymous users to sign the guest book, you could visit the 'Security' tab of the addEntry script, and give it the "Manager" proxy role.

Sign the guest book

Entries

By Guest Name
2001/12/12
Entry contents

There are no guest book entries yet.

q U _bind_namesq (cShared.DC.Scripts.Bindings NameAssignments q oq }q U_asgnsq}qU name_subpathqUtraverse_subpathqssbU__ac_local_roles__q}qUamosq]qUOwnerqasUidqU index_htmlqUexpandqKu. ±Ø((U OFS.FolderqUFolderqtqNt.}q(U_objectsq(}q(U meta_typeqUFileqUidq Uentry_0q utq U__ac_local_roles__q }q Uamosq]qUOwnerqasUidqUEntriesqh (U ¾q(U OFS.ImageqUFileqtqtqQUtitleqUu. ½((U OFS.ImageqUFileqtqNt.}q(U preconditionqUUtitleqUU__ac_local_roles__q}qUamosq ]q UOwnerq asU content_typeq U text/plainq U__name__qU example.txtqU_EtagSupport__etagqU ts56412603.29qUdataqUThis is an example text file.qUsizeqKu. ¼³((U OFS.ImageqUFileqtqNt.}q(U preconditionqUUtitleqUU__ac_local_roles__q}qUamosq ]q UOwnerq asU content_typeq U text/htmlq U__name__qU example.htmlqU_EtagSupport__etagqU ts56412592.16qUdataqUÎ Example

Example

This is an example HTML file.

qUsizeqKÎu. ·q((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UPigeonsq Utitleq Uu. ¸o((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UCrowsq Utitleq Uu. ºp((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UWhalesq Utitleq Uu. »n((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UBatsq Utitleq Uu. ¹Ò((U OFS.FolderqUFolderqtqNt.}q(U_objectsq(}q(U meta_typeqUFolderqUidq UMonkeysq utq h (U ¿q (hUFolderq tqtqQU__ac_local_roles__q}qUamosq]qUOwnerqasUidqUPrimatesqUtitleqUu. ¾”((U OFS.ImageqUFileqtqNt.}q(U guest_nameqUAmosqU preconditionqUUtitleqUU__ac_local_roles__q }q Uamosq ]q UOwnerq asU content_typeqU text/plainqU _propertiesq(}q(UtypeqUstringqUidqhu}q(hhhhu}q(hhhhutqU__name__qUentry_0qU_EtagSupport__etagqU ts05745452.64qUdataqTMThis is an example comment. It can contain multiple lines of text. Note that you cannot include HTML in your comments, since the HTML is quoted. This guest book entry is stored in a file named entry_0 in the Entries folder. To edit the entry, simple edit that file. You can also delete an entry by deleting its file.qUsizeqMMu. ¿q((U OFS.FolderqUFolderqtqNt.}q(U__ac_local_roles__q}qUamosq]qUOwnerq asUidq UMonkeysq Utitleq Uu.ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ