From edf65ddc4c545a16210a994d2d573ccbe7ad02c0 Mon Sep 17 00:00:00 2001
From: anonymous <anonymous>
Date: Wed, 28 Nov 2018 16:22:12 +0100
Subject: [PATCH] ODPSH-137: add bounding box to info page

---
 ckanext/odsh/helpers.py                       |  41 ++++++++++++++++++
 .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo  | Bin 4573 -> 4857 bytes
 .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po  |  18 ++++++++
 ckanext/odsh/plugin.py                        |  12 ++---
 ckanext/odsh/public/odsh.css                  |   8 +++-
 ckanext/odsh/templates/package/read_base.html |  20 +++++++++
 .../odsh/templates/package/snippets/info.html |   8 ----
 7 files changed, 90 insertions(+), 17 deletions(-)

diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py
index ab703c68..a41383ed 100644
--- a/ckanext/odsh/helpers.py
+++ b/ckanext/odsh/helpers.py
@@ -4,6 +4,7 @@ import ast
 import ckan.plugins.toolkit as toolkit
 import ckan.logic as logic
 import ckan.model as model
+import json
 from ckan.common import  c
 
 get_action = logic.get_action
@@ -46,3 +47,43 @@ def odsh_get_resource_views(pkg_dict, resource):
         return get_action('resource_view_list')(
             context, {'id': resource['id']})
 
