from django.utils.translation import ugettext as _

from jmbo.views import ObjectList

from jmbo_calendar.models import Event


class ObjectList(ObjectList):

    def get_context_data(self, **kwargs):
        context = super(ObjectList, self).get_context_data(**kwargs)
        try:
            from django.contrib.gis.geos import Point
            show_distance = isinstance(
                self.request.session['location']['position'], Point
            )
        except ImportError:
            show_distance = False
        context["title"] = _("Events")
        context["show_distance"] = show_distance
        return context

    def get_queryset(self):
        qs = Event.coordinator.upcoming()
        qs = qs.filter(
            location__country=self.request.session['location']['city'].country_id
        )
        position = self.request.session['location']['position']
        if not isinstance(position, Point):
            position = self.request.session['location']['city'].coordinates
        qs = qs.distance(position).order_by('distance', 'start')
        return qs

    def get_paginate_by(self, *args, **kwargs):
        # todo: needs work in Jmbo to work
        return 10

from django.utils.translation import ugettext as _

from jmbo import USE_GIS
from jmbo.views import ObjectList

from jmbo_calendar.models import Event


class ObjectList(ObjectList):

    def get_context_data(self, **kwargs):
        context = super(ObjectList, self).get_context_data(**kwargs)
        show_distance = False
        if USE_GIS:
            from django.contrib.gis.geos import Point
            show_distance = isinstance(
                self.request.session['location']['position'], Point
            )
        context["title"] = _("Events")
        context["show_distance"] = show_distance
        return context

    def get_queryset(self):
        qs = Event.coordinator.upcoming()
        qs = qs.filter(
            location__country=self.request.session['location']['city'].country_id
        )
        position = self.request.session['location']['position']
        if not isinstance(position, Point):
            position = self.request.session['location']['city'].coordinates
        qs = qs.distance(position).order_by('distance', 'start')
        return qs

    def get_paginate_by(self, *args, **kwargs):
        # todo: needs work in Jmbo to work
        return 10

Revert to using jmbo gis flag
Revert to using jmbo gis flag
