Code

Ticket #9278: geoadmin_rtl_fix_v2.diff

File geoadmin_rtl_fix_v2.diff, 4.6 KB (added by jbronn, 5 years ago)
Line 
1Index: django/contrib/gis/admin/options.py
2===================================================================
3--- django/contrib/gis/admin/options.py (revision 9732)
4+++ django/contrib/gis/admin/options.py (working copy)
5@@ -28,12 +28,11 @@
6     scale_text = True
7     layerswitcher = True
8     scrollable = True
9-    admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
10     map_width = 600
11     map_height = 400
12     map_srid = 4326
13     map_template = 'gis/admin/openlayers.html'
14-    openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js'
15+    openlayers_url = 'http://openlayers.org/api/2.7/OpenLayers.js'
16     wms_url = 'http://labs.metacarta.com/wms/vmap0'
17     wms_layer = 'basic'
18     wms_name = 'OpenLayers WMS'
19@@ -76,8 +75,7 @@
20         class OLMap(self.widget):
21             template = self.map_template
22             geom_type = db_field._geom
23-            params = {'admin_media_prefix' : self.admin_media_prefix,
24-                      'default_lon' : self.default_lon,
25+            params = {'default_lon' : self.default_lon,
26                       'default_lat' : self.default_lat,
27                       'default_zoom' : self.default_zoom,
28                       'display_wkt' : self.debug or self.display_wkt,
29Index: django/contrib/gis/admin/widgets.py
30===================================================================
31--- django/contrib/gis/admin/widgets.py (revision 9732)
32+++ django/contrib/gis/admin/widgets.py (working copy)
33@@ -1,8 +1,16 @@
34+from django.conf import settings
35 from django.contrib.gis.gdal import OGRException
36 from django.contrib.gis.geos import GEOSGeometry, GEOSException
37 from django.forms.widgets import Textarea
38-from django.template.loader import render_to_string
39+from django.template import loader, Context
40+from django.utils import translation
41 
42+# Creating a template context that will contain settings values needed
43+# by the OpenLayers templates.
44+geo_context = Context({'ADMIN_MEDIA_PREFIX' : settings.ADMIN_MEDIA_PREFIX,
45+                       'LANGUAGE_BIDI' : translation.get_language_bidi(),
46+                       })
47+
48 class OpenLayersWidget(Textarea):
49     """
50     Renders an OpenLayers map using the WKT of the geometry.
51@@ -40,8 +48,9 @@
52             srid = self.params['srid']
53             if value.srid != srid:
54                 try:
55-                    value.transform(srid)
56-                    wkt = value.wkt
57+                    ogr = value.ogr
58+                    ogr.transform(srid)
59+                    wkt = ogr.wkt
60                 except OGRException:
61                     wkt = ''
62             else:
63@@ -51,7 +60,8 @@
64             # geometry.
65             self.params['wkt'] = wkt
66 
67-        return render_to_string(self.template, self.params)
68+        return loader.render_to_string(self.template, self.params,
69+                                       context_instance=geo_context)
70     
71     def map_options(self):
72         "Builds the map options hash for the OpenLayers template."
73Index: django/contrib/gis/templates/gis/admin/openlayers.html
74===================================================================
75--- django/contrib/gis/templates/gis/admin/openlayers.html      (revision 9732)
76+++ django/contrib/gis/templates/gis/admin/openlayers.html      (working copy)
77@@ -2,14 +2,14 @@
78 <style type="text/css">
79   #{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; }
80   #{{ id }}_map .aligned label { float:inherit; }
81-  #{{ id }}_admin_map { position: relative; vertical-align: top; float: left; }
82+  #{{ id }}_admin_map { position: relative; vertical-align: top; float: {{ LANGUAGE_BIDI|yesno:"right,left" }}; }
83   {% if not display_wkt %}#{{ id }} { display: none; }{% endif %}
84   .olControlEditingToolbar .olControlModifyFeatureItemActive {
85-     background-image: url("{{ admin_media_prefix }}img/gis/move_vertex_on.png");
86+     background-image: url("{{ ADMIN_MEDIA_PREFIX }}img/gis/move_vertex_on.png");
87      background-repeat: no-repeat;
88   }
89   .olControlEditingToolbar .olControlModifyFeatureItemInactive {
90-     background-image: url("{{ admin_media_prefix }}img/gis/move_vertex_off.png");
91+     background-image: url("{{ ADMIN_MEDIA_PREFIX }}img/gis/move_vertex_off.png");
92      background-repeat: no-repeat;
93   }
94 </style>
95@@ -29,7 +29,7 @@
96 {% block openlayers %}{% include "gis/admin/openlayers.js" %}{% endblock %}
97 //]]>
98 </script>
99-<div id="{{ id }}_map"></div>
100+<div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
101 <a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
102 {% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
103 <textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ field_name }}">{{ wkt }}</textarea>