diff options
| -rw-r--r-- | chimere/admin.py | 25 | ||||
| -rw-r--r-- | chimere/templates/chimere/export.kml | 18 | 
2 files changed, 42 insertions, 1 deletions
diff --git a/chimere/admin.py b/chimere/admin.py index b0d0a15..afc818c 100644 --- a/chimere/admin.py +++ b/chimere/admin.py @@ -20,9 +20,13 @@  """  Settings for administration pages  """ +import datetime +import unicodedata  from django.conf import settings  from django.contrib import admin +from django.http import HttpResponse +from django.shortcuts import render_to_response  from django.utils.translation import ugettext_lazy as _  from chimere import tasks @@ -52,6 +56,25 @@ def validate(modeladmin, request, queryset):          item.save()  validate.short_description = _(u"Validate") +def export_to_kml(modeladmin, request, queryset): +    u""" +    Export data to KML +    """ +    dct = {'name':settings.PROJECT_NAME, +           'description':unicode(datetime.date.today()), +           'locations':queryset.all() +    } +    result = render_to_response('chimere/export.kml', dct) +    response = HttpResponse(result, +                        mimetype='application/vnd.google-earth.kml+xml') +    filename = ''.join( +        (c for c in unicodedata.normalize('NFD', settings.PROJECT_NAME) +        if unicodedata.category(c) != 'Mn')) + '-' + dct['description'] + '.kml' +    print filename +    response['Content-Disposition'] = 'attachment; filename=%s' % filename +    return response +export_to_kml.short_description = _(u"Export to KML") +  class MarkerAdmin(admin.ModelAdmin):      """      Specialized the Point field. @@ -60,7 +83,7 @@ class MarkerAdmin(admin.ModelAdmin):      list_display = ('name', 'status')      list_filter = ('status', 'categories')      exclude = [] -    actions = [validate] +    actions = [validate, export_to_kml]      if 'chimere_rss' in settings.INSTALLED_APPS:          exclude.append('available_date')      form = MarkerAdminForm diff --git a/chimere/templates/chimere/export.kml b/chimere/templates/chimere/export.kml new file mode 100644 index 0000000..55d671d --- /dev/null +++ b/chimere/templates/chimere/export.kml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://earth.google.com/kml/2.1"> +  <Document> +    <name>{{ name }}</name> +    <description>{{ description }}</description> + +{% for location in locations %} +  <Placemark> +    <name>{{ location.name }}</name> +    {% if location.description %}<description> +<![CDATA[{{ location.description|safe }}]]> +    </description>{% endif %} +    {{location.point.kml|safe}} +  </Placemark> +{% endfor %} + +</Document> +</kml>  | 
