]> git.parisson.com Git - telemeta.git/commitdiff
make CBV for country search
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 13 Nov 2014 01:36:29 +0000 (02:36 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 13 Nov 2014 01:36:29 +0000 (02:36 +0100)
telemeta/urls.py
telemeta/views/geo.py

index bad6eae167a36094cccb43a672b7dee210878d26..1a97cdf909fa2eee9f3d4e641906492c3a2f8d90 100644 (file)
@@ -176,8 +176,8 @@ urlpatterns = patterns('',
     # Geographic browsing
     url(r'^geo/$', geo_view.list_continents, name="telemeta-geo-continents"),
     url(r'^geo/(?P<continent>[a-z_]+)/$', geo_view.list_countries, name="telemeta-geo-countries"),
-    url(r'^geo/collections/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$', geo_view.list_country_collections, name="telemeta-geo-country-collections"),
-    url(r'^geo/items/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$', geo_view.list_country_items, name="telemeta-geo-country-items"),
+    url(r'^geo/collections/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$', GeoCountryCollectionView.as_view(), name="telemeta-geo-country-collections"),
+    url(r'^geo/items/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$', GeoCountryItemView.as_view() , name="telemeta-geo-country-items"),
     url(r'^geo/country_info/(?P<id>[0-9a-z]+)/$', geo_view.country_info, name="telemeta-country-info"),
 
     # Flat pages
index fa4adc1835f1ab101d2d63c4fd848a74f8117eb5..c7f00edb1fa04e3ce080ace5a266f3a364814997 100644 (file)
@@ -75,3 +75,46 @@ class GeoView(object):
         return list_detail.object_list(request, objects,
             template_name='telemeta/geo_country_items.html', paginate_by=20,
             extra_context={'country': country, 'continent': continent})
+
+
+class GeoCountryCollectionView(ListView):
+
+    model = MediaCollection
+    template_name = 'telemeta/geo_country_collections.html'
+    paginate_by = 20
+
+    def get_queryset(self):
+        country = self.kwargs['country']
+        continent = self.kwargs['continent']
+        self.continent = Location.objects.by_flatname(continent)[0]
+        self.country = Location.objects.by_flatname(country)[0]
+        return MediaCollection.objects.enriched().by_location(self.country)
+
+    def get_context_data(self, *args, **kwargs):
+        context = super(GeoCountryCollectionView, self).get_context_data(*args, **kwargs)
+        context['country'] = self.country
+        context['continent'] =  self.continent
+        return context
+
+
+
+class GeoCountryItemView(ListView):
+
+    model = MediaItem
+    template_name = 'telemeta/geo_country_collections.html'
+    paginate_by = 20
+
+    def get_queryset(self):
+        country = self.kwargs['country']
+        continent = self.kwargs['continent']
+        self.continent = Location.objects.by_flatname(continent)[0]
+        self.country = Location.objects.by_flatname(country)[0]
+        return MediaItem.objects.enriched().by_location(self.country)
+
+    def get_context_data(self, *args, **kwargs):
+        context = super(GeoCountryItemView, self).get_context_data(*args, **kwargs)
+        context['country'] = self.country
+        context['continent'] =  self.continent
+        return context
+
+