Exemple #1
0
    def get_context_data(self, **kwargs):
        from maps.widgets import map_options_for_region

        context = super(BasePageDetailView, self).get_context_data(**kwargs)
        context['region'] = self.object.region
        context['date'] = self.object.versions.most_recent().version_info.date
        if hasattr(self.object, 'mapdata'):
            # Remove the PanZoom on normal page views.
            olwidget_options = copy.deepcopy(
                getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
            map_opts = olwidget_options.get('map_options', {})
            map_controls = map_opts.get('controls', [])
            if 'PanZoom' in map_controls:
                map_controls.remove('PanZoom')
            if 'PanZoomBar' in map_controls:
                map_controls.remove('PanZoomBar')
            if 'KeyboardDefaults' in map_controls:
                map_controls.remove('KeyboardDefaults')
            if 'Navigation' in map_controls:
                map_controls.remove('Navigation')
            olwidget_options['map_options'] = map_opts
            olwidget_options['map_div_class'] = 'mapwidget small'
            olwidget_options.update(map_options_for_region(self.object.region))
            context['map'] = InfoMap(
                [(self.object.mapdata.geom, self.object.name)],
                options=olwidget_options)
        return context
def render_page_card(context, page):
    from maps.widgets import map_options_for_region
    cache = get_cache('long-living')
    request = context['request']

    card = cache.get('card:%s,%s' %
                     (get_urlconf() or settings.ROOT_URLCONF, page.id))
    if card:
        return card

    _file, _map = None, None

    # Try and get a useful image
    _file = page.get_highlight_image()

    # Otherwise, try and get a map
    if not _file and hasattr(page, 'mapdata'):
        olwidget_options.update(map_options_for_region(page.region))
        _map = InfoMap([(page.mapdata.geom, '')],
                       options=olwidget_options).render(
                           None, None, {'id': 'map_page_id_%s' % page.id})

    card = render_to_string(
        'cards/base.html', {
            'obj': page,
            'file': _file.file if _file else None,
            'map': _map,
            'title': page.name,
            'content': page.content,
        })
    cache.set('card:%s,%s' % (get_urlconf() or settings.ROOT_URLCONF, page.id),
              card)
    return card
    def get_context_data(self, *args, **kwargs):
        from maps.widgets import InfoMap, map_options_for_region

        context = super(GlobalTaggedList, self).get_context_data(*args, **kwargs)
        context['tag_name'] = self.tag_name
        map_objects = self.get_map_objects()
        if map_objects:
            # Remove the PanZoom on normal page views.
            olwidget_options = copy.deepcopy(getattr(settings,
                'OLWIDGET_DEFAULT_OPTIONS', {}))
            map_opts = olwidget_options.get('map_options', {})
            map_controls = map_opts.get('controls', [])
            if 'PanZoomBar' in map_controls:
                map_controls.remove('PanZoomBar')
            if 'PanZoom' in map_controls:
                map_controls.remove('PanZoom')
            if 'KeyboardDefaults' in map_controls:
                map_controls.remove('KeyboardDefaults')
            olwidget_options['map_options'] = map_opts
            olwidget_options['map_div_class'] = 'mapwidget small'
            olwidget_options['cluster'] = True
            context['map'] = InfoMap(
                map_objects,
                options=olwidget_options)
        return context
 def get_context_data(self, **kwargs):
     # Send this in directly because we've wrapped InfoMap.
     context = super(MapCompareView, self).get_context_data(**kwargs)
     # We subclassed olwidget.widget.InfoMap. We want to combine both
     # their media here to ensure we display more than one layer
     # correctly.
     context['map_diff_media'] = InfoMap([]).media + OLInfoMap([]).media
     return context
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)

        options = map_options_for_region(self.get_region())
        context['show_revision'] = True
        context['map'] = InfoMap([(self.object.geom, self.object.page.name)],
                                 options=options)
        context['date'] = self.object.version_info.date
        return context
    def get_context_data(self, **kwargs):
        context = super(MapDetailView, self).get_context_data(**kwargs)

        options = map_options_for_region(self.get_region())
        options['permalink'] = True
        context['date'] = self.get_object_date()
        context['map'] = InfoMap([(self.object.geom, self.object.page.name)],
                                 options=options)
        return context
