def dispatch(self, request, *args, **kwargs):
# Filtering
self.active_genre = request.GET.get('genre', 'All Genres')
self.distance = request.GET.get('distance')
self.location = request.GET.get('location')
self.lat = request.GET.get('lat')
self.lon = request.GET.get('lon')
# Sorting
order_by_slug = request.GET.get('sort')
if order_by_slug not in self.ORDER_BY_NAME:
order_by_slug = 'recent'
self.order_by = {
'slug': order_by_slug,
'name': self.ORDER_BY_NAME[order_by_slug],
}
# Geolocate if location
self.location_coordinates = None
self.geocoder_failed = False
if self.location:
geolocator = Nominatim()
try:
self.location_coordinates = geolocator.geocode(self.location)
except GeocoderTimedOut:
self.geocoder_failed = True
return super(ArtistListView, self).dispatch(request, *args, **kwargs)
评论列表
文章目录