+def odsh_get_bounding_box(pkg_dict):
+    try:
+        extras=pkg_dict.get('extras')
+        spatial=None
+        for f in extras:
+            if 'key' in f and f['key'] == 'spatial':
+                spatial=f['value']
+                break
+
+        if spatial is not None:
+            d = json.loads(spatial)
+            if 'coordinates' in d:
+                coords=d['coordinates']
+                return compute_bounding_box(coords)
+    except Exception, e:
+        log.error('Error while bounding box %s: %s\nException: %s',
+            e.__class__.__name__,  unicode(e), traceback.format_exc())
+    return None 
+
+def compute_bounding_box(coords):
+    if len(coords)==0:
+        return None
+
+    coords = [c for sublist in coords for c in sublist]
+
+    minx = min(coords, key = lambda t: t[0])[0]
+    maxx = max(coords, key = lambda t: t[0])[0]
+    miny = min(coords, key = lambda t: t[1])[1]
+    maxy = max(coords, key = lambda t: t[1])[1]
+     
+    return [maxx, minx, maxy, miny]
+
+def odsh_get_spatial_text(pkg_dict):
+    extras=pkg_dict.get('extras')
+    spatial=None
+    for f in extras:
+        if 'key' in f and f['key'] == 'spatial_text':
+            spatial=f['value']
+            return spatial
+    return None 
\ No newline at end of file
diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo
index 1c1591e99aaf2584f0359eebf5b23e51f151bf71..ea33e500d2dfdaca01704f6b45d3afa93cdd7058 100644
GIT binary patch
delta 1520
zcmcbs{8P35o)F7a1_lNOKL!Q{83qQ19wrbEf&Z{DFbFX)F#Kg<VBlt8U=UzsU{D3A
zWre7BVr5`pWnf^4XJueuXJBARWre8AWo2OCXJBBcWMyDbW?*3GWMyFBVqjoc%gVqY
z$iTp`gO!0nfq|i(;S?(agCqk3!)vGnD;q?iI2*(uB{ql!dTbDfn6NQ0urV+&xU(@Z
zaDp7p#=s!Kz`zgz6)$9iIHUq<P6JebH&lKi8v_F$0|UbhHjqc^85owcF)*kwFfg2D
zV_*<rU|{&f#=s!Uz`(%H&cMLSz`&r&4soC{J4B-|J49U!JH&y7><kRj3=9ml><kRr
z3=9l2*&#kZ%Fe(b#lXODm7Rfsg@J+L13Lo)4+8_kSExBm91IM)^$ZLQf*cGCq6`cS
z_8btOhH@}4a4;}1L~}rVn!*9GI2$Tn#lgTJ&cMLX%mJ}zHV4Fl)lhXCpyK<X>d$jP
zLi7ey{xMYjCk_UNdQhBwhbsIJr8zhuK`6)x@u4Iq!~#`L1_ogU1_muoh=c7oAt4pQ
z2?|OEh9XV|202jBa)RTQVLK-z<Zf_6qUsYT0|O{|{o!O_&|_d=_|M5u&)~(tz@W#)
zz+eGNEL;o>6Brp7HgQ3M-kApyw}Cti42BF03|Tx7i{|h^<PY&cg7gBEzRLq~*ef1L
zl!D?<3>1aD5OEt`1_m_-28JMB1_pVMeZ2J$gJwb%Ea!y;^<G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*vSrY
z;dyoj1`Y-WhO6ulm)?VFcnTH&!p^`T&cML%7iy6x2gCwZ4v58C91#6h91x#7b3iQg
zgQ|<=fH*t}%Fp9qV5k>nU|=ZbU|<ksU|?wHfP}zY4oDpD=3rouV_;x-$N`QkaCn2F
zN|6)HWU%IBU;rf-S55{7Jy06rWMJ@OU|=ZcWMHshU|=}J$-ppyk%8eiCnQ9BxFJzB
zi<^PLkb!|=GdDv$I59othA80XfdrK#lvd+`ILw#_6juxko;(Z;Vhjunc~J3I9tH+A
z1_p-NJPZu-APadQ<~)MRf8c?H02?nPO^EU`FbFU(Fv#*kLRgQt9uichypY7@zzg9A
zLlwk9=~P}w6y-qqMZAzSQ^^Ynp*~(nZdl6;amXoNNKn7xg@ougUWi9T_#h#m#RmyN
z=XyQ{1}#vw;A3D=WME*Z;DaQ(S$qr(nhXpKTlgS8y2r=B0E((Nd=P^`dCQ1_fkBKP
zVxcEL#DSUo5QFpiAwH~x@*DUeX{C!F5@P-QkdUn3#t#Xav;2^txeC?rj2~k02YyI?
z{m0M1z|6qFARquyCn5l`Ko!c@5ny1@U|?Xd6@aAfGyzB&nj*l!0CMOq0Z0_S6@Yj^
zND!P@l^HYyAqE=?GB8*&Fff=3GB7xUvWp-j1U3t9{>8GEar0TW$BdKrb69Ma<kVr^
ST*&9nH2IW({bmEflZ*f!yljvF

diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po
index 204d8fee..15630acb 100644
--- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po
+++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po
@@ -243,3 +243,21 @@ msgstr "zurücksetzen"
 
 msgid "There is no description for this organization"
 msgstr "Es gibt keine Beschreibung für diesen Herausgeber"
+
+msgid "in east"
+msgstr "im Osten"
+
+msgid "in west"
+msgstr "im Westen"
+
+msgid "in north"
+msgstr "im Norden"
+
+msgid "in south"
+msgstr "im Süden"
+
+msgid "borders of map"
+msgstr "Grenzen der Karte"
+
+msgid "Map showing the borders of {map_text}"
+msgstr "Karte, die die Grenzen von {map_text} zeigt"
\ No newline at end of file
diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py
index 5370eb1a..bdcdaeea 100644
--- a/ckanext/odsh/plugin.py
+++ b/ckanext/odsh/plugin.py
@@ -83,7 +83,6 @@ def known_spatial_uri(key, data, errors, context):
             spatial_text = row[1]
             loaded = json.loads(row[2])
             spatial = json.dumps(loaded['geometry'])
-            print spatial
             break
     if not_found:
         raise toolkit.Invalid("The specified URI is not known")
@@ -133,7 +132,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
                 'odsh_get_facet_items_dict': odsh_get_facet_items_dict,
                 'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html,
                 'odsh_get_resource_details': odsh_helpers.odsh_get_resource_details,
-                'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views
+                'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views,
+                'odsh_get_bounding_box': odsh_helpers.odsh_get_bounding_box,
+                'odsh_get_spatial_text': odsh_helpers.odsh_get_spatial_text
         }
 
     def before_map(self, map):
@@ -199,7 +200,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
                            'groups': _('Kategorie')})
 
     def _fields(self):
-        # return ['title','notes','tag_string']
         return ['title','notes']
 
     def _extraFields(self):
@@ -223,13 +223,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
                     toolkit.get_converter('convert_to_extras')]})
         for field in self._fields():
             schema.update({field: [toolkit.get_converter('not_empty')]})
-        # schema.update({ 'groups': [
-        #         # toolkit.get_converter('not_empty'),
-        #         toolkit.get_converter('odsh_convert_groups_string')] })
+
         schema['resources'].update({
                 'url' : [ toolkit.get_converter('not_empty') ]
-                # 'description' : [ toolkit.get_converter('not_empty') ],
-                # 'name' : [ toolkit.get_converter('not_empty') ]
                 })
 
     def create_package_schema(self):
diff --git a/ckanext/odsh/public/odsh.css b/ckanext/odsh/public/odsh.css
index c9f40b66..abdb5c6a 100644
--- a/ckanext/odsh/public/odsh.css
+++ b/ckanext/odsh/public/odsh.css
@@ -814,7 +814,13 @@ body {
     max-width: 193px;
     word-break: break-all;
 }
-
+.info-detail p{
+    margin: 0;
+}
+.info-detail .map-text{
+    margin-top: 5px;
+    margin-bottom: 5px;
+}
 .odsh-dataset-heading {
     margin-bottom: 30px;
 }
diff --git a/ckanext/odsh/templates/package/read_base.html b/ckanext/odsh/templates/package/read_base.html
index 4cf4dc02..ef23352a 100644
--- a/ckanext/odsh/templates/package/read_base.html
+++ b/ckanext/odsh/templates/package/read_base.html
@@ -33,6 +33,26 @@
 {% if dataset_extent %}
 {% snippet "spatial/snippets/dataset_map_sidebar.html", extent=dataset_extent %}
 {% endif %}
+{% block spatial_info %}
+{% set map_text = h.odsh_get_spatial_text(pkg) %}
+<div class="spatial-detail info-detail">
+    <div>{{ _('Spatial uri') }}:</div>
+    {%set ext=map_text if map_text else '-'%}
+    <p>{{ ext }}</p>
+</div>
+
+<div class="info-detail">
+    <p class='map-text'> {{_('Map showing the borders of {map_text}').format(map_text=map_text)}} </p>
+    {% set bbox = h.odsh_get_bounding_box(pkg) %}
+    {% if bbox%}
+    <div>{{ _('borders of map') }}:</div>
+    <p> {{ '{0:0.3f}'.format(bbox[0]).zfill(2).replace('.',',') }}° {{_('in east')}}</p>
+    <p> {{ '{0:0.3f}'.format(bbox[1]).replace('.',',') }}° {{_('in west')}}</p>
+    <p> {{ '{0:0.3f}'.format(bbox[2]).replace('.',',') }}° {{_('in south')}}</p>
+    <p> {{ '{0:0.3f}'.format(bbox[3]).replace('.',',') }}° {{_('in north')}}</p>
+    {% endif %}
+</div>
+{% endblock %}
 {% endblock %}
 
 {% endblock %}
\ No newline at end of file
diff --git a/ckanext/odsh/templates/package/snippets/info.html b/ckanext/odsh/templates/package/snippets/info.html
index 46fadc1c..df9121e8 100644
--- a/ckanext/odsh/templates/package/snippets/info.html
+++ b/ckanext/odsh/templates/package/snippets/info.html
@@ -33,14 +33,6 @@ Example:
             {% block nums %}
             {% endblock %}
 
-            {% block spatial %}
-            <div class="spatial-detail info-detail">
-                <div>{{ _('Spatial uri') }}:</div>
-                {%set ext=pkg.spatial_uri if pkg.spatial_uri else '-'%}
-                <p>{{ ext }}</p>
-            </div>
-            {% endblock %}
-
             {% block tags %}
             <div class="tags-detail info-detail">
                 <div>{{ _('Tags') }}:</div>
-- 
GitLab