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
Пример #2
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
Пример #3
0
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
Пример #4
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_region_card(context, region, key=False):
    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:
        id = (key if key != False else 'map') + '_region_id_%s' % region.id
        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': 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
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
Пример #7
0
 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([(self.get_region().geom, {
             'style': {
                 'fill_color': '#ffffff',
                 'stroke_color': '#fca92e',
                 'fill_opacity': '0',
                 'stroke_opacity': '1'
             },
             'html': '<p>' + self.get_region().full_name + '</p>'
         })], options=olwidget_options)
     else:
         map_objects = [InfoLayer(self.get_map_objects())]
         for layer_name in FrontPageView.layer_names:
             layer_objects = self.get_map_objects_by_tag(layer_name)
             if len(layer_objects) > 0:
                 map_objects.append(InfoLayer(layer_objects, {
                     'overlay_style': {
                         'external_graphic': '/static/tagicon/%s.png' % layer_name,
                         'graphic_height': 32,
                         'graphic_width': 32,
                         'graphic_opacity': 1.0
                     }
                 }))
         return Map(map_objects, options=olwidget_options)
Пример #8
0
    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)
Пример #9
0
 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)
Пример #10
0
 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)