0

我的代码允许人们在提供的空间中输入关键字并单击搜索按钮,在数据库中搜索这些关键字并显示在其行中包含该关键字的 url。代码自动执行联合搜索。

我在名为 union 和 intersect 的页面中添加了两个单选按钮。如何更改我的代码以允许用户通过选择单选按钮来选择他们执行的搜索?

#!/usr/bin/env python2.7

import sys
import sqlite3
from string import Template
from cgi import FieldStorage
from dateutil import parser
from textwrap import dedent
from eicpy.www import CGIHandler
from eicpy.sql import ezsql

from eicpy import www
from eicpy import cgierror
cgierror.enable(display=True)

DB = ezsql().connect("/usr/HTTPServer/dev7/data/asq1.db")

class Page(CGIHandler):

def handle1(self):
   search_terms = self.fs.getfirst("searchinp", None)
   if search_terms:
      fields = search_terms.split(" ")
      steps = []
      apps = []

      for field in fields:
        recs = DB.execute("select issue, url, steps from help where k1='%s' or
        k2='%s' or k3='%s' or k4='%s' or k5='%s' or k6='%s' or k7='%s' or
        k8='%s' or k9='%s' or k10='%s' or k11='%s' or k12='%s' or k13='%s'" %
        (field, field, field, field, field, field, field, field, field, field,
        field, field, field)).fetchall()

#self.debug(recs)

for r in recs:
  if r.steps == "S":
    steps.append({
    "issue" : r.issue,
    "size" : "600x460",
    "location" : "/" + r.url
    })

if r.steps =="A":
    apps.append({
    "issue" : r.issue,
    "size" : "600x460",
    "location" : "/" + r.url
    })

#self.debug(steps)
#self.debug(apps)

self.show({"steps": steps, "apps": apps})

else :
   self.show({})

if __name__ == '__main__':
    p = Page('Agent Support Query'
        ,'pt/asq.xml'
        , ['/styles/asq.css'])
    p.handle1()

编辑:HTML/XML 代码:

<html>
  <head>
    <title>Agent support Query</title>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/styles/asq.css" />
    <script type="text/javascript" src="/yui/yahoo-dom-event/yahoo-dom-event.js">
       </script>
    <script type="text/javascript" src="/yui/connection/connection-min.js"></script>
    <script type="text/javascript" src="/scripts/eiLib.js"></script>
    <script type="text/javascript" src="/scripts/win7.js"></script>
  </head>

  <body>
    <div id="container">
      <div id="header">
        <div id="body">
          <div id="hd">
            <a href="/"><img src="/images/eic_small.jpg" width="145" height="45" /></a>
          </div><!-- hd -->
          <div id="title">
            <div><h1>Agent Support Query</h1></div>
          </div><!-- title -->
        </div><!-- body -->
      </div><!-- header -->
      <form action="#">
        <div id="searchspace">
          <div id="searchform">
            <div id="radio">
              Union<input type="radio" name="accept" value="iaccept">
                <br>
              Intersect<input type="radio" name="accept" value="notaccept">
            </div><!-- radio -->
            <div id="dropbox">
              <select>
                <option>keyword</option>
                <option></option>
                <option></option>
              </select>
            </div> <!-- dropbox -->            
            <div id="keyword">keyword(s) -</div>
              <input type="text" id="searchinp" name="searchinp" />
              <input type="submit" id="srch" name="srch" value="?" />
          </div><!-- searchform -->
        </div><!-- searchspace -->

    <!-- This is the important bits for creating the help links -->

        <div id="help">
          <div id="steps">
            <div tal:condition="exists:vars/steps">
              <div tal:repeat="item vars/steps">
                <h1 tal:attributes="onclick string:window.open('${item/location}',
                   'popup',
                      '${item/size},scrollbars=yes')"
                      tal:content="item/issue"></h1>
              </div><!-- tal:repeat -->
            </div><!-- tal:condition -->
         </div><!-- steps -->
         <div id="append">
           <div tal:condition="exists:vars/apps">
             <div tal:repeat="item vars/apps">
               <h1 tal:attributes="onclick string:window.open('${item/location}',
                   'popup',
                    '${item/size},scrollbars=yes')"
                     tal:content="item/issue"></h1>
             </div><!-- tal:repeat -->
           </div><!-- tal:condition -->
      </div><!-- append -->
    </div><!-- help -->
   </form>
  </div><!-- container -->
 </body>
</html>
4

0 回答 0