Commits

Mikhail Korobov  committed a24d7f6

Фильтр для вывода статичных яндекс-карт

  • Participants
  • Parent commits 2c8839e

Comments (0)

Files changed (4)

 
 setup(
       name='django-yandex-maps',
-      version='0.1',
+      version='0.2',
       author='Mikhail Korobov',
       author_email='kmike84@gmail.com',
       url='http://bitbucket.org/kmike/django-yandex-maps/',
 
       description = 'Django app for work with Yandex Maps service.',
       license = 'MIT license',
-      packages=['yandex_maps'],
+      packages=['yandex_maps', 'yandex_maps.templatetags'],
 
       package_data={'yandex_maps': ['templates/yandex_maps/*']},
 

File yandex_maps/models.py

         return 5
 
     def get_map_url(self, width=None, height=None, detail_level = 5):
-        w = width if width else settings.YANDEX_MAPS_W
-        h = height if height else settings.YANDEX_MAPS_H
+        w = int(width) if width else settings.YANDEX_MAPS_W
+        h = int(height) if height else settings.YANDEX_MAPS_H
+        detail_level = int(detail_level) or self.get_detail_level()
         if YANDEX_KEY is not None:
-            return utils.get_map_url(YANDEX_KEY, self.longtitude, self.latitude, self.get_detail_level(), w, h)
+            return utils.get_map_url(YANDEX_KEY, self.longtitude, self.latitude, detail_level, w, h)
         else:
             return ''
 

File yandex_maps/templatetags/__init__.py

Empty file added.

File yandex_maps/templatetags/yandex_maps.py

+#coding: utf-8
+from django import template
+
+register = template.Library()
+
+@register.filter
+def static_map_url(address, params=None):
+    ''' Фильтр, который возвращает URL картинки с картой.
+        Применять на объект класса MapAndAddress.
+        Параметры: ширина, высота, уровень детализации - через запятую
+        без пробелов.
+    '''
+    data = [] if params is None else params.split(",")
+    try:
+        return address.get_map_url(*data)
+    except:
+        return ''