Back to index

plone3  3.1.7
search.py
Go to the documentation of this file.
00001 from zope import schema
00002 from zope.component import getMultiAdapter
00003 from zope.formlib import form
00004 from zope.interface import implements
00005 
00006 from plone.app.portlets.portlets import base
00007 from plone.memoize.instance import memoize
00008 from plone.portlets.interfaces import IPortletDataProvider
00009 
00010 from Acquisition import aq_inner
00011 from DateTime.DateTime import DateTime
00012 from Products.CMFCore.utils import getToolByName
00013 from Products.CMFPlone import PloneMessageFactory as _
00014 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00015 
00016 class ISearchPortlet(IPortletDataProvider):
00017     """ A portlet displaying a (live) search box
00018     """
00019 
00020     enableLivesearch = schema.Bool(
00021             title = _(u"Enable LiveSearch"),
00022             description = _(u"Enables the LiveSearch feature, which shows "
00023                              "live results if the browser supports "
00024                              "JavaScript."),
00025             default = True,
00026             required = False)
00027 
00028 class Assignment(base.Assignment):
00029     implements(ISearchPortlet)
00030 
00031     def __init__(self, enableLivesearch=True):
00032         self.enableLivesearch=enableLivesearch
00033 
00034     @property
00035     def title(self):
00036         return _(u"Search")
00037 
00038 
00039 class Renderer(base.Renderer):
00040 
00041     render = ViewPageTemplateFile('search.pt')
00042 
00043     def __init__(self, context, request, view, manager, data):
00044         base.Renderer.__init__(self, context, request, view, manager, data)
00045 
00046         portal_state = getMultiAdapter((context, request), name=u'plone_portal_state')
00047         self.portal_url = portal_state.portal_url()
00048 
00049     def enable_livesearch(self):
00050         return self.data.enableLivesearch
00051 
00052     def search_form(self):
00053         return '%s/search_form' % self.portal_url
00054 
00055     def search_action(self):
00056         return '%s/search' % self.portal_url
00057 
00058 
00059 class AddForm(base.AddForm):
00060     form_fields = form.Fields(ISearchPortlet)
00061     label = _(u"Add Search Portlet")
00062     description = _(u"This portlet shows a search box.")
00063 
00064     def create(self, data):
00065         return Assignment()
00066 
00067 
00068 class EditForm(base.EditForm):
00069     form_fields = form.Fields(ISearchPortlet)
00070     label = _(u"Edit Search Portlet")
00071     description = _(u"This portlet shows a search box.")