Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

URL Shortener in Django

tag: v1.4

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.textile

STUMPy

Mutaku URL Shortener

WHAT IS STUMPY?

STUMPy is a URL shortener written by xiao_haozi (Mutaku) using the django python web framework.

WHY STUMPY?

There are many url shorteners out there, and STUMPy does not do anything groundbreaking.
However, there are several benefits that encouraged it’s development:

  • you keep all the data and can access it at your will
  • you keep all the code and can access/change it at your will
  • simple to use, simple to run, and simple code
  • because of it’s simplicity, it is easy to understand how url shorteners work and some of the possible optimizations
  • uses the django framework which allows for easy expansion, management, and tweaking
  • django also allows for a nice web UI for administration of all of the data

REQUIREMENTS:

{requirement [link for source]}

INSTALLATION, SETUP, AND TESTING:

See: Django Install
Once you have django installed and running, you can checkout the repo and test things out in a few steps.

  1. Grab the latest release with git.
    git clone https://mutaku@github.com/mutaku/Stumpy.git
  2. Setup a mysql database that stumpy can access.
    create database stumpy;grant all on stumpy.* to ‘SOMEUSER@localhost’ identified by “SOMEPASS”;flush privilieges;
  3. Copy the local_settings.py.dist file to local_settings.py .
    cp local_settings.py.dist local_settings.py
  4. If you do not have a SECRET_KEY generated in Django you will need to generate one by running the keygen script and copy that key into your local_settings.py file in the next step.
    python gimme_key.py
  5. Edit the local_settings.py file and add in your appropriate database variables and your secret key you already had from django or the one you generated above.
  6. Sync the database to the models.
    python manage.py syncdb
  7. Fire up the server and navigate to /admin in your browser. Go to sites→sites and edit the domain name to match the domain you are using. This will initially be set to ‘example.com’.
    python manage.py runserver

PRODUCTION RUNNING:

See: Deploying Django
Once you have your webserver setup to serve the static files, you can set DEBUG=False. Without doing so, static files will not be served up by Django in production mode (DEBUG=False).
Additionally, ensure that you have set your proper FQDN through the admin interface as mentioned in the last step of the setup section.

I have included an example fastcgi script (stumpy.fcgi) that you may point to with your webserver to run Stumpy in a production setting.
The following is an example of a stanza that you could use with Lighttpd to serve up Stumpy.

$HTTP["host"] =~ "example.com" {
  server.document-root = "/home/JohnDoe/Stumpy/"
  fastcgi.server = ( ".fcgi" =>
                     ( "localhost" => (
             "socket" => "/var/lib/lighttpd/stumpy-fastcgi.socket",
                         "bin-path" => "/home/JohnDoe/Stumpy/stumpy.fcgi",
                         "check-local" => "disable",
                         "min-procs" => 2,
             "max-procs" => 4,
                       )
                     ),
                   )
  alias.url = ( "/static/admin"  => "/home/JohnDoe/django/contrib/admin/media/" )
  url.rewrite-once = ( "^(/static/.*)$" => "$1",
                       "^/favicon\.ico$" => "/static/favicon.ico",
               "^(/.*)$" => "/stumpy.fcgi$1" )
}

USAGE:

You will probably be able to see from the urls.py how to go about using Stumpy. Here’s the rundown:

  • [site]/ → index view (recent stumps, popular stumps, and the bookmarklet)
  • [site]/[shorturl] → grab shorturl and redirect
  • [site]/register → register new user [for users – admin can add through admin interface]
  • [site]/admin *→ admin interface
  • [site]/url/[longurl] *→ shorten url [this is how the bookmarklet does it] [needs to be escaped if not using bookmarklet]

*→ These views require authenticated_user and uses sessions

NOTES:

A bookmarklet is ready to use and can be found by visiting the index page (“/”) and dragging the ‘stumpy it!’ link to your bookmarks bar.

To add additional users that may submit URLs, add the user via the admin interface. They do not need to have any admin interface abilities to simply login and and submit URLs.
If you want a user to have permission to edit and delete urls (why?) you would have to enable those permissions in the user management in the admin interface.

FAQ:

[coming soon]

HELP:

Most of the information you might need can be found in the Django docs here: Django
For Stumpy specific help, see Stumpy

Something went wrong with that request. Please try again.