Changeset 5483


Ignore:
Timestamp:
14/07/09 09:38:42 (10 years ago)
Author:
pnorton
Message:

Modified the GetCapabilities? response so that the styles are added to the data summary and picked up by the genshi template.

Location:
qesdi/wms_ddc_vis/trunk/lib/wms_ddc_vis
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • qesdi/wms_ddc_vis/trunk/lib/wms_ddc_vis/controllers/csmlwms.py

    r5479 r5483  
    1111 
    1212from cows.pylons.wms_controller import WMSController 
    13  
     13from cows.pylons import ows_controller 
     14 
     15from cows.model.wms import Style, LegendURL, FormattedURL 
     16from cows.xml.iso19115_subset import OnlineResource 
     17 
     18from genshi.template import TemplateLoader, NewTextTemplate 
     19from pkg_resources import resource_filename 
     20from routes import url_for 
    1421 
    1522log = logging.getLogger(__name__) 
     
    1724class CsmlwmsController(WMSController): 
    1825    layerMapper = DDCLayerMapper() 
     26 
     27    loader = TemplateLoader( resource_filename('wms_ddc_vis', 'templates'), 
     28                             auto_reload=True, 
     29                           ) 
     30 
     31    JSON_CAPABILITIES_TEMPLATE = "wms_capabilities_json.txt" 
     32    XML_CAPABILITIES_V1_1_1 = "wms_capabilities_1_1_1.xml" 
     33    XML_CAPABILITIES_V1_1_3 = "wms_capabilities_1_3_0.xml" 
     34     
     35 
     36    def _renderCapabilities(self, version, format): 
     37         
     38        for ds in c.capabilities.contents.datasetSummaries: 
     39             
     40            onlineRes = OnlineResource(url_for(qualified=True, action='index') + "?request=GetLegend&layers=%s" % ds.identifier) 
     41             
     42            legendURL = LegendURL(630, 80, format='img/png', onlineResource=onlineRes ) 
     43             
     44            gridStyle = Style('grid', 'Grid Boxes', legendURLs=[legendURL] ) 
     45            contourStyle = Style('contour', 'Contour Lines', legendURLs=[legendURL] ) 
     46             
     47            ds.styles = [gridStyle, contourStyle] 
     48             
     49            log.debug("dir(ds) = %s" % (dir(ds),)) 
     50            log.debug("ds.identifier = %s" % (ds.identifier,)) 
     51            log.debug("ds.styles = %s" % (ds.styles,)) 
     52            log.debug("ds.metadata = %s" % (ds.metadata,)) 
     53         
     54        if format == 'application/json': 
     55             
     56            t = self.loader.load(self.JSON_CAPABILITIES_TEMPLATE, 
     57                                                   cls=NewTextTemplate) 
     58        elif version == '1.1.1': 
     59            t = self.loader.load(self.XML_CAPABILITIES_V1_1_1) 
     60        elif version == '1.3.0': 
     61            t = self.loader.load(self.XML_CAPABILITIES_V1_1_3) 
     62        else: 
     63            # We should never get here!  The framework should raise an exception before now. 
     64            raise RuntimeError("Version %s not supported" % version) 
     65         
     66        return t.generate(c=c).render() 
    1967 
    2068    def _getLayerParam(self, paramName='layers'): 
Note: See TracChangeset for help on using the changeset viewer.