# Path: wagtailplus/views/crud.py
# class IndexView(ListView):
# class BaseFormView(FormView):
#         class BaseChooserObjectList(BaseObjectList):
# class CreateView(BaseFormView, _CreateView):
# class UpdateView(BaseFormView, _UpdateView):
# class DeleteView(_DeleteView):
#     def get(self, request, *args, **kwargs):
#     def get_context_data(self, **kwargs):
#     def get_template_names(self):
#     def form_invalid(self, form):
#     def form_valid(self, form):
#     def get_context_data(self, **kwargs):
#     def get_edit_handler_class(self):
#             def render_missing_fields(self):
#         def ChooserObjectList(children):
#     def get_form_class(self):
#     def delete(self, request, *args, **kwargs):
# 
# Path: wagtailplus/wagtailaddresses/models.py
# 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='+')
#     administrative_area_level_2 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['administrative_area_level_2'], related_name='+', blank=True, null=True)
#     administrative_area_level_1 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['administrative_area_level_1'], related_name='+')
#     postal_code                 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['postal_code'], related_name='+')
#     country                     = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['country'], related_name='+')
#     tags                        = TaggableManager(help_text=None, blank=True, verbose_name=_('Tags'))
#     objects                     = AddressManager()
# 
#     class Meta(object):
#         verbose_name        = _(u'Address')
#         verbose_name_plural = _(u'Addresses')
#         unique_together     = ('street_number', 'route', 'postal_code')
# 
#     # Make address searchable.
#     search_fields = [
#         index.SearchField('label', partial_match=True, boost=10),
#         index.SearchField('get_tags', partial_match=True, boost=10),
#     ]
# 
#     @property
#     def latitude(self):
#         """
#         Returns address latitude, if available.
# 
#         :rtype: float.
#         """
#         lat = None
#         if self.geom:
#             if GEO_ENABLED:
#                 lat = self.geom.y
#             else:
#                 lat, lon = self.geom.split(',')
#         return lat
# 
#     @property
#     def longitude(self):
#         """
#         Returns address longitude, if available.
# 
#         :rtype: float.
#         """
#         lon = None
#         if self.geom:
#             if GEO_ENABLED:
#                 lon = self.geom.x
#             else:
#                 lat, lon = self.geom.split(',')
#         return lon
# 
#     def __str__(self):
#         """
#         Returns formatted address.
# 
#         :rtype: str.
#         """
#         format_values = []
#         for field in ADDRESS_FORMAT_FIELDS:
#             format_values.append(getattr(self, field, ''))
#         return ADDRESS_FORMAT.format(*format_values)
# 
#     def save(self, *args, **kwargs):
#         """
#         Automatically sets address geometry and saves instance.
#         """
#         # Set address label.
#         self.label = self.__str__()
# 
#         # Attempt to set geometry if empty.
#         if not self.geom:
#             data = get_address_data(self.__str__())
#             if data:
#                 self.geom = get_geom_from_data(data)
# 
#         super(Address, self).save(*args, **kwargs)
# 
#     @classmethod
#     def get_edit_handler(cls):
#         """
#         Returns edit handler instance.
# 
#         :rtype: wagtail.wagtailadmin.edit_handlers.ObjectList.
#         """
#         return ObjectList(cls.content_panels)


from wagtailplus.views import crud
from ..models import Address

"""
Contains address view functions.
"""



class IndexView(crud.IndexView):
    """
    Address index view.
    """
    model               = Address
    index_template      = 'wagtailaddresses/addresses/index.html'
    results_template    = 'wagtailaddresses/addresses/results.html'

class CreateView(crud.CreateView):
    """
    Address create view.
    """
    model           = Address
    template_name   = 'wagtailaddresses/addresses/add.html'
    success_url     = 'wagtailaddresses_index'

class UpdateView(crud.UpdateView):
    """
    Address update view.
    """

