Changeset 5303 for MILK


Ignore:
Timestamp:
18/05/09 17:18:17 (10 years ago)
Author:
cbyrom
Message:

Retrieve the 'orderByFieldList' data from the discovery ws + add new
drop down to set the order by direction and implement the logic
for using this.

Location:
MILK/trunk/milk_server/milk_server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/config/milkMiddleware.py

    r5302 r5303  
    66from ndg.common.src.lib.atomvalidator import AtomValidator 
    77from ndg.common.src.clients.http.vocabserverclient import VocabServerClient 
     8from ndg.common.src.clients.ws.discovery.discoveryserviceclient import DiscoveryServiceClient 
    89import milk_server.lib.helpers as h 
    910 
     
    7879        # used by discoveryServiceClient 
    7980        self.globals.discoveryServiceURL = cf.get('DISCOVERY', 'discoveryServiceURL') 
     81 
     82        searchClient = DiscoveryServiceClient(HostAndPort = self.globals.discoveryServiceURL) 
     83        # Look up values to use in the 'order by' list 
     84        orderByVals = searchClient.getList('orderByFieldList') 
     85        self.globals.orderByList = orderByVals 
    8086                 
    8187        self.globals.pwFile = cf.get('NDG_EXIST','passwordFile') 
     
    193199        g.example_granulite = g.example_granulite.replace('HREF', \ 
    194200            h.url_for('example')) 
    195          
    196          
     201 
     202 
    197203    def __call__(self,environ,start_response): 
    198204         
  • MILK/trunk/milk_server/milk_server/controllers/browse/discovery.py

    r5302 r5303  
    3636         
    3737        c.discoveryUrl = h.url_for('discovery') 
    38  
    39         orderBySelect = "" 
    40         if 'orderBy' in self.inputs: 
    41             orderBySelect = self.inputs['orderBy'] 
    42         c.orderByList = h.options_for_select(constants.ORDER_BY_LIST, orderBySelect)                
     38                        
    4339     
    4440    def index(self): 
     
    5955        
    6056        self.__getInputs() 
     57 
     58        if 'orderBy' not in self.inputs: 
     59            self.inputs['orderBy'] = g.orderByList[0] 
     60        c.orderByList = h.options_for_select(g.orderByList, self.inputs['orderBy']) 
     61 
     62        if 'orderDirection' not in self.inputs: 
     63            self.inputs['orderDirection'] = constants.ORDER_BY_DIRECTION[0] 
     64        c.orderDirection = h.options_for_select(constants.ORDER_BY_DIRECTION, 
     65                                                self.inputs['orderDirection'])  
    6166         
    6267        # if any errors are found, return user to search page 
     
    7883        try: 
    7984            return self.__runSearch(searchString, self.inputs['textTarget'], 
    80                                  self.inputs['start'], self.inputs['howmany'],  
    81                                  scope = self.scope, dateRange = self.dateRange,  
    82                                  bbox = self.bbox, geoSearch=self.inputs['geoSearchType']) 
     85                                    self.inputs['start'], self.inputs['howmany'],  
     86                                    orderBy = self.inputs['orderBy'],  
     87                                    orderDirection = self.inputs['orderDirection'], 
     88                                    scope = self.scope, dateRange = self.dateRange,  
     89                                    bbox = self.bbox, geoSearch=self.inputs['geoSearchType']) 
    8390        except Exception, e: 
    8491            if g.debugModeOn == 'True': 
     
    100107            constraints = getURLConstraints(self.inputs['constraints']) 
    101108            del self.inputs['constraints'] 
    102             self.inputs.update(constraints) 
     109            # NB, be careful not to overwrite newly passed in info 
     110            for key, val in constraints.items(): 
     111                if key not in self.inputs: 
     112                    self.inputs[key] = val 
    103113                     
    104114        if 'vocabTerm' in self.inputs and 'searchString' not in self.inputs: 
     
    177187                c.inputErrors[bc.INVALID_BBOX_MESSAGE].extend(errors) 
    178188 
    179         # NB 
    180189        missingInputs = self.__checkform(['startDate', 'endDate']) 
     190        self.dateRange = None 
    181191        if missingInputs: 
    182192            self.dateRange = None 
     
    185195        elif not self.inputs['startDate'] and self.inputs['endDate']: 
    186196            c.inputErrors[bc.INCOMPLETE_DATERANGE_MESSAGE] = ['Start date missing'] 
    187         else: 
     197        elif self.inputs['startDate'] and self.inputs['endDate']: 
    188198            dateError = None 
    189199            try: 
     
    241251 
    242252    def __runSearch(self, searchString, textTarget, start, 
    243                  howmany, scope = None, dateRange = None, bbox = None, 
    244                  geoSearch = 'overlaps'): 
     253                    howmany, orderBy = None, orderDirection = None, scope = None,  
     254                    dateRange = None, bbox = None, geoSearch = 'overlaps'): 
    245255        '''  
    246256        Carry out a text search for <searchString>  
     
    251261        @param start: starting record to return 
    252262        @param howmany: number of records to return 
     263        @keyword orderBy: Field to order results by - NB, must be one of the 
     264        getList('orderByFieldList') values 
     265        @keyword orderDirection: Direction the 'orderBy' results should be returned in 
     266        - NB, this is currently 'ascending' or 'descending' 
    253267        @keyword scope: scope of search - either NERC, NERC_DDC, MDIP or DPPP. Default = None 
    254268        @keyword dateRange: date range in format [startDate, endDate] where the 
     
    279293                                dateRange = dateRange, 
    280294                                bbox = bbox, 
    281                                 geoSearchType = geoSearch) 
     295                                geoSearchType = geoSearch, 
     296                                orderBy = orderBy, 
     297                                orderDirection = orderDirection) 
    282298        except socket.error, e: 
    283299            logging.error("Socket error for discovery service search: %s" % e) 
  • MILK/trunk/milk_server/milk_server/lib/constants.py

    r5302 r5303  
    2323 
    2424# NB, this info should probably be retrieved from the discovery web service 
    25 ORDER_BY_LIST = [["Date", "date"], ["Data Centre", "dataCentre"]] 
     25ORDER_BY_DIRECTION = ["ascending", "descending"] 
  • MILK/trunk/milk_server/milk_server/templates/browse/results.kid

    r5302 r5303  
    3333                    <span py:if="c.state.hits != 0" py:strip="">  
    3434                                | Order By ${XML(h.select('orderBy',option_tags = c.orderByList, onchange="orderByForm.submit()"))} 
     35                                ${XML(h.select('orderDirection',option_tags = c.orderDirection, onchange="orderByForm.submit()"))} 
    3536                        | Found ${c.state.hits}  
    3637                            <span py:if="p!=[]"> | <a href="$purl"> Previous ${p[1]}</a> </span> 
Note: See TracChangeset for help on using the changeset viewer.