# Path: listing/edit_handlers.py
# class ListingTabbedInterface(TabbedInterface):
#     def bind_to_model(self, model):
#         cls = super().bind_to_model(model)
#         base_form_class = cls.get_form_class(model)
#         cls._form_class = get_form_class(base_form_class)
#         return cls
# 
# Path: listing/mixins.py
# class ListingPageViewMixin(object):
#     @cached_property
#     def similar_params(self):
#         params = {}
#         params['category'] = self.get_parent().slug
#         params['city'] = self.city.slug
#         params['bedrooms'] = self.bedrooms
# 
#         if self.listing_type.sell:
#             params['listing_type'] = 'sell'
#             price = float(self.sell_price)
# 
#         elif self.listing_type.rent:
#             params['listing_type'] = 'rent'
#             price = float(self.rent_price)
# 
#         diff = float(price) * 0.20
# 
#         params['min_price'] = price - diff
#         params['max_price'] = price + diff
# 
#         return params
# 
#     @cached_property
#     def similar_queryset(self):
#         category = self.get_parent()
#         city = self.city
#         listing_type = self.listing_type
#         bedrooms = self.bedrooms
# 
#         qs = self.__class__.objects.child_of(category).filter(
#             city=city, listing_type=listing_type,
#             bedrooms__gte=bedrooms,
#         )
# 
#         if listing_type.sell:
#             price = float(self.sell_price)
#             diff = float(price) * 0.20
#             qs = qs.filter(sell_price__range=(price-diff, price+diff))
# 
#         elif listing_type.rent:
#             price = float(self.rent_price)
#             diff = float(price) * 0.20
#             qs = qs.filter(rent_price__range=(price-diff, price+diff))
# 
#         return qs
# 
#     def get_context(self, *args, **kwargs):
#         ctx = super().get_context(*args, **kwargs)
#         ctx['condominiums'] = self.get_condominiums()
#         ctx['neighbourhoods'] = self.get_neighbourhoods()
# 
#         return ctx
# 
#     def get_neighbourhoods(self, *args):
#         qs = self.similar_queryset.filter(neighbourhood__isnull=False)
# 
#         result = []
# 
#         for row in qs.annotate(Count('neighbourhood')):
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'neighbourhood-{}'.format(
#                 row.neighbourhood.slug)
# 
#             result.append((
#                 row.neighbourhood,
#                 row.neighbourhood__count,
#                 params,
#             ))
# 
#         if qs:
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'neighbourhood'
# 
#             result.insert(0, ('Todos', qs.count(), params))
# 
#         return result
# 
#     def get_condominiums(self):
#         qs = self.similar_queryset.filter(condominium__isnull=False)
#         result = []
# 
#         for row in qs.annotate(Count('condominium')):
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'condominium-{}'.format(
#                 row.condominium.slug)
# 
#             result.append((
#                 row.condominium,
#                 row.condominium__count,
#                 params,
#             ))
# 
#         if qs:
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'condominium'
# 
#             result.insert(0, ('Todos', qs.count(), params))
# 
#         return result
# 
# Path: listing/widgets.py
# class NeighbourhoodWidget(AjaxCitySelect):
#     filter_url = reverse_lazy('dashboard_neighbourhoods_json')
# 
#     @property
#     def media(self):
#         return forms.Media()
# 
# class CondominiumWidget(AjaxCitySelect):
#     filter_url = reverse_lazy('dashboard_condominiums_json')
# 
#     @property
#     def media(self):
#         return forms.Media()


from django.contrib.gis.db import models
from django.conf import settings
from django.templatetags.l10n import localize
from django.template.defaultfilters import strip_tags
from django.core.urlresolvers import reverse
from django.utils.functional import cached_property
from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as trans
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, FieldRowPanel, \
    MultiFieldPanel, InlinePanel, ObjectList
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsnippets.models import register_snippet
from bitfield import BitField
from location_field.models.spatial import LocationField
from input_mask.widgets import DecimalInputMask
from modelcluster.fields import ParentalKey
from .edit_handlers import ListingTabbedInterface
from .mixins import ListingPageViewMixin
from .widgets import NeighbourhoodWidget, CondominiumWidget
        verbose_name = 'Imóveis'

    """
    Settings
    """
    subpage_types = ['listing.CategoryPage']


class CategoryPage(Page):
    def get_absolute_url(self):
        return '{url}?category={slug}'.format(
            url=reverse('search'), slug=self.slug)

    class Meta:
        verbose_name = 'categoria'
        verbose_name_plural = 'categorias'

    """
    Settings
    """
    subpage_types = ['listing.ListingPage']

    """
    Panels
    """
    content_panels = [
        FieldPanel('title'),
    ]



# Path: listing/edit_handlers.py
# class ListingTabbedInterface(TabbedInterface):
#     def bind_to_model(self, model):
#         cls = super().bind_to_model(model)
#         base_form_class = cls.get_form_class(model)
#         cls._form_class = get_form_class(base_form_class)
#         return cls
# 
# Path: listing/mixins.py
# class ListingPageViewMixin(object):
#     @cached_property
#     def similar_params(self):
#         params = {}
#         params['category'] = self.get_parent().slug
#         params['city'] = self.city.slug
#         params['bedrooms'] = self.bedrooms
# 
#         if self.listing_type.sell:
#             params['listing_type'] = 'sell'
#             price = float(self.sell_price)
# 
#         elif self.listing_type.rent:
#             params['listing_type'] = 'rent'
#             price = float(self.rent_price)
# 
#         diff = float(price) * 0.20
# 
#         params['min_price'] = price - diff
#         params['max_price'] = price + diff
# 
#         return params
# 
#     @cached_property
#     def similar_queryset(self):
#         category = self.get_parent()
#         city = self.city
#         listing_type = self.listing_type
#         bedrooms = self.bedrooms
# 
#         qs = self.__class__.objects.child_of(category).filter(
#             city=city, listing_type=listing_type,
#             bedrooms__gte=bedrooms,
#         )
# 
#         if listing_type.sell:
#             price = float(self.sell_price)
#             diff = float(price) * 0.20
#             qs = qs.filter(sell_price__range=(price-diff, price+diff))
# 
#         elif listing_type.rent:
#             price = float(self.rent_price)
#             diff = float(price) * 0.20
#             qs = qs.filter(rent_price__range=(price-diff, price+diff))
# 
#         return qs
# 
#     def get_context(self, *args, **kwargs):
#         ctx = super().get_context(*args, **kwargs)
#         ctx['condominiums'] = self.get_condominiums()
#         ctx['neighbourhoods'] = self.get_neighbourhoods()
# 
#         return ctx
# 
#     def get_neighbourhoods(self, *args):
#         qs = self.similar_queryset.filter(neighbourhood__isnull=False)
# 
#         result = []
# 
#         for row in qs.annotate(Count('neighbourhood')):
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'neighbourhood-{}'.format(
#                 row.neighbourhood.slug)
# 
#             result.append((
#                 row.neighbourhood,
#                 row.neighbourhood__count,
#                 params,
#             ))
# 
#         if qs:
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'neighbourhood'
# 
#             result.insert(0, ('Todos', qs.count(), params))
# 
#         return result
# 
#     def get_condominiums(self):
#         qs = self.similar_queryset.filter(condominium__isnull=False)
#         result = []
# 
#         for row in qs.annotate(Count('condominium')):
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'condominium-{}'.format(
#                 row.condominium.slug)
# 
#             result.append((
#                 row.condominium,
#                 row.condominium__count,
#                 params,
#             ))
# 
#         if qs:
#             params = self.similar_params.copy()
#             params['neighbourhood'] = 'condominium'
# 
#             result.insert(0, ('Todos', qs.count(), params))
# 
#         return result
# 
# Path: listing/widgets.py
# class NeighbourhoodWidget(AjaxCitySelect):
#     filter_url = reverse_lazy('dashboard_neighbourhoods_json')
# 
#     @property
#     def media(self):
#         return forms.Media()
# 
# class CondominiumWidget(AjaxCitySelect):
#     filter_url = reverse_lazy('dashboard_condominiums_json')
# 
#     @property
#     def media(self):
#         return forms.Media()


# Path: listing/models.py
from django.contrib.gis.db import models
from django.conf import settings
from django.templatetags.l10n import localize
from django.template.defaultfilters import strip_tags
from django.core.urlresolvers import reverse
from django.utils.functional import cached_property
from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as trans
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, FieldRowPanel, \
    MultiFieldPanel, InlinePanel, ObjectList
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsnippets.models import register_snippet
from bitfield import BitField
from location_field.models.spatial import LocationField
from input_mask.widgets import DecimalInputMask
from modelcluster.fields import ParentalKey
from .edit_handlers import ListingTabbedInterface
from .mixins import ListingPageViewMixin
from .widgets import NeighbourhoodWidget, CondominiumWidget

        verbose_name = 'Imóveis'

    """
    Settings
    """
    subpage_types = ['listing.CategoryPage']


class CategoryPage(Page):
    def get_absolute_url(self):
        return '{url}?category={slug}'.format(
            url=reverse('search'), slug=self.slug)

    class Meta:
        verbose_name = 'categoria'
        verbose_name_plural = 'categorias'

    """
    Settings
    """
    subpage_types = ['listing.ListingPage']

    """
    Panels
    """
    content_panels = [
        FieldPanel('title'),
    ]



class ListingPage(ListingPageViewMixin, Page):