Example #1
0
def article_view(request, story_id, **section_and_slug):
    template = 'story.html'
    # template = 'dateline.html'
    try:
        story = Story.objects.get(pk=story_id)
    except Story.DoesNotExist:
        slug = section_and_slug.get('slug')
        if slug:
            return search_404_view(request, slug)
        else:
            raise Http404('This page does not exist')

    if not request.user.is_staff:
        if story.publication_status != Story.STATUS_PUBLISHED:
            raise Http404('You are not supposed to visit this page')

    correct_url = story.get_absolute_url()

    if request.path != correct_url:
        return HttpResponseRedirect(correct_url)

    translation.activate(story.language)
    # context = Context({'story': story, })
    # template = get_template('story.html')
    # response = template.render(context)

    context = {'story': story, }
    response = render(request, template, context,)
    return response
Example #2
0
def fallback_view(request, slug):
    try:
        # is the slug a story type?
        story_type = StoryType.objects.get(slug=slug)
        return HttpResponseRedirect(story_type.get_absolute_url())
    except StoryType.DoesNotExist:
        try:
            # is the slug a legacy base36 short url
            story = Story.objects.get(pk=base36_to_int(slug))
            return HttpResponsePermanentRedirect(story.get_absolute_url())
        except (ValueError, Story.DoesNotExist):
            return search_404_view(request, slug)
Example #3
0
def fallback_view(request, slug):
    try:
        # is the slug a story type?
        story_type = StoryType.objects.get(slug=slug)
        return HttpResponseRedirect(story_type.get_absolute_url())
    except StoryType.DoesNotExist:
        try:
            # is the slug a legacy base36 short url
            story = Story.objects.get(pk=base36_to_int(slug))
            return HttpResponsePermanentRedirect(story.get_absolute_url())
        except (ValueError, Story.DoesNotExist):
            return search_404_view(request, slug)