Igor Támara avatar Igor Támara committed a576582

Initial import of osm plugin for django-cms

Comments (0)

Files changed (10)

+syntax: glob
+*~
+*pyc
+ @sthevenb
+ @woakas
+ @ikks
+First Version of plugin inspired in googlemaps plugin
+include AUTHORS
+include README.txt
+recursive-include osm/templates *
+This plugin includes an iframe with a map in the places you
+define for django-cms
+
+Configuration
+=============
+
+inside 'settings.py' add 
+  'osm'
+to 'INSTALLED_APPS'
+
+don't forget to syncdb
+
+Tested With
+===========
+
+- Django-1.2.5
+- django_cms-2.1.3
+
Add a comment to this file

django-cms-osm-screenshot.png

Added
New image

Empty file added.

osm/cms_plugins.py

+from cms.plugin_base import CMSPluginBase
+from cms.plugin_pool import plugin_pool
+from models import OsmMap
+from django.utils.translation import ugettext as _
+
+class OsmMapPlugin(CMSPluginBase):
+    model = OsmMap
+    name = _("Openstreetmap")
+    render_template = "cms/plugins/osm.html"
+
+    def render(self, context, instance, placeholder):
+        context.update({
+            'object':instance, 
+            'placeholder':placeholder, 
+        })
+        return context
+    
+plugin_pool.register_plugin(OsmMapPlugin)
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from cms.models import CMSPlugin
+from decimal import *
+import sys
+
+class OsmMap(CMSPlugin):
+    title = models.CharField(_("map title"), max_length=100, blank=True, null=True)
+    address = models.CharField(_("address"), max_length=150)
+    zoom = models.IntegerField(_("zoom level"), blank=True, null=True)
+    lat = models.DecimalField(_('latitude'), max_digits=10, decimal_places=6, null=True, blank=True, 
+        help_text=_('Use latitude & longitude to fine tune the map possiton.'))
+    lng = models.DecimalField(_('longitude'), max_digits=10, decimal_places=6, null=True, blank=True)
+    content = models.CharField(_("content"), max_length=1500, blank=True, null=True)
+
+    def __unicode__(self):
+        return u"%s (%s)" % (self.get_title(), self.address)
+    
+    def get_title(self):
+        return self.title or  _("Map")
+
+    def get_content(self):
+        return self.content or ""
+
+    def get_zoom_level(self):
+        return  self.zoom or 13    
+    
+    def get_lat_lng(self):
+        if self.lat and self.lng:
+            return [self.lat, self.lng]
+
+    def get_bbox(self):
+        try :
+            if self.lat and self.lng and self.zoom:
+                size = Decimal(str(180.0 / (2**(self.zoom+1))))
+                return [self.lng-size,self.lat-size,self.lng+size,self.lat+size]
+        except:
+            return ["-74.096282645507812","4.747965354492188","-74.094909354492188","4.749338645507812"]
+

osm/templates/cms/plugins/osm.html

+{% load i18n %}
+<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.openstreetmap.org/export/embed.html?bbox={{ object.get_bbox|join:"," }}&amp;layer=mapnik&amp;marker={{ object.lat }},{{ object.lng }}" style="border: 1px solid black"></iframe><br /><small><a href="http://www.openstreetmap.org/?lat={{ object.lat }}&amp;lon={{ object.lng }}&amp;zoom={{ object.zoom }}&amp;layers=M&amp;mlat={{ object.lat }}&amp;mlon={{ object.lng }}">{{ object.get_content }}</a></small>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.