From: Guillaume Pellerin Date: Thu, 13 Nov 2014 01:36:29 +0000 (+0100) Subject: make CBV for country search X-Git-Tag: 1.5.0rc1~27^2~46 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=773fcbeb5e579356508d33e3747273d0f56fac1a;p=telemeta.git make CBV for country search --- diff --git a/telemeta/urls.py b/telemeta/urls.py index bad6eae1..1a97cdf9 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -176,8 +176,8 @@ urlpatterns = patterns('', # Geographic browsing url(r'^geo/$', geo_view.list_continents, name="telemeta-geo-continents"), url(r'^geo/(?P[a-z_]+)/$', geo_view.list_countries, name="telemeta-geo-countries"), - url(r'^geo/collections/(?P[a-z_]+)/(?P[a-z_]+)/$', geo_view.list_country_collections, name="telemeta-geo-country-collections"), - url(r'^geo/items/(?P[a-z_]+)/(?P[a-z_]+)/$', geo_view.list_country_items, name="telemeta-geo-country-items"), + url(r'^geo/collections/(?P[a-z_]+)/(?P[a-z_]+)/$', GeoCountryCollectionView.as_view(), name="telemeta-geo-country-collections"), + url(r'^geo/items/(?P[a-z_]+)/(?P[a-z_]+)/$', GeoCountryItemView.as_view() , name="telemeta-geo-country-items"), url(r'^geo/country_info/(?P[0-9a-z]+)/$', geo_view.country_info, name="telemeta-country-info"), # Flat pages diff --git a/telemeta/views/geo.py b/telemeta/views/geo.py index fa4adc18..c7f00edb 100644 --- a/telemeta/views/geo.py +++ b/telemeta/views/geo.py @@ -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 + +