# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_ATTR_MAP        = getattr(settings, 'ADDRESS_ATTR_MAP', DEFAULT_ADDRESS_ATTR_MAP)
# 
# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_FORMAT          = getattr(settings, 'ADDRESS_FORMAT', DEFAULT_ADDRESS_FORMAT)
# 
# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_FORMAT_FIELDS   = getattr(settings, 'ADDRESS_FORMAT_FIELDS', DEFAULT_ADDRESS_FORMAT_FIELDS)
# 
# Path: wagtailplus/wagtailaddresses/edit_handlers.py
# def AddressComponentChooserPanel(field_name):
#     """
#     Returns choser panel class with specified field name.
# 
#     :param field_name: field name of chosen model.
#     """
#     return type('_AddressComponentChooserPanel', (BaseAddressComponentChooserPanel,), {
#         'field_name': field_name,
#     })


import json
import urllib2
from django.conf import settings
from django.contrib.gis.geos import Point
from django.utils.encoding import python_2_unicode_compatible
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailadmin.edit_handlers import MultiFieldPanel
from wagtail.wagtailadmin.edit_handlers import ObjectList
from wagtail.wagtailadmin.taggable import TagSearchable
from wagtail.wagtailsearch import index
from .app_settings import ADDRESS_ATTR_MAP
from .app_settings import ADDRESS_FORMAT
from .app_settings import ADDRESS_FORMAT_FIELDS
from .edit_handlers import AddressComponentChooserPanel
    from django.contrib.gis.db import models
    from django.db import models

    tags        = TaggableManager(help_text=None, blank=True, verbose_name=_('Tags'))

    # Make component searchable.
    search_fields = [
        index.SearchField('short_name'),
        index.SearchField('long_name'),
    ]

    class Meta(object):
        ordering        = ('long_name',)
        unique_together = (('type', 'short_name'), ('type', 'long_name'))

    def __str__(self):
        """
        Returns component long name.

        :rtype: str.
        """
        return '{0}'.format(self.long_name)

@python_2_unicode_compatible
class Address(models.Model, TagSearchable):
    """
    Stores a composite address record.
    """
    created_at                  = models.DateTimeField(_(u'Created'), auto_now_add=True)
    geom                        = geom_field
    label                       = models.CharField(_(u'Label'), max_length=200, unique=True, editable=False)
    street_number               = models.CharField(_(u'Street Number'), max_length=6, db_index=True)
    route                       = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['route'], related_name='+')

# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_ATTR_MAP        = getattr(settings, 'ADDRESS_ATTR_MAP', DEFAULT_ADDRESS_ATTR_MAP)
# 
# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_FORMAT          = getattr(settings, 'ADDRESS_FORMAT', DEFAULT_ADDRESS_FORMAT)
# 
# Path: wagtailplus/wagtailaddresses/app_settings.py
# ADDRESS_FORMAT_FIELDS   = getattr(settings, 'ADDRESS_FORMAT_FIELDS', DEFAULT_ADDRESS_FORMAT_FIELDS)
# 
# Path: wagtailplus/wagtailaddresses/edit_handlers.py
# def AddressComponentChooserPanel(field_name):
#     """
#     Returns choser panel class with specified field name.
# 
#     :param field_name: field name of chosen model.
#     """
#     return type('_AddressComponentChooserPanel', (BaseAddressComponentChooserPanel,), {
#         'field_name': field_name,
#     })


# Path: wagtailplus/wagtailaddresses/models.py
import json
import urllib2
from django.conf import settings
from django.contrib.gis.geos import Point
from django.utils.encoding import python_2_unicode_compatible
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailadmin.edit_handlers import MultiFieldPanel
from wagtail.wagtailadmin.edit_handlers import ObjectList
from wagtail.wagtailadmin.taggable import TagSearchable
from wagtail.wagtailsearch import index
from .app_settings import ADDRESS_ATTR_MAP
from .app_settings import ADDRESS_FORMAT
from .app_settings import ADDRESS_FORMAT_FIELDS
from .edit_handlers import AddressComponentChooserPanel
    from django.contrib.gis.db import models
    from django.db import models

    tags        = TaggableManager(help_text=None, blank=True, verbose_name=_('Tags'))

    # Make component searchable.
    search_fields = [
        index.SearchField('short_name'),
        index.SearchField('long_name'),
    ]

    class Meta(object):
        ordering        = ('long_name',)
        unique_together = (('type', 'short_name'), ('type', 'long_name'))

    def __str__(self):
        """
        Returns component long name.

        :rtype: str.
        """
        return '{0}'.format(self.long_name)

@python_2_unicode_compatible
class Address(models.Model, TagSearchable):
    """
    Stores a composite address record.
    """
    created_at                  = models.DateTimeField(_(u'Created'), auto_now_add=True)
    geom                        = geom_field
    label                       = models.CharField(_(u'Label'), max_length=200, unique=True, editable=False)
    street_number               = models.CharField(_(u'Street Number'), max_length=6, db_index=True)
    route                       = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['route'], related_name='+')

    locality                    = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['locality'], related_name='+')