Exemple #7
0
    def get_map(self):
        (paginator, page) = self.build_page()
        result_pks = [p.pk for p in page.object_list if p]
        maps = MapData.objects.filter(page__pk__in=result_pks)
        if not maps:
            return None

        _map = InfoMap([(obj.geom, popup_html(obj)) for obj in maps],
                       options=self.get_map_options())
        return _map
 def get_map(self):
     map_objects = self.get_map_objects()
     options = map_options_for_region(self.get_region())
     options.update({
         'dynamic': self.dynamic,
         'zoomToDataExtent': self.zoom_to_data,
         'permalink': self.permalink,
         'cluster': True
     })
     return InfoMap(map_objects, options=options)
 def get_map(self):
     map_objects = self.get_map_objects()
     options = copy.deepcopy(
         getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
     options.update({
         'dynamic': self.dynamic,
         'zoomToDataExtent': self.zoom_to_data,
         'permalink': self.permalink,
         'cluster': True
     })
     return InfoMap(map_objects, options=options)
    def get_context_data(self, *args, **kwargs):
        from maps.widgets import InfoMap

        def popup_html(obj):
            url = reverse('frontpage', kwargs={'region': obj.slug})
            return '<a href="%s">%s</a>' % (url, obj.full_name)

        context = super(RegionListView, self).get_context_data(*args, **kwargs)
        map_objects = [(obj.geom.centroid, popup_html(obj))
                       for obj in self.get_queryset() if obj.geom]

        context['map'] = InfoMap(map_objects, options=self.get_map_options())
        return context
 def get_map(self, cover=False):
     olwidget_options = copy.deepcopy(
         getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
     map_opts = olwidget_options.get('map_options', {})
     olwidget_options.update(map_options_for_region(self.get_region()))
     map_controls = map_opts.get('controls', [])
     if 'PanZoom' in map_controls:
         map_controls.remove('PanZoom')
     if 'PanZoomBar' in map_controls:
         map_controls.remove('PanZoomBar')
     if 'KeyboardDefaults' in map_controls:
         map_controls.remove('KeyboardDefaults')
     if 'Navigation' in map_controls:
         map_controls.remove('Navigation')
     if not cover:
         olwidget_options['map_div_class'] = 'mapwidget small'
     olwidget_options['map_options'] = map_opts
     olwidget_options['zoomToDataExtent'] = False
     olwidget_options['cluster'] = True
     if cover:
         return InfoMap([], options=olwidget_options)
     else:
         return InfoMap(self.get_map_objects(), options=olwidget_options)
Exemple #12
0
 def get_context_data(self, **kwargs):
     context = super(PageDetailView, self).get_context_data(**kwargs)
     context['date'] = self.object.versions.most_recent().version_info.date
     if hasattr(self.object, 'mapdata'):
         # Remove the PanZoomBar on normal page views.
         olwidget_options = copy.deepcopy(
             getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
         map_opts = olwidget_options.get('map_options', {})
         map_controls = map_opts.get('controls', [])
         if 'PanZoomBar' in map_controls:
             map_controls.remove('PanZoomBar')
         olwidget_options['map_options'] = map_opts
         olwidget_options['map_div_class'] = 'mapwidget small'
         context['map'] = InfoMap(
             [(self.object.mapdata.geom, self.object.name)],
             options=olwidget_options)
     return context
def render_region_card(context, region):
    from maps.widgets import map_options_for_region
    cache = get_cache('long-living')
    request = context['request']

    card = cache.get('rcard:%s' % region.id)
    if card:
        return card

    urlconf = get_urlconf()
    set_urlconf('main.urls')

    _file, _map, front_page_content = None, None, None
    is_meta_region = hasattr(
        region, 'regionsettings') and region.regionsettings.is_meta_region

    if Page.objects.filter(region=region, slug='front page'):
        front_page_content = Page.objects.get(region=region,
                                              slug='front page').content

    # User the cover photo, if it exists, as the thumbnail
    if FrontPage.objects.filter(region=region).exists():
        frontpage = FrontPage.objects.get(region=region)
        if frontpage.cover_photo:
            _file = frontpage.cover_photo

    # Otherwise, try and get a map
    if not _file and not is_meta_region and region.geom:
        map_opts = map_options_for_region(region)
        map_opts['default_zoom'] -= 1
        olwidget_options.update(map_opts)
        _map = InfoMap([(None, '')], options=olwidget_options).render(
            None, None, {'id': 'map_region_id_%s' % region.id})

    card = render_to_string(
        'cards/base.html', {
            'obj': region,
            'file': _file,
            'map': _map,
            'title': region.full_name,
            'content': front_page_content,
        })
    cache.set('rcard:%s' % region.id, card)

    set_urlconf(urlconf)
    return card
Exemple #14
0
 def get_context_data(self, *args, **kwargs):
     context = super(TaggedList, self).get_context_data(*args, **kwargs)
     context['tag'] = self.tag
     context['tag_name'] = self.tag_name
     map_objects = self.get_map_objects()
     if map_objects:
         # Remove the PanZoomBar on normal page views.
         olwidget_options = copy.deepcopy(
             getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
         map_opts = olwidget_options.get('map_options', {})
         map_controls = map_opts.get('controls', [])
         if 'PanZoomBar' in map_controls:
             map_controls.remove('PanZoomBar')
         olwidget_options['map_options'] = map_opts
         olwidget_options['map_div_class'] = 'mapwidget small'
         context['map'] = InfoMap(map_objects, options=olwidget_options)
     return context
    def get_context_data(self, *args, **kwargs):
        from maps.widgets import InfoMap

        def popup_html(obj):
            url = reverse('frontpage', kwargs={'region': obj.slug})
            return '<a href="%s">%s</a>' % (url, obj.full_name)

        context = super(RegionExploreView,
                        self).get_context_data(*args, **kwargs)

        # Add a map of every single region:
        all_regions = Region.objects.filter(is_active=True).exclude(
            regionsettings__is_meta_region=True)
        map_objects = [(obj.geom.centroid, popup_html(obj))
                       for obj in all_regions if obj.geom]

        olwidget_options = copy.deepcopy(
            getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))

        if get_language() in settings.LANGUAGE_DEFAULT_CENTERS:
            olwidget_options['default_lat'], olwidget_options[
                'default_lon'] = settings.LANGUAGE_DEFAULT_CENTERS[
                    get_language()]
            olwidget_options['default_zoom'] = 5
        else:
            # Center to show most of the US'ish
            olwidget_options['default_lon'] = -100.99
            olwidget_options['default_lat'] = 39.79

        olwidget_options['zoomToDataExtent'] = self.zoom_to_data

        map_opts = olwidget_options.get('map_options', {})
        map_controls = map_opts.get('controls', [])
        if 'KeyboardDefaults' in map_controls:
            map_controls.remove('KeyboardDefaults')
        olwidget_options['map_options'] = map_opts
        olwidget_options['map_div_class'] = 'mapwidget small'
        context['map'] = InfoMap(map_objects, options=olwidget_options)

        context['page_type'] = 'random'
        context['random_seed'] = self.random_seed

        return context
Exemple #16
0
 def get_map(self):
     (paginator, page) = self.build_page()
     result_pks = [p.pk for p in page.object_list if p]
     maps = MapData.objects.filter(page__pk__in=result_pks)
     if not maps:
         return None
     widget_options = copy.deepcopy(
         getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
     map_opts = widget_options.get('map_options', {})
     map_controls = map_opts.get('controls', [])
     # Remove the PanZoomBar.
     if 'PanZoomBar' in map_controls:
         map_controls.remove('PanZoomBar')
     # Remove the Keyboard scrolling behavior.
     if 'KeyboardDefaults' in map_controls:
         map_controls.remove('KeyboardDefaults')
     widget_options['map_options'] = map_opts
     widget_options['map_div_class'] = 'mapwidget small'
     map = InfoMap([(obj.geom, popup_html(obj)) for obj in maps],
                   options=widget_options)
     return map
    def map_context(self, map_objects):
        from maps.widgets import InfoMap, map_options_for_region

        if map_objects:
            # Remove the PanZoom on normal page views.
            olwidget_options = copy.deepcopy(getattr(settings,
                'OLWIDGET_DEFAULT_OPTIONS', {}))
            map_opts = olwidget_options.get('map_options', {})
            map_controls = map_opts.get('controls', [])
            if 'PanZoomBar' in map_controls:
                map_controls.remove('PanZoomBar')
            if 'PanZoom' in map_controls:
                map_controls.remove('PanZoom')
            if 'KeyboardDefaults' in map_controls:
                map_controls.remove('KeyboardDefaults')
            olwidget_options['map_options'] = map_opts
            olwidget_options['map_div_class'] = 'mapwidget small'
            olwidget_options.update(map_options_for_region(self.get_region()))
            return InfoMap(
                map_objects,
                options=olwidget_options)
    def get_context_data(self, *args, **kwargs):
        from maps.widgets import InfoMap
        context = super(MapNearbyView, self).get_context_data(*args, **kwargs)
        qs = self.get_queryset()
        if qs is None:
            context['no_location'] = True
            qs = []
        map_objects = [(obj.geom, popup_html(obj)) for obj in qs]

        # Remove the PanZoom on normal page views.
        olwidget_options = copy.deepcopy(
            getattr(settings, 'OLWIDGET_DEFAULT_OPTIONS', {}))
        map_opts = olwidget_options.get('map_options', {})
        map_controls = map_opts.get('controls', [])
        if 'PanZoomBar' in map_controls:
            map_controls.remove('PanZoomBar')
        if 'PanZoom' in map_controls:
            map_controls.remove('PanZoom')
        if 'KeyboardDefaults' in map_controls:
            map_controls.remove('KeyboardDefaults')
        olwidget_options['map_options'] = map_opts
        olwidget_options['map_div_class'] = 'mapwidget small'
        context['map'] = InfoMap(map_objects, options=olwidget_options)
        return context