### redirect_anywhere/models.py ###
from django.db import models

class RedirectAnywhere(models.Model):
    md5sum = models.CharField(max_length=40)
    url = models.CharField(max_length=500)

    class Meta:
        verbose_name_plural = "redirect anywhere"



### redirect_anywhere/urls.py ###
from django.conf.urls.defaults import *
from redirect_anywhere.views import *

urlpatterns = patterns('',
    (r'^$', redirect_anywhere),
    (r'^(?P<md5sum>\w+)/$', redirect_anywhere),
)



### redirect_anywhere/views.py ###
import hashlib
from django.shortcuts import render_to_response
from django.template import RequestContext
from redirect_anywhere.models import *

def redirect_anywhere(request, md5sum=None):
    redirect_anywhere = None
    new_redirect_anywhere = None

    if request.method == 'POST':
        if request.POST.has_key('direct_url'):
            direct_url = request.POST['direct_url']
            md5sum = hashlib.md5(request.POST['direct_url']).hexdigest()
            try:
                new_redirect_anywhere = RedirectAnywhere.objects.get(md5sum = md5sum)
            except RedirectAnywhere.DoesNotExist:
                new_redirect_anywhere = RedirectAnywhere(md5sum = md5sum, url = direct_url)
                new_redirect_anywhere.save()
    elif md5sum:
        try:
            redirect_anywhere = RedirectAnywhere.objects.get(md5sum = md5sum)
        except RedirectAnywhere.DoesNotExist:
            pass

    context = {
        'redirect_anywhere': redirect_anywhere,
        'new_redirect_anywhere': new_redirect_anywhere,
    }
    return render_to_response('redirect_anywhere/redirect_anywhere.html', context,
        context_instance = RequestContext(request))



### template/redirect_anywhere/redirect_anywhere.html (simplified example) ###
<form method="post" action=".">
    Your blocked URL:
    <input type="text" name="direct_url" size="40" />
    <input type="submit" value="Get RedirectAnywhere URL" />
</form>

{% if redirect_anywhere %}
<br />Your RedirectAnywhere URL is to unblock the URL below. Click on it to continue..
<h1><a href="{{redirect_anywhere.url}}/">{{redirect_anywhere.url}}</a></h1>
{% endif %}

{% if new_redirect_anywhere %}
<br />Your RedirectAnywhere URL for <a href="{{new_redirect_anywhere.url}}">{{new_redirect_anywhere.url}}</a> is:<br />
<textarea class="textarea">dazzlepod.com/redirect_anywhere/{{new_redirect_anywhere.md5sum}}</textarea>
{% endif %}