# Path: wagtailplus/views/crud.py
# class IndexView(ListView):
# class BaseFormView(FormView):
#         class BaseChooserObjectList(BaseObjectList):
# class CreateView(BaseFormView, _CreateView):
# class UpdateView(BaseFormView, _UpdateView):
# class DeleteView(_DeleteView):
#     def get(self, request, *args, **kwargs):
#     def get_context_data(self, **kwargs):
#     def get_template_names(self):
#     def form_invalid(self, form):
#     def form_valid(self, form):
#     def get_context_data(self, **kwargs):
#     def get_edit_handler_class(self):
#             def render_missing_fields(self):
#         def ChooserObjectList(children):
#     def get_form_class(self):
#     def delete(self, request, *args, **kwargs):
# 
# Path: wagtailplus/wagtailaddresses/models.py
# 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='+')
#     administrative_area_level_2 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['administrative_area_level_2'], related_name='+', blank=True, null=True)
#     administrative_area_level_1 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['administrative_area_level_1'], related_name='+')
#     postal_code                 = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['postal_code'], related_name='+')
#     country                     = models.ForeignKey('wagtailaddresses.AddressComponent', verbose_name=ADDRESS_ATTR_MAP['country'], related_name='+')
#     tags                        = TaggableManager(help_text=None, blank=True, verbose_name=_('Tags'))
#     objects                     = AddressManager()
# 
#     class Meta(object):
#         verbose_name        = _(u'Address')
#         verbose_name_plural = _(u'Addresses')
#         unique_together     = ('street_number', 'route', 'postal_code')
# 
#     # Make address searchable.
#     search_fields = [
#         index.SearchField('label', partial_match=True, boost=10),
#         index.SearchField('get_tags', partial_match=True, boost=10),
#     ]
# 
#     @property
#     def latitude(self):
#         """
#         Returns address latitude, if available.
# 
#         :rtype: float.
#         """
#         lat = None
#         if self.geom:
#             if GEO_ENABLED:
#                 lat = self.geom.y
#             else:
#                 lat, lon = self.geom.split(',')
#         return lat
# 
#     @property
#     def longitude(self):
#         """
#         Returns address longitude, if available.
# 
#         :rtype: float.
#         """
#         lon = None
#         if self.geom:
#             if GEO_ENABLED:
#                 lon = self.geom.x
#             else:
#                 lat, lon = self.geom.split(',')
#         return lon
# 
#     def __str__(self):
#         """
#         Returns formatted address.
# 
#         :rtype: str.
#         """
#         format_values = []
#         for field in ADDRESS_FORMAT_FIELDS:
#             format_values.append(getattr(self, field, ''))
#         return ADDRESS_FORMAT.format(*format_values)
# 
#     def save(self, *args, **kwargs):
#         """
#         Automatically sets address geometry and saves instance.
#         """
#         # Set address label.
#         self.label = self.__str__()
# 
#         # Attempt to set geometry if empty.
#         if not self.geom:
#             data = get_address_data(self.__str__())
#             if data:
#                 self.geom = get_geom_from_data(data)
# 
#         super(Address, self).save(*args, **kwargs)
# 
#     @classmethod
#     def get_edit_handler(cls):
#         """
#         Returns edit handler instance.
# 
#         :rtype: wagtail.wagtailadmin.edit_handlers.ObjectList.
#         """
#         return ObjectList(cls.content_panels)


# Path: wagtailplus/wagtailaddresses/views/addresses.py
from wagtailplus.views import crud
from ..models import Address

"""
Contains address view functions.
"""



class IndexView(crud.IndexView):
    """
    Address index view.
    """
    model               = Address
    index_template      = 'wagtailaddresses/addresses/index.html'
    results_template    = 'wagtailaddresses/addresses/results.html'

class CreateView(crud.CreateView):
    """
    Address create view.
    """
    model           = Address
    template_name   = 'wagtailaddresses/addresses/add.html'
    success_url     = 'wagtailaddresses_index'

class UpdateView(crud.UpdateView):
    """
    Address update view.
    """

    model           = Address
