[Zope3-checkins] CVS: Zope3/src/zope/app/browser/index/field - __init__.py:1.1 configure.zcml:1.1 control.pt:1.1 control.py:1.1

Marius Gedminas mgedmin@codeworks.lt
Sun, 22 Jun 2003 12:10:56 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/index/field
In directory cvs.zope.org:/tmp/cvs-serv11775/src/zope/app/browser/index/field

Added Files:
	__init__.py configure.zcml control.pt control.py 
Log Message:
Added views for FieldIndex


=== Added File Zope3/src/zope/app/browser/index/field/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/index/field/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
>

  <browser:addform
    name="AddFieldIndex"
    menu="add_component" title="Field Index"
    schema="zope.app.interfaces.index.field.IUIFieldIndex"
    permission="zope.ManageServices"
    content_factory="zope.app.index.field.index.FieldIndex"
    arguments="field_name"
    />

  <browser:page
    for="zope.app.interfaces.index.field.IUIFieldIndex"
    name="index.html" 
    menu="zmi_views"
    title="Control"
    permission="zope.ManageServices"
    class=".control.ControlView"
    template="control.pt" />

</zopeConfigure>


=== Added File Zope3/src/zope/app/browser/index/field/control.pt ===
<html metal:use-macro="views/standard_macros/page">

  <head>
    <title>FieldIndex Control Page</title>
  </head>

  <body>

  <div metal:fill-slot="body">

    <h1><br>FieldIndex</h1>

    <p class="form-help">
        This page lets you control a field index, which is used to
        provide a single field searching facility.  The search box here is
        only for debugging.  Subscription status: A "subscribed" index
        will update itself whenever objects are added, deleted or
        modified; an "unsubscribed" index will retain the indexing
        information but not update itself further.
    </p>

    <span tal:condition="request/callSubscribe|nothing" tal:omit-tag="">
        <span tal:define="dummy context/subscribe" tal:omit-tag=""/>
        Successfully subscribed.
    </span>
    <span tal:condition="request/callUnsubscribe|nothing" tal:omit-tag="">
        <span tal:define="dummy context/unsubscribe" tal:omit-tag=""/>
        Successfully unsubscribed.
    </span>

    <div>
        Documents: <span tal:replace="context/documentCount" />
    </div>

    <form method="POST">
       <span tal:condition="context/isSubscribed" tal:omit-tag="">
           Subscription state: ON
           <input type="submit" value="Unsubscribe" name="callUnsubscribe" />
       </span>
       <span tal:condition="not:context/isSubscribed" tal:omit-tag="">
           Subscription state: OFF
           <input type="submit" value="Subscribe" name="callSubscribe" />
       </span>
       <input type="hidden" name="queryText" value=""
              tal:attributes="value request/queryText|nothing" />
    </form>

    <form method="GET">
        <input type="text" name="queryText" value=""
               tal:attributes="value request/queryText|nothing" />
        <input type="submit" value="Query" />
    </form>

    <div tal:condition="request/queryText|nothing" tal:omit-tag="">
        <div tal:define="result view/query" tal:omit-tag="">
	    <div tal:condition="not:result/total">
	        No hits.  Please try another query.
	    </div>
	    <div tal:condition="result/total">
		<div tal:content="
		string:Hits ${result/first}-${result/last} of ${result/total}:"
		/>
		<div tal:repeat="info result/results">
	            title=<span tal:replace="info/title" />;
		    url=<a href="location"
		            tal:attributes="href info/location"
                            tal:content="info/location">url</a>
		</div>
	    </div>
	    <span tal:condition="exists:result/prev">
                <a href="next"
                   tal:attributes="href
                       string:?queryText=${request/queryText}&start=${view/prevBatch}">&lt;-- PREVIOUS BATCH</a>
	    </span>
	    <span tal:condition="exists:result/next">
                <a href="next"
                   tal:attributes="href
                       string:?queryText=${request/queryText}&start=${view/nextBatch}">NEXT BATCH --&gt;</a>
	    </span>
        </div>
    </div>

  </div>

  </body>

</html>


=== Added File Zope3/src/zope/app/browser/index/field/control.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Control view for the text index.

XXX longer description goes here.

$Id: control.py,v 1.1 2003/06/22 16:10:55 mgedmin Exp $
"""

from __future__ import generators

from zope.interface import implements
from zope.component import getService, queryAdapter
from zope.app.services.servicenames import HubIds
from zope.exceptions import NotFoundError
from zope.publisher.browser import BrowserView

from zope.app.traversing import canonicalPath
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.app.interfaces.index.text import IQueryView

class ControlView(BrowserView):

    implements(IQueryView)

    def __init__(self, context, request):
        super(ControlView, self).__init__(context, request)
        self.hub = getService(context, HubIds)

    def query(self):
        queryText = self.request.get('queryText', '')
        results = self.context.search(queryText)
        nresults = len(results)
        first = 1
        last = first + len(results) - 1
        result = {
            'results': list(self._resultIterator(results)),
            'nresults': nresults,
            'first': first,
            'last': last,
            'total': nresults,
            }
        return result

    def _resultIterator(self, results):
        for hubid in results:
            yield self._cookInfo(hubid)

    def _cookInfo(self, hubid):
        location = canonicalPath(self.hub.getPath(hubid))
        # XXX `location` is later used as a URL in a page template, using a
        #     physical path instead of absolute_url will break virtual hosting.
        result = {
            'location': location,
            }
        try:
            object = self.hub.getObject(hubid)
        except NotFoundError:
            pass
        else:
            dc = queryAdapter(object, IZopeDublinCore, context=self.context)
            if dc is not None:
                title = dc.title
                result['title'] = title
        return result