<NME> easy_maps_tags.py
<BEF> from django import template
from django.core.exceptions import ImproperlyConfigured

from classytags.arguments import Argument, IntegerArgument
from classytags.core import Options
from classytags.helpers import InclusionTag

from ..conf import settings
from ..models import Address

register = template.Library()


def parse_address(address=None):
    if isinstance(address, Address):
        return address

    if not address:
        return Address(
            latitude=settings.EASY_MAPS_CENTER[0],
            longitude=settings.EASY_MAPS_CENTER[1],
        )

    return Address.objects.for_address(address)


class EasyMapTag(InclusionTag):
    """
    The syntax:

    {% easy_map <address> [<width> <height>] [<zoom>] [using <template_name>] %}

    The "address" parameter can be an ``easy_maps.Address`` instance
    or a string describing it.  If an address is not found a new entry
    is created in the database.

    """

    name = "easy_map"
    template = "easy_maps/map.html"
    options = Options(
        Argument("address", resolve=True, required=True),

    def __init__(self, address, width, height, zoom, template_name):
        self.address = template.Variable(address)
        self.width = width or ''
        self.height = height or ''
        self.zoom = zoom or 16
        self.template_name = template.Variable(template_name or '"easy_maps/map.html"')

    def get_map(self, address):
        if "address" in params and (len(params) == 2 or len(params) > 4):
            raise template.TemplateSyntaxError(
                "easy_map tag has the following syntax: "
                "{% easy_map <address> [<width> <height>] [zoom] [using <template_name>] %}"
            )

        if settings.EASY_MAPS_GOOGLE_KEY is None:
            raise ImproperlyConfigured(
                "easy_map tag requires EASY_MAPS_GOOGLE_KEY to be set in global settings "
        return map_

    def render(self, context):
        try:
            address = self.address.resolve(context)
            template_name = self.template_name.resolve(context)

            context.update({
                'map': map_,
                'width': self.width,
                'height': self.height,
                'zoom': self.zoom,
                'template_name': template_name
            })
            return render_to_string(template_name, context_instance=context)

<MSG> Merge pull request #10 from bashu/patch-1

resolve width / height from context
<DFF> @@ -43,9 +43,9 @@ class EasyMapNode(template.Node):
 
     def __init__(self, address, width, height, zoom, template_name):
         self.address = template.Variable(address)
-        self.width = width or ''
-        self.height = height or ''
-        self.zoom = zoom or 16
+        self.width = template.Variable(width)
+        self.height = template.Variable(height)
+        self.zoom = template.Variable(zoom)
         self.template_name = template.Variable(template_name or '"easy_maps/map.html"')
 
     def get_map(self, address):
@@ -61,6 +61,19 @@ class EasyMapNode(template.Node):
         return map_
 
     def render(self, context):
+        try:
+            width = self.width.resolve(context)
+        except:
+            width = ''
+        try:
+            height = self.height.resolve(context)
+        except:
+            height = ''
+        try:
+            zoom = self.zoom.resolve(context)
+        except:
+            zoom = 16
+
         try:
             address = self.address.resolve(context)
             template_name = self.template_name.resolve(context)
@@ -68,9 +81,9 @@ class EasyMapNode(template.Node):
 
             context.update({
                 'map': map_,
-                'width': self.width,
-                'height': self.height,
-                'zoom': self.zoom,
+                'width': width,
+                'height': height,
+                'zoom': zoom,
                 'template_name': template_name
             })
             return render_to_string(template_name, context_instance=context)

Merge pull request #10 from bashu/patch-1