m Ec@sPdZdZdklZdkZdklZdkl Z dk l Z dk l Z dklZd klZd klZlZd klZd klZlZd klZdklZdklZdkl Z dk!l"Z"dk#l$Z$dee"fdYZ%de%fdYZ&de&e fdYZ'dfdYZ(dS(shAdding View The Adding View is used to add new objects to a container. It is sort of a factory screen. trestructuredtext(swarnN(s implements(sIPublishTraverse(sIFactory(snotify(s UserError(sObjectCreatedEvent(sIAddings INameChooser(sIContainerNamesContainer(s checkFactorys checkObject(sgetMenu(sImplicit(s BadRequest(s SimpleItem(s BrowserView(sZopeTwoPageTemplateFilet BasicAddingcBsltZeeedZdZdZdZ dZ dZ dZ dddZ dZdZRS( NcCs |i}|i}t|}t|||t i |o |i |ipd|}n~|i }|i d|}|djo |i |ipd|}n6|djo|i d|}n|i ||}||_|i||||_|i|S(s2See zope.app.container.interfaces.IAdding ttadd_input_nameN(tselftcontextt containert contentNametnamet INameChoosertchoosert checkObjecttcontenttIContainerNamesContainert providedByt chooseNametrequesttgettNonetidt _setObjectt_getOb(RR RRRR ((t;/data/zmath/zope/lib/python/Products/Five/browser/adding.pytadd/s$          cCs,ttii|i|ifdddS(s)See zope.app.container.interfaces.IAddingRu absolute_urls /manage_mainN(tstrtzopet componenttgetMultiAdapterRRR(R((RtnextURLRscCstdtddS(Ns9The renderAddButton method is deprecated, use nameAllowedi(twarntDeprecationWarning(R((RtrenderAddButton^scCsd|jo_|idd\}}||_|ido|d}ntii ||fd|Sn|ido|d}n|}tii ||fd|}|dj o|Sntiit|}|djott|i||Sn|S(s)See zope.app.container.interfaces.IAddingt=is@@iRN(Rtsplitt view_namet content_nameRRt startswithRRRRtqueryMultiAdaptertviewRt queryUtilitytIFactorytfactorytsuperRtpublishTraverse(RRRR#R)R"R&((RR+cs"     RcCsB|ptdn|ido|d}nd|jo|iddd}n|}tii||i fd|dj oIdtii ||i fdd ||f}|i ii|dSn|ip ||_ntiit|}|}tt||i||i ii|idS( Ns*You must select the type of object to add.s@@it/iiRs%s/%s=%su absolute_url(t type_namet UserErrorR$R!R"RRR%RRRRRturltresponsetredirectRt getUtilityR(R)R tnotifytObjectCreatedEventRR(RR-RR/R)R R"((Rtaction|s$ (.    cCsti|i S(N(R RRR(R((Rt namesAcceptedscCsti|i S(s.Return whether names can be input by the user.N(R RRR(R((Rt nameAlloweds(t__name__t __module__t implementstIAddingtIPublishTraverseRRRRRRRR+R5R6R7(((RR,s  !    tAddingcBs5tZdZedZdZdZdZRS(Ns adding.ptcCs|i}g}x|idfD]}|pqnxt|||iD]}|id}|ot|id}|oZt i i t|}t|d|pqIq|dd|djot|dsN(RRRtresulttmenu_idtgetMenuRtitemRR>R)RRR2R(t checkFactoryRtTruetappendtsort(RRFRR>R)RHRE((Rt addingInfos* cCst|idjS(s0Return whether there is single menu item or not.iN(tlenRRM(R((RtisSingleMenuItemscCs:|io)|id}d|jotSq6ntS(sEThis should be called only if there is `singleMenuItem` else return 0iR?N(RRORMt menu_itemRJtFalse(RRP((RthasCustomAddViews    ( R8R9RRFtZopeTwoPageTemplateFiletindexRMRORR(((RR=s    t ContentAddingcBstZdZRS(Nt add_content(R8R9RF(((RRUstObjectManagerNameChoosercBs3tZdZeedZdZdZRS(s.A name chooser for a Zope object manager. cCs ||_dS(N(RR(RR((Rt__init__scCsy|id}Wntj otdnXy|ii|dtWn7tj o+}di |i pd}t|nXdS(Ntasciis&Id must contain only ASCII characters.t allow_dupt sId is in use or invalid( RtencodetUnicodeDecodeErrorR.RRt_checkIdRQt BadRequesttetjointargstmsg(RRtobjectRcR`((Rt checkNamescCs|p|ii}n3y|id}Wntj otdnX|id}|djo||}|| }nd}||}d}xYt oQ|d7}y|ii|Wntj oPnX|dt||}qW|i|||S(NRYs&Id must contain only ASCII characters.t.iRit-(RRdt __class__R8R\R]R.trfindtdottsuffixtntiRJRRRtAttributeErrorRRe(RRRdRmRlRjRk((RRs.    (R8R9t__doc__R:R RXReR(((RRWs    ()Rot __docformat__twarningsRtzope.componentRtzope.interfaceR:tzope.publisher.interfacesR<tzope.component.interfacesR(t zope.eventR3tzope.exceptionsR.tzope.lifecycleeventR4tzope.app.container.interfacesR;R R tzope.app.container.constraintsRIR tzope.app.publisher.browser.menuRGt AcquisitiontImplicitt zExceptionsR_tOFS.SimpleItemt SimpleItemt Products.Fivet BrowserViewt&Products.Five.browser.pagetemplatefileRSRR=RURW(R=RWRRpRSR R3R_RGR4R<R}RIR.RR R RRR:RURR;R(((Rt?s,               v*