<NME> easy_maps_tags.py
<BEF> #coding: utf-8
from django import template
from django.template.loader import render_to_string
from easy_maps.models import Address
from classytags.core import Options

register = template.Library()

@register.tag
def easy_map(parser, token):
    """

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
        width, height, zoom = params[2], params[3], params[4]
    elif len(params) == 3 or len(params) > 5:
        raise template.TemplateSyntaxError('easy_map tag has the following syntax: '
                   '{% easy_map <address> <width> <height> [zoom] [using <template_name>] %}')
    return EasyMapNode(address, width, height, zoom, template_name)


class EasyMapNode(template.Node):
    def __init__(self, address, width, height, zoom, template_name):
        self.address = template.Variable(address)
        self.width = width or ''
        Argument("template_name", default=None, required=False),
    )

    def render_tag(self, context, **kwargs):
        params = {k: v for k, v in kwargs.items() if v and k not in ["template_name"]}
        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(

        return map_


    def render(self, context):
        try:
            address = self.address.resolve(context)
        return kwargs.get("template_name", None) or self.template

    def get_context(self, context, **kwargs):
        kwargs.update({"map": parse_address(kwargs.pop("address"))})
        if not kwargs.get("zoom", None):
            kwargs["zoom"] = settings.EASY_MAPS_ZOOM  # default value
        kwargs["language"] = settings.EASY_MAPS_LANGUAGE
        kwargs["api_key"] = settings.EASY_MAPS_GOOGLE_KEY or settings.EASY_MAPS_GOOGLE_MAPS_API_KEY
        return kwargs


register.tag(EasyMapTag)

<MSG> Merge pull request #11 from duixteam/master

Resolve the 500 error when google send a no results info
<DFF> @@ -1,4 +1,4 @@
-#coding: utf-8
+# coding: utf-8
 from django import template
 from django.template.loader import render_to_string
 from easy_maps.models import Address
@@ -6,6 +6,7 @@ from django.conf import settings
 
 register = template.Library()
 
+
 @register.tag
 def easy_map(parser, token):
     """
@@ -34,11 +35,12 @@ def easy_map(parser, token):
         width, height, zoom = params[2], params[3], params[4]
     elif len(params) == 3 or len(params) > 5:
         raise template.TemplateSyntaxError('easy_map tag has the following syntax: '
-                   '{% easy_map <address> <width> <height> [zoom] [using <template_name>] %}')
+                                           '{% easy_map <address> <width> <height> [zoom] [using <template_name>] %}')
     return EasyMapNode(address, width, height, zoom, template_name)
 
 
 class EasyMapNode(template.Node):
+
     def __init__(self, address, width, height, zoom, template_name):
         self.address = template.Variable(address)
         self.width = width or ''
@@ -58,7 +60,6 @@ class EasyMapNode(template.Node):
 
         return map_
 
-
     def render(self, context):
         try:
             address = self.address.resolve(context)

Merge pull request #11 from duixteam/master