[Checkins] SVN: z3c.livesearch/ initial import of the livesearch
package
Bernd Dorn
bernd.dorn at fhv.at
Wed Aug 30 02:08:03 EDT 2006
Log message for revision 69883:
initial import of the livesearch package
Changed:
A z3c.livesearch/
A z3c.livesearch/trunk/
A z3c.livesearch/trunk/setup.cfg
A z3c.livesearch/trunk/setup.py
A z3c.livesearch/trunk/src/
A z3c.livesearch/trunk/src/z3c/
A z3c.livesearch/trunk/src/z3c/__init__.py
A z3c.livesearch/trunk/src/z3c/livesearch/
A z3c.livesearch/trunk/src/z3c/livesearch/README.txt
A z3c.livesearch/trunk/src/z3c/livesearch/SETUP.cfg
A z3c.livesearch/trunk/src/z3c/livesearch/__init__.py
A z3c.livesearch/trunk/src/z3c/livesearch/browser.py
A z3c.livesearch/trunk/src/z3c/livesearch/configure.zcml
A z3c.livesearch/trunk/src/z3c/livesearch/ftesting.zcml
A z3c.livesearch/trunk/src/z3c/livesearch/ftests.py
A z3c.livesearch/trunk/src/z3c/livesearch/interfaces.py
A z3c.livesearch/trunk/src/z3c/livesearch/livesearch.pt
A z3c.livesearch/trunk/src/z3c/livesearch/results.pt
A z3c.livesearch/trunk/src/z3c/livesearch/test.pt
A z3c.livesearch/trunk/src/z3c/livesearch/z3c.livesearch-configure.zcml
-=-
Added: z3c.livesearch/trunk/setup.cfg
===================================================================
--- z3c.livesearch/trunk/setup.cfg 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/setup.cfg 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = .dev
+tag_svn_revision = 1
Property changes on: z3c.livesearch/trunk/setup.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/setup.py
===================================================================
--- z3c.livesearch/trunk/setup.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/setup.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,22 @@
+from setuptools import setup, find_packages
+
+setup(
+ name = "z3c.livesearch",
+ version = "0.1",
+ author = "Zope Contributors",
+ author_email = "zope3-dev at zope.org",
+ description = "Livesearch for zope3",
+ license = "ZPL 2.1",
+ keywords = "zope3 search live ajax javascript",
+ url='http://svn.zope.org/z3c.livesearch',
+ classifiers = [
+ 'Development Status :: 3 - Alpha',
+ "License :: OSI Approved :: Zope Public License",
+ "Framework :: Zope :: UI",
+ ],
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['z3c'],
+ zip_safe=False,
+ )
Property changes on: z3c.livesearch/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/__init__.py
===================================================================
--- z3c.livesearch/trunk/src/z3c/__init__.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/__init__.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,6 @@
+try:
+ # Declare this a namespace package if pkg_resources is available.
+ import pkg_resources
+ pkg_resources.declare_namespace('z3c')
+except ImportError:
+ pass
Property changes on: z3c.livesearch/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/README.txt
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/README.txt 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/README.txt 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,79 @@
+==========
+Livesearch
+==========
+
+The z3c.livesearch package provides views which provide a Ajax based
+livesearch field based on scriptacuolous.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+At first we need a site with a catalog and and intid util, we get this
+from the z3c.sampledata package.
+
+ >>> browser.open('http://localhost/@@managesamples.html')
+ >>> browser.getLink('Site with Catalog').click()
+ >>> browser.getControl('Sitename').value=u'livesearchsite'
+ >>> browser.getControl('Generate').click()
+
+Let us add the needed index
+
+ >>> browser.open('http://localhost/livesearchsite/++etc++site/default/Catalog/+/AddTextIndex=')
+ >>> browser.getControl(name='field.interface').value=[
+ ... 'zope.index.text.interfaces.ISearchableText']
+ >>> browser.getControl('Field Name').value='getSearchableText'
+ >>> browser.getControl('Field Callable').selected=True
+ >>> browser.getControl(name='add_input_name').value='getSearchableText'
+ >>> browser.getControl('Add').click()
+
+
+We can now call our result page which is an empty unordered list.
+
+ >>> base = 'http://localhost/livesearchsite'
+
+ >>> browser.open(base + '/@@livesearch/@@results?query=a')
+ >>> print browser.contents
+ <ul class="autocomplete">
+ </ul>
+
+Let us add 2 zpt pages which is indexed by our catalog.
+
+ >>> browser.open(base + '/+/zope.app.zptpage.ZPTPage=')
+ >>> browser.getControl('Source').value="apple pear"
+ >>> browser.getControl('Add').click()
+
+ >>> browser.open(base + '/+/zope.app.zptpage.ZPTPage=')
+ >>> browser.getControl('Source').value="pear cherry"
+ >>> browser.getControl('Add').click()
+
+ >>> browser.open(base + '/@@livesearch/@@results?query=app')
+
+We should have one match now labeled with the name.
+
+ >>> browser.getLink('ZPTPage').url
+ 'http://localhost/livesearchsite/ZPTPage'
+
+ >>> not '>ZPTPage-2<' in browser.contents
+ True
+
+Let us test some another queries.
+
+ >>> browser.open(base + '/@@livesearch/@@results?query=notthere')
+ >>> print browser.contents
+ <ul class="autocomplete">
+ </ul>
+
+ >>> browser.open(base + '/@@livesearch/@@results?query=pea')
+ >>> browser.getLink('ZPTPage').url
+ 'http://localhost/livesearchsite/ZPTPage'
+ >>> browser.getLink('ZPTPage-2').url
+ 'http://localhost/livesearchsite/ZPTPage-2'
+
+ >>> browser.open(base + '/@@livesearch/@@results?query=che')
+ >>> browser.getLink('ZPTPage-2').url
+ 'http://localhost/livesearchsite/ZPTPage-2'
+
+ >>> not '>ZPTPage<' in browser.contents
+ True
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/SETUP.cfg
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/SETUP.cfg 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/SETUP.cfg 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+ z3c.livesearch-*.zcml
+</data-files>
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/SETUP.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/__init__.py
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/__init__.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/__init__.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Livesearch for zope3
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+
+
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/browser.py
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/browser.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/browser.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,46 @@
+from interfaces import ILiveSearchView
+from zope import interface
+from zope.traversing.browser.absoluteurl import absoluteURL
+from zope.app.catalog.interfaces import ICatalog
+from zope.app.intid.interfaces import IIntIds
+from zope.app.zapi import getUtility
+
+try:
+ from zc import resourcelibrary
+ haveResourceLibrary = True
+except ImportError:
+ haveResourceLibrary = False
+
+class LiveSearchView(object):
+ interface.implements(ILiveSearchView)
+
+ def __call__(self):
+ if haveResourceLibrary:
+ resourcelibrary.need('z3c.javascript.scriptaculous')
+ return super(LiveSearchView, self).__call__()
+
+class LiveSearchResultsView(object):
+
+ idxName = u'getSearchableText'
+ catalogName = u''
+
+ def catalogResults(self):
+ query = self.request.get('query', None)
+ if query is None:
+ return {}
+ query = u'%s*' % query
+ catalog = getUtility(ICatalog, name=self.catalogName)
+ results = catalog.apply({self.idxName:query})
+ return results
+
+ def results(self):
+ uidutil = getUtility(IIntIds)
+ for uid, score in self.catalogResults().items():
+ obj = uidutil.getObject(uid)
+ info = {}
+ info['obj'] = obj
+ info['name'] = obj.__name__
+ info['url'] = absoluteURL(obj, self.request)
+ info['score'] = "%.4f" % score
+ yield info
+
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/browser.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/configure.zcml
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/configure.zcml 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/configure.zcml 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,31 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope">
+
+ <browser:page
+ name="livesearch"
+ for="zope.app.component.interfaces.ISite"
+ class=".browser.LiveSearchView"
+ permission="zope.Public"
+ template="livesearch.pt"
+ />
+
+ <browser:page
+ name="results"
+ for=".interfaces.ILiveSearchView"
+ class=".browser.LiveSearchResultsView"
+ permission="zope.Public"
+ template="results.pt"
+ />
+
+ <browser:page
+ for="zope.app.component.interfaces.ISite"
+ name="testsearch.html"
+ menu="zmi_views"
+ title="Test Livesearch"
+ template="test.pt"
+ permission="zope.Public"/>
+
+
+
+</configure>
\ No newline at end of file
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/ftesting.zcml
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/ftesting.zcml 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/ftesting.zcml 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,55 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ i18n_domain="zope">
+ <include package="zope.app" />
+ <include package="zope.app.server" />
+ <include package="zope.app.authentication" />
+ <include package="zope.app.securitypolicy" file="meta.zcml" />
+ <securityPolicy
+ component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+ <include package="zope.app.securitypolicy" />
+
+ <include package="zope.formlib"/>
+ <include package="zope.app.catalog" />
+ <include package="zope.app.intid" />
+ <include package="zope.app.zptpage"/>
+ <include package="zope.app.zptpage.textindex"/>
+ <include package="zope.app.keyreference"/>
+
+ <!-- Turn on the devmode which is needed for sample data generation -->
+ <meta:provides feature="devmode" />
+
+
+ <include package="z3c.sampledata" file="meta.zcml"/>
+ <include package="z3c.sampledata"/>
+ <include package="zc.resourcelibrary" file="meta.zcml"/>
+ <include package="zc.resourcelibrary" />
+ <include package="z3c.javascript.prototype"/>
+ <include package="z3c.javascript.scriptaculous"/>
+
+ <include package="z3c.livesearch"/>
+ <role id="zope.Anonymous" title="Everybody"
+ description="All users have this role implicitly" />
+ <role id="zope.Manager" title="Site Manager" />
+ <role id="zope.Member" title="Site Member" />
+ <grantAll role="zope.Manager" />
+
+ <principal
+ id="zope.manager"
+ title="Administrator"
+ login="mgr"
+ password="mgrpw" />
+
+ <grant
+ role="zope.Manager"
+ principal="zope.manager"
+ />
+
+ <browser:page
+ for="zope.app.component.interfaces.ISite"
+ name="testsearch.html"
+ template="test.pt"
+ permission="zope.Public"/>
+
+</configure>
\ No newline at end of file
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/ftesting.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/ftests.py
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/ftests.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/ftests.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,13 @@
+from zope.app.testing import functional
+
+functional.defineLayer('TestLayer', 'ftesting.zcml')
+
+def test_suite():
+ suite = functional.FunctionalDocFileSuite(
+ 'README.txt',
+ )
+ suite.layer = TestLayer
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/ftests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/interfaces.py
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/interfaces.py 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/interfaces.py 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,9 @@
+from zope import interface
+from zope.publisher.interfaces.browser import IBrowserView
+
+class ILiveSearchView(IBrowserView):
+ """A view which renders the livesearch input field"""
+
+class ILiveSearchResultsView(IBrowserView):
+ """A view which renders the livesearch results"""
+
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/livesearch.pt
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/livesearch.pt 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/livesearch.pt 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,25 @@
+<div>
+ <script tal:content="
+ string:var lsResultURL = '${view/@@absolute_url}/@@results';">
+ </script>
+ <input autocomplete="off"
+ id="livesearch_input"
+ name="query"
+ size="30"
+ type="text"
+ value="" />
+ <div class="auto_complete"
+ id="livesearch_complete">
+ </div>
+
+
+ <script type="text/javascript">
+ <!--
+ new Ajax.Autocompleter(
+ 'livesearch_input',
+ 'livesearch_complete',
+ lsResultURL, {})
+ -->
+ </script>
+
+</div>
\ No newline at end of file
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/livesearch.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/results.pt
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/results.pt 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/results.pt 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,7 @@
+<ul class="autocomplete">
+ <li tal:repeat="result view/results">
+ <a href="result/url"
+ tal:attributes="href result/url"
+ tal:content="result/name"/>
+ </li>
+</ul>
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/results.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/test.pt
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/test.pt 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/test.pt 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1,6 @@
+<html metal:use-macro="context/@@standard_macros/view">
+ <div metal:fill-slot="body">
+
+ <div tal:replace="structure context/@@livesearch"/>
+ </div>
+</html>
\ No newline at end of file
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/test.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.livesearch/trunk/src/z3c/livesearch/z3c.livesearch-configure.zcml
===================================================================
--- z3c.livesearch/trunk/src/z3c/livesearch/z3c.livesearch-configure.zcml 2006-08-30 02:07:26 UTC (rev 69882)
+++ z3c.livesearch/trunk/src/z3c/livesearch/z3c.livesearch-configure.zcml 2006-08-30 06:08:02 UTC (rev 69883)
@@ -0,0 +1 @@
+<include package="z3c.livesearch"/>
\ No newline at end of file
Property changes on: z3c.livesearch/trunk/src/z3c/livesearch/z3c.livesearch-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list