def printImpactTable(self, theKeywords, theFilename=None): """High level table generator to print layer keywords. It gets the summary and impact table from a QgsMapLayer's keywords and renders to pdf, returning the resulting PDF file path. Args: theKeywords: dic containing impact layer keywords (required) Returns: str: Path to generated pdf file. Raises: None """ myFilePath = theFilename if theFilename is None: myFilePath = unique_filename(suffix='.pdf', dir=temp_dir()) try: mySummaryTable = theKeywords['impact_summary'] except KeyError: mySummaryTable = None myAttributionTable = impactLayerAttribution(theKeywords) try: myFullTable = theKeywords['impact_table'] except KeyError: myFullTable = None try: myAggregationTable = theKeywords['postprocessing_report'] except KeyError: myAggregationTable = None myHtml = '' if mySummaryTable != myFullTable and mySummaryTable is not None: myHtml = '<h2>%s</h2>' % self.tr('Summary Table') myHtml += mySummaryTable if myAggregationTable is not None: myHtml += myAggregationTable if myAttributionTable is not None: myHtml += myAttributionTable myHtml += '<h2>%s</h2>' % self.tr('Detailed Table') myHtml += myFullTable else: if myAggregationTable is not None: myHtml = myAggregationTable if myFullTable is not None: myHtml += myFullTable if myAttributionTable is not None: myHtml += myAttributionTable # myNewFilePath should be the same as myFilePath myNewFilePath = self.printToPdf(myHtml, myFilePath) return myNewFilePath
def test_impactLayerAttribution(self): """Test we get an attribution html snippet nicely for impact layers.""" myKeywords = {'hazard_title': 'Sample Hazard Title', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'Sample Exposure Title', 'exposure_source': 'Sample Exposure Source'} myHtml = impactLayerAttribution(myKeywords) print myHtml self.assertEqual(len(myHtml), 288)
def test_localisedAttribution(self): """Test we can localise attribution.""" os.environ['LANG'] = 'id' myKeywords = {'hazard_title': 'Jakarta 2007 flood', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'People in Jakarta', 'exposure_source': 'Sample Exposure Source'} myHtml = impactLayerAttribution(myKeywords, True) print myHtml assert myHtml == '11'