def __call__(self): """Perform the toggle.""" msg_type = 'info' if ILocalAgencyInfo.providedBy(self.context): # Deactivate local agency information. noLongerProvides(self.context, ILocalAgencyInfo) self.context.reindexObject(idxs=['object_provides', ]) msg = _(u'Local agency information deactivated.') elif IPossibleLocalAgencyInfo.providedBy(self.context): alsoProvides(self.context, ILocalAgencyInfo) self.context.reindexObject(idxs=['object_provides', ]) msg = _(u'Local agency information activated.') else: msg = _( u'The local agency information don\'t work with this ' u'content type. Add \'IPossibleLocalAgencyInfo\' to the ' u'provided interfaces to enable this feature.' ) msg_type = 'error' self.context.plone_utils.addPortalMessage(msg, msg_type) self.request.response.redirect(self.context.absolute_url())
def _basicAgentPagesSetup(self): """setup basic agent folder structure """ context = self.context portal = aq_inner(self.context) catalog = getToolByName(portal, 'portal_catalog') workflowTool = getToolByName(portal, "portal_workflow") languages = ['en', 'es', 'de'] agent_profile = { 'en': {'id':'personal-description', 'title':'Personal Description' }, 'es': {'id':'perfil-inmobiliario', 'title':'Perfil del Inmobiliario' }, 'de': {'id':'makler-profil', 'title':'Makler Profil' } } agent_featured_folders = { 'en': {'id':'featured-listings', 'title':'Featured Listings' }, 'es': {'id':'propiedades-destacadas', 'title':'Propiedades Destacadas' }, 'de': {'id':'besondere-immobilien', 'title':'Besondere Immobilien' } } agent_folders = { 'en': {'id':'agents', 'title':'Agents' }, 'es': {'id':'inmobiliarios', 'title':'Inmobiliarios' }, 'de': {'id':'makler', 'title':'Makler' } } agent_blog_folders = { 'en': {'id':'blog', 'title':'Blog' }, 'es': {'id':'blog', 'title':'Blog' }, 'de': {'id':'blog', 'title':'Blog' } } if len(self.userid): member = self.membershiptool.getMemberById(self.userid) member_fullname = member.getProperty("fullname", self.userid) for lang in languages: # get the different navigation roots navRoot = portal.unrestrictedTraverse(lang) #check if basic setup is done already agent_folders_id = agent_folders[lang]['id'] agent_folders_title = agent_folders[lang]['title'] my_path = '/'.join(context.getPhysicalPath()) my_path = my_path + '/' + lang + '/' + agent_folders_id foo = catalog(path={ "query": my_path}, Language="all") if len(foo)==0: #create main agent folders try: new_folder = navRoot.invokeFactory('Folder', agent_folders_id, title=agent_folders_title, path=my_path) agent_root = getattr(navRoot, new_folder,None) workflowTool.doActionFor(agent_root, "publish",comment="published by setup (customer.krainrealestate)") self.context.plone_utils.addPortalMessage('"'+new_folder+'" added.' , 'info') except Exception: print Exception agentRoot= portal.unrestrictedTraverse(lang + "/" + agent_folders_id) try: #test if agent folder already exists newAgentFolder = agentRoot.invokeFactory('Folder', self.userid, title=member_fullname, path=my_path + "/" + self.userid) agent_home = getattr(agentRoot, newAgentFolder,None) workflowTool.doActionFor(agent_home, "publish",comment="published by setup (customer.krainrealestate)") self.context.plone_utils.addPortalMessage('"'+newAgentFolder+'" added & published.' , 'info') created = True # activate local agency Info if IPossibleLocalAgencyInfo.providedBy(agent_home): alsoProvides(agent_home, ILocalAgencyInfo) alsoProvides(agent_home, IAgentFolder) agent_home.reindexObject(idxs=['object_provides', ]) except Exception: """Folders exist already""" created = False print 'Personal Agent folder already exist' if(created): """"setup the missing folders and contents""" myAgentRoot = portal.unrestrictedTraverse(lang + "/" + agent_folders_id + "/" + self.userid) #set 'Blog' folder blog_id= agent_blog_folders[lang]['id'] blog_title= agent_blog_folders[lang]['title'] try: newAgentBlogFolder = myAgentRoot.invokeFactory('Folder', blog_id, title=blog_title, path=my_path + "/" + self.userid +"/"+blog_id) agent_blog = getattr(myAgentRoot, newAgentBlogFolder,None) workflowTool.doActionFor(agent_blog, "publish",comment="published by setup (customer.krainrealestate)") except Exception, e: """Folders exist already""" print 'Blog folder exists already' print e try: #create 'Blog' collection blog_collection = agent_blog.invokeFactory('Collection', blog_id, title=blog_title) agent_blog_collection = getattr(agent_blog, blog_collection,None) workflowTool.doActionFor(agent_blog_collection, "publish",comment="published by setup (customer.krainrealestate)") agent_blog.manage_addProperty('default_page',blog_collection,'string') #set criteria blog_criteria = [] blog_criteria.append({'i':'portal_type', 'o':'plone.app.querystring.operation.selection.is','v':'News Item'}) blog_criteria.append({'i':'Creator','o':'plone.app.querystring.operation.string.is','v':self.userid}) self._setCriteria(agent_blog_collection, blog_criteria) except Exception, e: print 'Featured Listing Collection: could not create.' print e #set 'Featured Listings' folder featured_id= agent_featured_folders[lang]['id'] featured_title= agent_featured_folders[lang]['title'] try: newAgentFeaturedFolder = myAgentRoot.invokeFactory('Folder', featured_id, title=featured_title, path=my_path + "/" + self.userid +"/"+featured_id) agent_featured = getattr(myAgentRoot, newAgentFeaturedFolder,None) workflowTool.doActionFor(agent_featured, "publish",comment="published by setup (customer.krainrealestate)") except Exception, e: """Folders exist already""" print 'Featured folder exist already' print e try: #create 'Featured listing' collection featured_collection = agent_featured.invokeFactory('Collection', featured_id, title=featured_title) agent_featured_collection = getattr(agent_featured, featured_collection,None) workflowTool.doActionFor(agent_featured_collection, "publish",comment="published by setup (customer.krainrealestate)") agent_featured.manage_addProperty('default_page',featured_collection,'string') #set criteria criteria = [] criteria.append({'i':'portal_type', 'o':'plone.app.querystring.operation.selection.is','v':'plone.mls.listing.listing'}) criteria.append({'i':'path','o':'plone.app.querystring.operation.string.relativePath','v':'../'}) self._setCriteria(agent_featured_collection, criteria) except Exception, e: print 'Featured Listing Collection: could not create.' print e
def can_activate(self): """Can the local agency information be activated for this context?""" return IPossibleLocalAgencyInfo.providedBy(self.context) and \ not ILocalAgencyInfo.providedBy(self.context)