<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

    """
    The syntax:
        {% easy_map <address> [<width> <height>] [<zoom>] [using <template_name>] %}
    """
    width, height, zoom, template_name = None, None, None, None
    params = token.split_contents()
            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),
        Argument("width", required=False, default=None),
        Argument("height", required=False, default=None),
        IntegerArgument("zoom", required=False, default=None),
        "using",
        Argument("template_name", default=None, required=False),
    )

            address = self.address.resolve(context)
            template_name = self.template_name.resolve(context)

            map = None
            if address == '':
                map = Address(latitude=settings.EASY_MAPS_CENTER[0], longitude=settings.EASY_MAPS_CENTER[1])
            else:
                map, _ = Address.objects.get_or_create(address=address)

            context.update({
                'map': map,
            )
        return super().render_tag(context, **kwargs)

    def get_template(self, context, **kwargs):
        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> Allow to pass an Address instance as argument of easy_map tag.

This reduce the database hits since we can pass directly the instance
instead of its description.

<DFF> @@ -11,6 +11,9 @@ def easy_map(parser, token):
     """
     The syntax:
         {% easy_map <address> [<width> <height>] [<zoom>] [using <template_name>] %}
+
+    The "address" parameter can be an Address instance or a string describing it.
+    If an address is not found a new entry is created in the database.
     """
     width, height, zoom, template_name = None, None, None, None
     params = token.split_contents()
@@ -47,11 +50,12 @@ class EasyMapNode(template.Node):
             address = self.address.resolve(context)
             template_name = self.template_name.resolve(context)
 
-            map = None
-            if address == '':
-                map = Address(latitude=settings.EASY_MAPS_CENTER[0], longitude=settings.EASY_MAPS_CENTER[1])
-            else:
-                map, _ = Address.objects.get_or_create(address=address)
+            map = address
+            if not isinstance(address, Address):
+                if address == '':
+                    map = Address(latitude=settings.EASY_MAPS_CENTER[0], longitude=settings.EASY_MAPS_CENTER[1])
+                else:
+                    map, _ = Address.objects.get_or_create(address=address)
 
             context.update({
                 'map': map,

Allow to pass an Address instance as argument of easy_map tag.