Skip to content

teamcolab/django-ittybitty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This application offers those with Django-powered sites to have their very own URL-shortening capabilities with great ease.  For an idea of what "URL-shortening" means, have a gander at http://mashable.com/2008/01/08/url-shortening-services/ or just Google "url shortening".  It's kind of a big deal all of the sudden.

Why should you use this when all of those services already exist online?  Maybe it's just me, but I don't like relying on 3rd party servers in order for my site to function, and that includes relying on other servers for people to follow a link to my site.  With this application installed, you no longer need to worry about downtime on those other servers affecting your traffic at all.  If people can't get to your site using the shortened URLs generated by this application, you probably have bigger problems (ie your site itself is down).

By the way, here's the article from scripting.com that inspired me to create this project: http://www.scripting.com/stories/2009/03/07/solvingTheTinyurlCentraliz.html

==Features==

  * Has potential to shorten up to 18,446,744,073,709,551,615 URLs in 64 characters or less (plus the length of "http://www.yourdomain.com/"). if you have that many URLs to shorten, you are likely to need more hardware before you need more URLs...
  * Uses a simple template tag to give your templates access to the shortened URL for any given page on your site
  * Will not try shorten a URL if the URL itself is shorter than its generated shortcut URL would be
  * Keeps track of how many times a particular Itty Bitty URL is used to access the real URL on your site

==Requirements==

`django-ittybitty` requires a relatively modern version of the Django framework.  By modern I simply mean a version with the `newforms-admin` functionality.  If you're running on Django 1.0 or later, you're good.

`django-ittybitty` also relies upon the `django.contrib.sites` framework in order to create the full URL for redirecting users.

==Installation==

Download `django-ittybitty` using *one* of the following methods:

===easy_install===

You can download the package from the [http://pypi.python.org/pypi/django-ittybitty/ CheeseShop] or use

{{{
easy_install django-ittybitty
}}}

to download and install `django-ittybitty`.

===Package Download===

Download the latest `.tar.gz` file from the downloads section and extract it somewhere you'll remember.  Use `python setup.py install` to install it.

===Checkout from Subversion===

Execute the following command (or use the equivalent function in a GUI such as TortoiseSVN), and make sure you're checking ittybitty out somewhere on the `PYTHONPATH`.

{{{
svn co http://django-ittybitty.googlecode.com/svn/trunk/ittybitty ittybitty
}}}

===Verifying Installation===

The easiest way to ensure that you have successfully installed ittybitty is to execute a command such as:

{{{
python -c "import ittybitty; print ittybitty.get_version()"
}}}

If that displays the version of ittybitty that you tried to install, you're good to roll.  If you see something other than that, you probably need to check your `PYTHONPATH` environment variable.

==Configuration==

First of all, you must add this project to your list of `INSTALLED_APPS` in `settings.py`:

{{{
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    ...
    'ittybitty',
    ...
)
}}}

Run `manage.py syncdb`.  This creates the table in your database that is necessary for operation.

Next, you should add an the Itty Bitty middleware to the `MIDDLEWARE_CLASSES` in your `settings.py` file.  For example:

{{{
MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    'ittybitty.middleware.IttyBittyURLMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
)
}}}

*Note*: if you have `django.contrib.flatpages` installed, you will probably want to place the `ittybitty.middleware.IttyBittyURLMiddleware` class above the `django.contrib.flatpages.middleware.FlatpageFallbackMiddleware` in your `MIDDLEWARE_CLASSES`.  This is so that the flat pages middleware will check for a flatpage before the Itty Bitty middleware tries to kick in.

==Usage==

Once all of your configuration is taken care of, using `django-ittybitty` is very simple.  In any Django template, just `{% load ittybitty_tags %}` and have fun with the `{% ittybitty_url %}` template tag!

For example:

{{{
{% extends 'base.html' %}
{% load ittybitty_tags %}

{% block content %}
<a href="{% ittybitty_url %}">Link to this page!</a>
{% endblock %}
}}}

or:

{{{
{% extends 'base.html' %}
{% load ittybitty_tags %}

{% block content %}
{% ittybitty_url as ittybitty %}
<a href="{{ ittybitty.get_shortcut }}">Link to this page!</a>
{% endblock %}
}}}

or:

{{{
{% extends 'base.html' %}
{% load ittybitty_tags %}

{% block content %}
{% ittybitty_url as ittybitty %}
{% with ittybitty.get_shortcut as short_url %}
<a href="{{ short_url }}">Link to this page!</a>
<a href="{{ short_url }}">Link to this page again!</a>
<a href="{{ short_url }}">Link to this page one more time!</a>
{% endwith %}
{% endblock %}
}}}

If you want each and every page on your site to have a link for "link to this page", you could throw the `{% ittybitty_url %}` tag into your `base.html` (or whatever template everything else inherits from) and call it a day.