def show_section(request, section_id = 'home', template = None, context = {}, page = None): section = find_section(section_id) model = section['model'] context = dict({'sections': get_section_ids(), 'title': section['title'], 'current_section': section_id, 'entries': model and model.objects.all(), }.items() + context.items()) pages = make_pages(context['entries'], section_id) if page and pages: try: page = int(page) context['entries'] = pages.page(page) context['pages'] = neighbours(pages.page_range, page) except EmptyPage: raise Http404 context.update(csrf(request)) return render_to_response(template or '%s.html'%section_id, context)
def make_pages(objects, section_id = 'photos'): objs_per_page = find_section(section_id)['objs_per_page'] if objs_per_page: return Paginator(objects, objs_per_page) else: return None