def tag_detail(request, tag, paginate_by=30, page=None, allow_empty=True): from django.views.generic.list_detail import object_detail try: # If there's a section with this tag name, redirect to it's URL. from savoy.contrib.sections.models import Section section = Section.objects.get(slug=tag) return HttpResponseRedirect(section.get_absolute_url()) except: pass try: # Look for a tag with this name. tags = Tag.objects.filter(name=tag) tag = Tag.objects.get(name=tag) except: raise Http404 tagged_items = sort_items_by_date(get_items_for_tags(tag), recent_first=True) extra_context = { 'tagged_items': tagged_items, } # Return a tag detail page. return object_detail( request, queryset=tags, object_id=tag.id, template_object_name='tag', template_name='sections/tag_detail.html', extra_context=extra_context, )
def items(self, radius_miles=.1): """ Returns a heterogenous list of objects located within a given radius (defaults to .1 miles) of this place. Note that this is not a 100% accurate representation of items geolocated to this place, but it's the best we can do while maintaining solid performance. """ from savoy.utils.date_sort import sort_items_by_date object_list = [ item.content_object for item in self.location().get_geolocated_items_within_radius(radius_miles=radius_miles) if item.content_object ] return sort_items_by_date(object_list, recent_first=True)
def items(self): """ Returns a heterogenous list of objects geolocated in this Neighborhood. """ from savoy.utils.date_sort import sort_items_by_date object_list = [ item.content_object for item in GeolocatedItem.objects.filter(neighborhood=self) if item.content_object ] return sort_items_by_date(object_list, recent_first=True)
def items(self): """ Returns a heterogeneous list of objects which are geolocated in this city. """ from savoy.utils.date_sort import sort_items_by_date object_list = [ item.content_object for item in GeolocatedItem.objects.filter(city=self) if item.content_object ] return sort_items_by_date(object_list, recent_first=True)