def non_place_url_parts(context): try: return context['same_place_parts'] except KeyError: pass # _default_instance had better be a town only argument instance. # Empty viewname should get the default. return InOtherPlace.get_split('', 'XXX', 'XXX')
def non_place_url_parts(context): try: return context["same_place_parts"] except KeyError: pass # _default_instance had better be a town only argument instance. # Empty viewname should get the default. return InOtherPlace.get_split("", "XXX", "XXX")
def story(request, place_slug, story_slug=None): page_type = "story" place = get_object_or_404(Place, slug=place_slug) place_stories = place.datastories.all() # Maybe return an alternate rendering if place_stories.count == 0? try: if story_slug is None: story = place_stories[0] else: story = place_stories.get(slug=story_slug) except (Story.DoesNotExist, IndexError): story = None if story: pages = story.pages.order_by('storypage__page_number') else: pages = [] paginator = Paginator(pages, 1) page_count = paginator.num_pages page_num = request.GET.get('page_num') try: pgpg = paginator.page(page_num) except PageNotAnInteger: pgpg = paginator.page(1) except EmptyPage: pgpg = paginator.page(page_count) if not pgpg.object_list: # No pages page = None page_num = 0 page_next = 0 page_prev = 0 page_count = 0 else: page = pgpg.object_list[0] page_num = pgpg.number page_next = pgpg.next_page_number() if pgpg.has_next() else 0 page_prev = pgpg.previous_page_number() if pgpg.has_previous() else 0 if story: spp = InOtherPlace.get_split('story', 'XXX', 'XXX', story.slug) else: spp = InOtherPlace.get_split('story', 'XXX', 'XXX') return render_to_response('datastories/story.html', dict( story=story, page_type=page_type, page=page, page_num=page_num, page_count=page_count, page_prev=page_prev, page_next=page_next, paginator=paginator, paginator_page=pgpg, place=place, datastories=place_stories, same_place_parts=spp, ), context_instance=RequestContext(request))
def story(request, place_slug, story_slug=None): page_type = "story" place = get_object_or_404(Place, slug=place_slug) place_stories = place.datastories.all() # Maybe return an alternate rendering if place_stories.count == 0? try: if story_slug is None: story = place_stories[0] else: story = place_stories.get(slug=story_slug) except (Story.DoesNotExist, IndexError): story = None if story: pages = story.pages.order_by('storypage__page_number') else: pages = [] paginator = Paginator(pages, 1) page_count = paginator.num_pages page_num = request.GET.get('page_num') try: pgpg = paginator.page(page_num) except PageNotAnInteger: pgpg = paginator.page(1) except EmptyPage: pgpg = paginator.page(page_count) if not pgpg.object_list: # No pages page = None page_num = 0 page_next = 0 page_prev = 0 page_count = 0 else: page = pgpg.object_list[0] page_num = pgpg.number page_next = pgpg.next_page_number() if pgpg.has_next() else 0 page_prev = pgpg.previous_page_number() if pgpg.has_previous() else 0 if story: spp = InOtherPlace.get_split('story', 'XXX', 'XXX', story.slug) else: spp = InOtherPlace.get_split('story', 'XXX', 'XXX') return render_to_response( 'datastories/story.html', dict(story=story, page_type=page_type, page=page, page_num=page_num, page_count=page_count, page_prev=page_prev, page_next=page_next, paginator=paginator, paginator_page=pgpg, place=place, datastories=place_stories, same_place_parts=spp, ), context_instance=RequestContext(request))
page = pgpg.object_list[0] page_num = pgpg.number page_next = pgpg.next_page_number() if pgpg.has_next() else 0 page_prev = pgpg.previous_page_number() if pgpg.has_previous() else 0 if story: spp = InOtherPlace.get_split('story', 'XXX', 'XXX', story.slug) else: spp = InOtherPlace.get_split('story', 'XXX', 'XXX') return render_to_response('datastories/story.html', dict( story=story, page_type=page_type, page=page, page_num=page_num, page_count=page_count, page_prev=page_prev, page_next=page_next, paginator=paginator, paginator_page=pgpg, place=place, datastories=place_stories, same_place_parts=spp, ), context_instance=RequestContext(request)) InOtherPlace(story, 'XXX') InOtherPlace(story, 'XXX', 'YYY')