Skip to content

Commit

Permalink
Merge pull request #247 from m-kuhn/units_alias
Browse files Browse the repository at this point in the history
Do not show [None] unit type
  • Loading branch information
m-kuhn authored Sep 20, 2018
2 parents 36fd3dc + 8954dff commit 2f5ac52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion projectgenerator/libqgsprojectgen/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def layers(self, filter_layer_list=[]):
if 'numeric_scale' in fielddef:
field.widget_config['Step'] = pow(10, -1 * fielddef['numeric_scale'])
# field.widget_config['Suffix'] = fielddef['unit'] if 'unit' in fielddef else ''
if 'unit' in fielddef:
if 'unit' in fielddef and fielddef['unit'] is not None:
field.alias = '{alias} [{unit}]'.format(
alias=alias or column_name, unit=fielddef['unit'])

Expand Down
23 changes: 23 additions & 0 deletions projectgenerator/tests/test_projectgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,29 @@ def test_meta_attr_toml_geopackage(self):

self.assertEqual(count, 3)

def test_unit(self):
importer = iliimporter.Importer()
importer.tool_name = 'ili2pg'
importer.configuration = iliimporter_config(importer.tool_name, 'ilimodels')
importer.configuration.ilimodels = 'ZG_Naturschutz_und_Erholung_V1_0'

importer.configuration.dbschema = 'nue_{:%Y%m%d%H%M%S%f}'.format(
datetime.datetime.now())
importer.configuration.epsg = 21781
importer.configuration.inheritance = 'smart2'
importer.stdout.connect(self.print_info)
importer.stderr.connect(self.print_error)
self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

generator = Generator(
'ili2pg', 'dbname=gis user=docker password=docker host=postgres', 'smart2', importer.configuration.dbschema)

available_layers = generator.layers()

infra_po = next((layer for layer in available_layers if layer.name == 'erholungsinfrastruktur_punktobjekt'))
naechste_kontrolle = next((field for field in infra_po.fields if field.name == 'naechste_kontrolle'))
self.assertEqual(naechste_kontrolle.alias, 'Naechste_Kontrolle')

def print_info(self, text):
logging.info(text)

Expand Down

0 comments on commit 2f5ac52

Please sign in to comment.