[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser - Find.py:1.1.2.1 __init__.py:1.1.2.1 browser.zcml:1.1.2.1 find.pt:1.1.2.1

Martijn Faassen m.faassen@vet.uu.nl
Tue, 9 Apr 2002 11:24:33 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv21631/OFS/Container/Find/Views/Browser

Added Files:
      Tag: Zope-3x-branch
	Find.py __init__.py browser.zcml find.pt 
Log Message:
Added a basic framework for finding objects. The UI right now only exposes 
looking for ids (see find;view).


=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser/Find.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
# 
##############################################################################
"""

$Id: Find.py,v 1.1.2.1 2002/04/09 15:24:31 faassen Exp $
"""

from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.PageTemplate.PageTemplateFile import PageTemplateFile
from Zope.App.OFS.Container.Find.IFind import IFind
# XXX this needs to be looked up in a registry
from Zope.App.OFS.Container.Find.FindAdapter import SimpleIdFindFilter

from Zope.ComponentArchitecture import getAdapter

# XXX very simple implementation right now
class Find(AttributePublisher):

    def __init__(self, context):
        self._context = context

    def getContext(self):
        return self._context
    
    index = PageTemplateFile('find.pt')

    def findByIds(self, ids):
        """Do a find for the ids listed in ids, which is a string.
        """
        finder = getAdapter(self._context, IFind)
        ids = ids.split()
        # if we don't have any ids listed, don't search at all
        if not ids:
            return []
        found = finder.find([SimpleIdFindFilter(ids)])
        return [getId(object) for object in found]

from Zope.ContextWrapper import getdict

# XXX get the id of an object (should be imported from somewhere)
def getId(object):
    dict = getdict(object)
    if dict:
        return dict.get('name')
    return None


=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser/__init__.py ===
# this is a package


=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser/browser.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security' 
   xmlns:browser='http://namespaces.zope.org/browser'
>

  <security:protectClass 
    name=".Find."
    permission_id="Zope.ManageContent" 
    methods="index, findByIds" />

  <browser:view for="Zope.App.OFS.Container.IContainer.IReadContainer"
    name="find" factory=".Find." />

</zopeConfigure>

=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/Views/Browser/find.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body" >
<form action="." method="GET">
<input type="text" name="ids" value="" /><br />
<input type="submit" name="find_submit" value=" Find " />
</form>
<table tal:condition="request/ids | nothing">
<tr tal:repeat="id python:view.findByIds(request['ids'])">
<td tal:content="id">id</td>
</tr>
</table>
</div>
</body>
</html>