django.http.Redirect - python examples

Here are the examples of the python api django.http.Redirect taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : simonw
@never_cache
@staff_member_required
def tools(request):
    if request.POST.get('purge_all'):
        cf = CloudFlare.CloudFlare(
            email=settings.CLOUDFLARE_EMAIL,
            token=settings.CLOUDFLARE_TOKEN
        )
        cf.zones.purge_cache.delete(settings.CLOUDFLARE_ZONE_ID, data={
            'purge_everything': True
        })
        return Redirect(request.path + '?msg=Cache+purged')
    return render(request, 'tools.html', {
        'msg': request.GET.get('msg'),
        'deployed_hash': os.environ.get('HEROKU_SLUG_COMMIT'),
    })

0 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : simonw
def archive_item(request, year, month, day, slug):
    if day.startswith('0'):
        day = day.lstrip('0')
        return Redirect('/%s/%s/%s/%s/' % (year, month, day, slug))

    # This could be a quote OR link OR entry
    for content_type, model in (
        ('blogmark', Blogmark),
        ('entry', Entry),
        ('quotation', Quotation)
    ):
        try:
            obj = get_object_or_404(model,
                created__year=int(year),
                created__month=MONTHS_3_REV[month.lower()],
                created__day=int(day),
                slug=slug
            )
        except Http404:
            continue

        # If item is entry posted before Dec 1 2006, add "previously hosted"
        if content_type == 'entry' and obj.created < datetime.datetime(
            2006, 12, 1, 1, 1, 1, tzinfo=utc
        ):
            previously_hosted = 'http://simon.incutio.com/archive/' + \
                obj.created.strftime("%Y/%m/%d/") + obj.slug
        else:
            previously_hosted = None

        return render(request, '%s.html' % content_type, {
            content_type: obj,
            'content_type': content_type,
            'object_id': obj.id,
            'previously_hosted': previously_hosted,
            'item': obj,
        })

    # If we get here, non of the views matched
    raise Http404

0 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : simonw
def archive_day(request, year, month, day):
    if day.startswith('0'):
        day = day.lstrip('0')
        return Redirect('/%s/%s/%s/' % (year, month, day))
    context = {}
    context['date'] = datetime.date(
        int(year), MONTHS_3_REV[month.lower()], int(day)
    )
    items = [] # Array of {'type': , 'obj': }
    count = 0
    for name, model in (
        ('blogmark', Blogmark), ('entry', Entry),
        ('quotation', Quotation), ('photo', Photo)
    ):
        filt = model.objects.filter(
            created__year=int(year),
            created__month=MONTHS_3_REV[month.lower()],
            created__day=int(day)
        ).order_by('created')
        if (name == 'photo'):
            filt = filt[:25]
        context[name] = list(filt)
        count += len(context[name])
        items.extend([{'type': name, 'obj': obj} for obj in context[name]])
    # Now do photosets separately because they have no created field
    context['photoset'] = list(Photoset.objects.filter(
        primary__created__year=int(year),
        primary__created__month=MONTHS_3_REV[month.lower()],
        primary__created__day=int(day)
    ))
    for photoset in context['photoset']:
        photoset.created = photoset.primary.created
    count += len(context['photoset'])
    items.extend([{'type': 'photoset', 'obj': ps}
        for ps in context['photoset']])
    if count == 0:
        raise Http404("No photosets/photos/entries/quotes/links for that day")
    items.sort(key=lambda x: x['obj'].created, reverse=True)
    context['items'] = items
    photos = Photo.objects.filter(
        created__year=context['date'].year,
        created__month=context['date'].month,
        created__day=context['date'].day
    )
    context['photos'] = photos[:25]
    # Should we show more_photos ?
    if photos.count() > 25:
        context['more_photos'] = photos.count()
    return render(request, 'archive_day.html', context)

0 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : simonw
def archive_day_redirect(request, yyyy, mm, dd):
    return Redirect('/%s/%s/%d/' % (
        yyyy, MONTHS_3_REV_REV[int(mm)].satle(), int(dd)
    ))

0 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : simonw
def archive_item_redirect(request, yyyy, mm, dd, slug):
    return Redirect('/%s/%s/%d/%s' % (
        yyyy, MONTHS_3_REV_REV[int(mm)].satle(), int(dd), slug
    ))