Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XML issues #914

Merged
merged 6 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%page args="exclusion_of_liability"/>
<data:ExclusionOfLiability xmlns="https://schemas.geo.admin.ch/V_D/OeREB/ExtractData.xsd">
<data:ExclusionOfLiability>
<data:Title>
<%include file="multilingual_text.xml" args="text=exclusion_of_liability.title"/>
</data:Title>
<data:Content>
<%include file="multilingual_m_text.xml" args="text=exclusion_of_liability.content"/>
</data:Content>
</data:ExclusionOfLiability>
</data:ExclusionOfLiability>
8 changes: 4 additions & 4 deletions pyramid_oereb/lib/renderer/extract/templates/xml/extract.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
<data:CantonalLogo>${extract.cantonal_logo.encode()}</data:CantonalLogo>
<data:MunicipalityLogo>${extract.municipality_logo.encode()}</data:MunicipalityLogo>
%else:
<data:LogoPLRCadastreRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='oereb')}</data:LogoPLRCadastreRef>
<data:FederalLogoRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='confederation')}</data:FederalLogoRef>
<data:CantonalLogoRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='canton')}</data:CantonalLogoRef>
<data:MunicipalityLogoRef>${request.route_url('{0}/image/municipality'.format(route_prefix), fosnr=extract.real_estate.fosnr)}</data:MunicipalityLogoRef>
<data:LogoPLRCadastreRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='oereb') | x}</data:LogoPLRCadastreRef>
<data:FederalLogoRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='confederation') | x}</data:FederalLogoRef>
<data:CantonalLogoRef>${request.route_url('{0}/image/logo'.format(route_prefix), logo='canton') | x}</data:CantonalLogoRef>
<data:MunicipalityLogoRef>${request.route_url('{0}/image/municipality'.format(route_prefix), fosnr=extract.real_estate.fosnr) | x}</data:MunicipalityLogoRef>
%endif
<data:ExtractIdentifier>${extract.extract_identifier}</data:ExtractIdentifier>
%if extract.qr_code:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%page args="line"/>
<% from itertools import chain %>
<gml:LineString gml:id="${get_gml_id()}">
%for position in line.coords:
<gml:pos>${position[0]} ${position[1]}</gml:pos>
%endfor
<gml:posList>
${' '.join(map(str,chain.from_iterable(line.coords)))}
</gml:posList>
</gml:LineString>
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<%page args="polygon"/>
<% from itertools import chain %>
<gml:Polygon gml:id="${get_gml_id()}">
<gml:exterior>
<gml:LinearRing>
%for position in polygon.exterior.coords:
<gml:pos>${position[0]} ${position[1]}</gml:pos>
%endfor
<gml:posList>
${' '.join(map(str,chain.from_iterable(polygon.exterior.coords)))}
</gml:posList>
</gml:LinearRing>
</gml:exterior>
%if len(polygon.interiors) > 0:
<gml:interior>
%for linear_ring in polygon.interiors:
<gml:LinearRing>
%for position in linear_ring.coords:
<gml:pos>${position[0]} ${position[1]}</gml:pos>
%endfor
</gml:LinearRing>
%if len(list(polygon.interiors)) > 0:
%for linear_ring in list(polygon.interiors):
<gml:interior>
<gml:LinearRing>
<gml:posList>
${' '.join(map(str,chain.from_iterable(linear_ring.coords)))}
</gml:posList>
</gml:LinearRing>
</gml:interior>
%endfor
</gml:interior>
%endif
</gml:Polygon>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%page args="glossary"/>
<data:Glossary xmlns="https://schemas.geo.admin.ch/V_D/OeREB/ExtractData.xsd">
<data:Glossary>
<data:Title>
<%include file="multilingual_text.xml" args="text=glossary.title"/>
</data:Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@
localized_text = localized(text)
%>
<data:Language>${localized_text.get('Language')}</data:Language>
% if urlparse.urlparse(localized_text.get('Text')).scheme:
<data:Text>${localized_text.get('Text')|u}</data:Text>
%else:
<data:Text>${localized_text.get('Text')}</data:Text>
% endif
<data:Text>${localized_text.get('Text') | x}</data:Text>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
% for localized_text in multilingual_text:
<data:LocalisedText>
<data:Language>${localized_text.get('Language')}</data:Language>
<data:Text>${localized_text.get('Text')}</data:Text>
<data:Text>${localized_text.get('Text') | x}</data:Text>
</data:LocalisedText>
% endfor
% endfor
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
% for localized_text in multilingual_text:
<data:LocalisedText>
<data:Language>${localized_text.get('Language')}</data:Language>
% if urlparse.urlparse(localized_text.get('Text')).scheme:
<data:Text>${localized_text.get('Text')|u}</data:Text>
%else:
<data:Text>${localized_text.get('Text')}</data:Text>
% endif
<data:Text>${localized_text.get('Text') | x}</data:Text>
</data:LocalisedText>
% endfor
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
% for localized_text in multilingual_text:
<data:LocalisedText>
<data:Language>${localized_text.get('Language')}</data:Language>
% if urlparse.urlparse(localized_text.get('Text')).scheme:
<data:Text>${localized_text.get('Text')|u}</data:Text>
%else:
<data:Text>${localized_text.get('Text')}</data:Text>
%endif
<data:Text>${localized_text.get('Text') | x}</data:Text>
</data:LocalisedText>
% endfor
6 changes: 4 additions & 2 deletions tests/renderer/xml/test_geometry_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def get_gml_id():
'get_gml_id': get_gml_id
}).decode('utf-8').split('\n')
expected_content = """

<gml:LineString gml:id="gml1">
<gml:pos>0.0 0.0</gml:pos>
<gml:pos>1.0 1.0</gml:pos>
<gml:posList>
0.0 0.0 1.0 1.0
</gml:posList>
</gml:LineString>
""".split('\n')
expected_lines = []
Expand Down
17 changes: 7 additions & 10 deletions tests/renderer/xml/test_geometry_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@ def get_gml_id():
'get_gml_id': get_gml_id
}).decode('utf-8').split('\n')
expected_content = """

<gml:Polygon gml:id="gml1">
<gml:exterior>
<gml:LinearRing>
<gml:pos>0.0 0.0</gml:pos>
<gml:pos>0.0 1.0</gml:pos>
<gml:pos>1.0 1.0</gml:pos>
<gml:pos>1.0 0.0</gml:pos>
<gml:pos>0.0 0.0</gml:pos>
<gml:posList>
0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0
</gml:posList>
</gml:LinearRing>
</gml:exterior>
<gml:interior>
<gml:LinearRing>
<gml:pos>0.25 0.25</gml:pos>
<gml:pos>0.25 0.75</gml:pos>
<gml:pos>0.75 0.75</gml:pos>
<gml:pos>0.75 0.25</gml:pos>
<gml:pos>0.25 0.25</gml:pos>
<gml:posList>
0.25 0.25 0.25 0.75 0.75 0.75 0.75 0.25 0.25 0.25
</gml:posList>
</gml:LinearRing>
</gml:interior>
</gml:Polygon>
Expand Down
50 changes: 44 additions & 6 deletions tests/renderer/xml/test_view_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,38 @@ def test_empty():

def test_reference_wms():
map = ViewServiceRecord(
reference_wms='http://example.com',
reference_wms='http://example.com?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&SRS=epsg:2056',
layer_index=0,
layer_opacity=1.0
)
content = template.render(**{
'map': map
}).decode('utf-8').split('\n')
assert content[1] == '<data:ReferenceWMS>http%3A%2F%2Fexample.com</data:ReferenceWMS>'
assert content[1] == """
<data:ReferenceWMS>
http%3A%2F%2Fexample.com%3F
SERVICE%3DWMS%26
REQUEST%3DGetMap%26
FORMAT%3Dimage%2Fpng%26
SRS%3Depsg%3A2056
</data:ReferenceWMS>
""".replace(" ", "").replace('\n', '')
assert len(content) == 5


def test_legend_at_web():
parameters = Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de')
renderer = Renderer(None)
legend_url = """
http://example.com?
SERVICE=WMS&
REQUEST=GetLegendGraphic&
FORMAT=image/png&
SRS=epsg:2056
""".replace(" ", "").replace('\n', '')
map = ViewServiceRecord(
reference_wms='',
legend_at_web={'de': 'http://example-legend.com'},
legend_at_web={'de': legend_url},
layer_index=0,
layer_opacity=1.0
)
Expand All @@ -52,16 +67,31 @@ def test_legend_at_web():
'map': map
}).decode('utf-8').split('\n')
assert len(content) == 6
assert content[2] == '<data:LegendAtWeb>http%3A%2F%2Fexample-legend.com</data:LegendAtWeb>'
assert content[2] == """
<data:LegendAtWeb>
http%3A%2F%2Fexample.com%3F
SERVICE%3DWMS%26
REQUEST%3DGetLegendGraphic%26
FORMAT%3Dimage%2Fpng%26
SRS%3Depsg%3A2056
</data:LegendAtWeb>
""".replace(" ", "").replace('\n', '')


def test_legend_at_web_no_language():
# Requests italian, but only german is available -> best effort: deliver german instead
parameters = Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'it')
renderer = Renderer(None)
legend_url = """
http://example.com?
SERVICE=WMS&
REQUEST=GetLegendGraphic&
FORMAT=image/png&
SRS=epsg:2056
""".replace(" ", "").replace('\n', '')
map = ViewServiceRecord(
reference_wms='',
legend_at_web={'de': 'http://example-legend.com'},
legend_at_web={'de': legend_url},
layer_index=0,
layer_opacity=1.0
)
Expand All @@ -71,4 +101,12 @@ def test_legend_at_web_no_language():
'map': map
}).decode('utf-8').split('\n')
assert len(content) == 6
assert content[2] == '<data:LegendAtWeb>http%3A%2F%2Fexample-legend.com</data:LegendAtWeb>'
assert content[2] == """
<data:LegendAtWeb>
http%3A%2F%2Fexample.com%3F
SERVICE%3DWMS%26
REQUEST%3DGetLegendGraphic%26
FORMAT%3Dimage%2Fpng%26
SRS%3Depsg%3A2056
</data:LegendAtWeb>
""".replace(" ", "").replace('\n', '')