MarcosFino avatar MarcosFino committed b49d5a1

Addesd GeoRSS view

Comments (0)

Files changed (2)

src/macadjan_base/urls.py

     url(r'^map_kml/(?P<category_slug>[a-zA-Z0-9_\-]+)/$', MapKML.as_view(), name='map-kml'),
     url(r'^map_kml/$', MapKML.as_view(), name='map-kml'),
 
+    # GeoRSS Feed that exports map entities in GeoRSS Simple format.
+    url(r'^georss/(?P<category_slug>[a-zA-Z0-9_\-]+)/(?P<subcategory_slug>[a-zA-Z0-9_\-]+)/$',
+        GeoRSS.as_view(), name='georss'),
+    url(r'^georss/(?P<category_slug>[a-zA-Z0-9_\-]+)/$', GeoRSS.as_view(), name='georss'),
+    url(r'^georss/$', GeoRSS.as_view(), name='georss'),
+
     # Openstreetmap query to get the markers for one map tile.
     url(r'^entities/$', Entities.as_view(), name='entities'),
 

src/macadjan_base/views.py

         return context
 
 
+class GeoRSS(View):
+    '''Returns a GeoRSS feed with the entities'''
+
+    def get(self, request, category_slug = None, subcategory_slug = None):
+        map_arguments = MapArguments(request, category_slug, subcategory_slug)
+        context = self.get_context_data(request, map_arguments)
+        return render_to_response('macadjan_base/geo_rss.xml', 
+            context, context_instance = RequestContext(request),
+            mimetype = 'application/vnd.google-earth.kml+xml')
+
+    def get_context_data(self, request, map_arguments):
+        context = map_arguments.get_context_data()
+
+        entities = models.Entity.objects_active.entities_with_area(map_arguments.category,
+                                                                   map_arguments.subcategory)
+        entities = models.Entity.objects_active.filter_with_keywords(entities,
+                                                                     map_arguments.keywords)
+        entities = entities.order_by('-modification_date')
+        entities_urls = [(entity, 'http://' + Site.objects.get_current().domain + 
+                                  reverse('base:entity', kwargs={'entity_slug': entity.slug}))
+                         for entity in entities]
+
+        context.update({
+            'entities_urls': entities_urls, 'site':Site.objects.get_current()
+        })
+
+        return context
+
+
 class AjaxEntityList(View):
     '''Show a list of entities in a block to be included by ajax'''
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.