Changeset 2750 for TI05-delivery


Ignore:
Timestamp:
28/07/07 15:39:13 (12 years ago)
Author:
lawrence
Message:

Fixes for ticket:818

Location:
TI05-delivery/ows_framework/trunk/ows_server/ows_server
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/discovery.py

    r2745 r2750  
    66from ows_server.models.DIF import DIF 
    77from ows_server.templates.renderDiscoverySet import renderDiscoverySet 
    8 from ows_server.models.DiscoveryState import DiscoveryState 
     8from ows_server.models.DiscoveryState import DiscoveryState,constraints 
    99from ows_server.models.ndgObject import ndgObject 
    1010from ows_server.models.Utilities import myConfig 
    1111from ows_server.lib.mailer import mailHandler 
    1212 
    13 # Note that this code has not been ported to kid yet, it's pretty much the old 
    14 # code ported into this environment ... 
    1513 
    1614class DiscoveryController(BaseController): 
     
    2624         
    2725        self.__setup() 
    28         print request.environ['QUERY_STRING'] 
    29         print self.inputs 
    3026        # parse the query string and hand off to a discovery engine 
    3127        if self.inputs=={}: return self.__advancedPrompt() 
     
    9187            # ------------- Handle Date Ranges --------------- 
    9288            try: 
    93                 dateRange=[(self.inputs['startDateDay'],iMonth(self.inputs['startDateMon']),self.inputs['startDateYear']), 
    94                             (self.inputs['endDateDay'],iMonth(self.inputs['endDateMon']),self.inputs['endDateYear'])] 
     89                dateRange=[(self.inputs['startDateDay'],self.inputs['startDateMon'],self.inputs['startDateYear']), 
     90                            (self.inputs['endDateDay'],self.inputs['endDateMon'],self.inputs['endDateYear'])] 
    9591                #default form has blanks, in which case we don't want to check for date range 
    9692                if dateRange<>[("","",""),("","","")]: 
     
    10399                return render_response('content') 
    104100                 
     101                 
     102        if 'constrained' in self.inputs:  
     103            con=self.__buildconstraints(dateRange,bbox,scope,self.inputs['searchString']) 
     104            return self.__advancedPrompt(searchConstraints=con) 
     105        else: 
    105106        # ------------- ok, now go do the search ----------- 
    106         response=self.doText(self.inputs['searchString'],self.inputs['textTarget'], 
     107           response=self.doText(self.inputs['searchString'],self.inputs['textTarget'], 
    107108                self.inputs['start'],self.inputs['howmany'],scope=scope,dateRange=dateRange,bbox=bbox) 
    108             
    109         return response 
     109           return response 
    110110 
    111111    def doText(self,searchString,textTarget,start,howmany,scope=None,dateRange=None,bbox=None): 
     
    127127         
    128128        #build constraints info for report 
    129         constraints=self.__buildconstraints(dateRange,bbox,scope) 
     129        searchConstraints=self.__buildconstraints(dateRange,bbox,scope,searchString) 
    130130         
    131131        hits=ws.hits 
     
    133133         
    134134        if hits<howmany:howmany=hits 
    135         state=DiscoveryState(id,searchString,request.environ,hits,constraints,start,howmany) 
     135        state=DiscoveryState(id,searchString,request.environ,hits,searchConstraints,start,howmany) 
    136136         
    137137        if hits==0:  
     
    193193                                
    194194        return 
    195     def __advancedPrompt(self): 
     195    def __advancedPrompt(self,searchConstraints=None): 
    196196        ''' This provides the advanced search input page ''' 
    197197        try: 
     
    200200        except: 
    201201            return 'Error, invalid configuration for search interface' 
    202         bboxN,bboxW,bboxE,bboxS='+90.0','-180.0','+180.0','-90.0' 
     202        #defaults 
     203        c.bbox='+90.0','-180.0','+180.0','-90.0' 
    203204        c.startDateDay,c.startDateMon,c.startDateYear='','','' 
    204205        c.endDateDay,c.endDateMon,c.endDateYear='','','' 
     206        c.textTarget='All' 
     207        c.searchString='' 
     208        c.source=['All'] 
     209        #constraints 
     210        if searchConstraints is not None: 
     211            if searchConstraints['dateRange'] is not None: 
     212                c.startDateDay,c.startDateMon,c.startDateYear=searchConstraints['dateRange'][0] 
     213                c.endDateDay,c.endDateMon,c.endDateYear=searchConstraints['dateRange'][1] 
     214            if searchConstraints['bbox'] is not None: 
     215                bboxN,bboxW,bboxE,bboxS=searchConstraints['bbox'] 
     216            if searchConstraints['textTarget'] is not None: 
     217                c.textTarget=searchConstraints['textTarget'] 
     218            if searchConstraints['searchString'] is not None: 
     219                c.searchString=searchConstraints['searchString'] 
     220            if searchConstraints['scope'] is not None: 
     221                c.source=searchConstraintss['scope'] 
     222                 
    205223        return render_response('advanced') 
    206224         
     
    219237    def __checkdates(self,dateRange): 
    220238        ''' Check input dates for sanity ''' 
     239        print 'dr',dateRange 
    221240        if not ValidDate(dateRange[0])*ValidDate(dateRange[1]): 
    222             self.message='Input dates are not valid' 
     241            self.message='Input dates are not valid [%s]'%dateRange 
    223242        elif JulDay(dateRange[0])>=JulDay(dateRange[1]): 
    224243            self.message='Second date must be after first date' 
    225244         
    226     def __buildconstraints(self,dateRange,bbox,scope): 
     245    def __buildconstraints(self,dateRange,bbox,scope,searchString): 
    227246        ''' Just build a constraint string ''' 
    228         constraints='' 
    229         if dateRange is not None:  
    230             constraints+='Including&nbsp;%s&nbsp;to&nbsp;%s; '%('%s,%s,%s'%dateRange[0],'%s,%s,%s'%dateRange[1]) 
    231         if bbox is None or bbox==['+90.0','-90.0','-180.0','+180.0']: 
    232             constraints+='Global; ' 
    233         else: constraints+='Bounding&nbsp;Box:&nbsp;%s,%s,%s,%s; '%tuple(bbox) 
    234         if scope is not None: 
    235             constraints+='Restricted to %s; '%scope[0] 
    236         constraints=constraints[:-2] 
    237         logger.info('Constraints=%s'%constraints) 
    238         return constraints 
     247        return constraints(dateRange=dateRange,bbox=bbox,scope=scope,searchString=searchString) 
    239248         
    240249    def oneLineSearch(self): 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/DiscoveryState.py

    r2745 r2750  
    11from paste.request import parse_querystring,construct_url 
    22import cgi 
     3class constraints: 
     4    ''' A container object for constraints on a search ''' 
     5    def __init__(self, **kw): 
     6        self.values={} 
     7        keys=['dateRange','bbox','scope','textTarget','searchString'] 
     8        for key in keys:self.values[key]=None 
     9        print kw 
     10        for k in kw: self[k]=kw[k] 
     11             
     12    def __setitem__(self,key,value): 
     13        if key in self.values: 
     14            self.values[key]=value 
     15        else: 
     16            raise ValueError('Unknown key [%s] in constraints') 
     17     
     18    def __getitem__(self,key): 
     19        if key in self.values:  
     20            return self.values[key] 
     21        else: 
     22            raise ValueError('Unknown key [%s] in constraints'%key) 
     23     
     24    def __str__(self): 
     25        c='' 
     26        if self.values['dateRange'] is not None: 
     27            dr=self.values['dateRange']  
     28            c+='Including&nbsp;%s&nbsp;to&nbsp;%s; '%('%s,%s,%s'%dr[0],'%s,%s,%s'%dr[1]) 
     29        bbox=self.values['bbox'] 
     30        if bbox is None or bbox==['+90.0','-90.0','-180.0','+180.0']: 
     31            c+='Global; ' 
     32        else: c+='Bounding&nbsp;Box:&nbsp;%s,%s,%s,%s; '%tuple(bbox) 
     33        if self.values['scope'] is not None or self.values['textTarget'] is not None: 
     34            c+='Restricted to ' 
     35        if self.values['scope'] is not None: c+='%s; '%self.values['scope'] 
     36        if self.values['textTarget'] is not None: c+='%s; '%self.values['textTarget'] 
     37        return c[:-2] 
     38 
    339class DiscoveryState: 
    4     ''' This class holds the state associated with presenting multiple slices 
    5     of a large result set ''' 
     40    ''' This class holds the state associated with a search (including presenting multiple slices 
     41    of a large result set) ''' 
    642    def __init__(self,sessionID,searchString,environ,hits,constraints,offset=1,stride=10): 
    743        ''' On instantiation, provide 
     
    1046                the stride through the result set ''' 
    1147        self.environ=environ # the wsgi environment 
    12         self.constraints=constraints # some text to show constraints on search 
     48        self.constraintsInstance=constraints 
     49        self.constraints=str(constraints) # some text to show constraints on search 
     50        self.constrainedurl=self.geturl()+'&constrained' 
    1351        self.sessID=sessionID 
    1452        self.hits=hits 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/advanced.kid

    r2688 r2750  
    2929                            </div> 
    3030                            <div class="SearchBox"> 
    31                                 <label for="searchString"><input name="searchString" type="text" id="searchString" size="25" /></label> 
     31                                <label for="searchString"><input name="searchString" type="text" id="searchString" size="25" value="$c.searchString"/></label> 
    3232                                <label for="textTarget"><select name="textTarget" id="textTarget"> 
    3333                                <option value="All" selected="selected">All</option> 
     
    5757                           </div><br/>                   
    5858                            <div id="SearchSubmit"><input name="Search" type="submit" value="Search" />&nbsp;&nbsp;&nbsp; 
     59                             <form action="$g.discoveryURL"> 
     60                                <input type="submit" value="Clear Form"/> 
     61                            </form> 
    5962                            <input name="Clear form" type="reset" value="Clear form" /></div><br /> 
    6063                        </div> 
     
    9396                    <tr><td>Northerly Latitude:</td> 
    9497                        <td colspan="2" align="center"> 
    95                                 <input size="7" value="+90.0" name="bboxN"/> 
     98                                <input size="7" value="${c.bbox[0]}" name="bboxN"/> 
    9699                        </td></tr> 
    97100                    <tr><td>Longitudinal Extent:</td> 
    98                         <td align="center"><input size="8" value="-180.0" name="bboxW"/></td> 
    99                         <td align="center"><input size="8" value="+180.0" name="bboxE"/></td></tr> 
     101                        <td align="center"><input size="8" value="${c.bbox[1]}" name="bboxW"/></td> 
     102                        <td align="center"><input size="8" value="${c.bbox[2]}" name="bboxE"/></td></tr> 
    100103                    <tr><td> Southerly Latitude:</td> 
    101104                        <td colspan="2" align="center"> 
    102                             <input size="7" value="-90.0" name="bboxS"/> 
     105                            <input size="7" value="${c.bbox[3]}" name="bboxS"/> 
    103106                        </td></tr> 
    104107                        <tr><td colspan="3">(Units: degrees, north and east positive)</td></tr> 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/results.kid

    r2713 r2750  
    2727            ?> 
    2828            <div class="resultsBar"> 
    29                 <a href="${g.discoveryURL}?constraints=${c.constraints}"> Refine search</a>  
     29                <a href="${c.state.constrainedurl}"> Refine search</a>  
    3030                | Found ${c.state.hits} | Showing ${c.state.offset}-$upper  
    3131                  <span py:if="p!=[]"> | <a href="$purl"> Previous ${p[1]}</a> </span> 
     
    4343            </div> 
    4444            <div class="resultsBar"> 
    45                 <a href="${g.discoveryURL}?constraints=${c.constraints}"> Refine search</a>  
     45                <a href="${g.discoveryURL}?constraints=abc"> Refine search</a>  
    4646                | Found ${c.state.hits} | Showing ${c.state.offset}-$upper  
    4747                  <span py:if="p!=[]"> | <a href="$purl"> Previous ${p[1]}</a> </span> 
Note: See TracChangeset for help on using the changeset viewer.