Skip to main content

django-brevisurl is django app for shortening urls

Project description

django-brevisurl is django app for shortening urls. Brevis is a latin word, which means short, so the name brevisurl == shorturl or url shortener. The actual creating of short url is handled by the shortening backend.

Requirements

  • python 2.7+

  • django

Installation

Install via pypi or copy this module into your project or into your PYTHONPATH.

Put brevisurl into INSTALLED_APPS in your projects settings.py file

INSTALLED_APPS = (
    'localeurl',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.sitemaps',
    'web',
    'debug_toolbar',
    'rosetta',
    'south',
    'brevisurl'
)

Run syncdb command to create database tables from brevisurl models

python manage.py syncdb

Configuration

django settings.py constants

# Setting for default brevis backend
BREVISURL_BACKEND = 'brevisurl.backends.local.BrevisUrlBackend' # Default is 'brevisurl.backends.local.BrevisUrlBackend'

# This bypasses Django Site framework and settings.SITE_ID; if set, brevisurl don't use Django Site framework
# but uses this settings insted to generate  absolute urls
BREVISURL_BACKEND_LOCAL_DOMAIN = 'http://brevisurl.net/' # Default is None

Append brevisurl url patterns to your urls.py at the end of module, if you’re using local backend

urlpatterns += patterns('',
    # brevisurl urls
    (r'^', include('brevisurl.urls'))
)

To be able to access brevisurl settings add brevisurl.context_processors.brevisurl_data to your context processors

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages',
    'brevisurl.context_processors.brevisurl_data'
)

Examples

Example 1

Using programmatic approach

from brevisurl import get_connection

connection = get_connection()
short_url_obj = connection.shorten_url('http://www.codescale.net/')
print short_url_obj.shortened_url

Example 2

Using programmatic approach with shortcut

from brevisurl import shorten_url

shor_url_obj = shorten_url('http://www.codescale.net/')
print shor_url_obj.shortened_url

Example 3

Using brevisurl in templates via filter approach

{% load brevisurl %}
{% url homepage as homepage_url %}
{{ homepage_url|shorten_url }}

Example 4

Using brevisurl in templates with filtered tag approach. brevisurl comes with special tag called absurl that works exactly the same as url django tag but prepends protocol + domain in front of resovled url path.

{% load brevisurltags %}
{% absurl homepage as homepage_url %}
{{ homepage_url|shorten_url }}

Tests

Tested on evnironment

  • Xubuntu Linux 12.04 LTS precise 64-bit

  • python 2.7.3+

  • python unittest

  • django 1.4

Running tests

To run the test run command:

$ python manage.py test brevisurl

Author

char0n (Vladimír Gorej, CodeScale s.r.o.)

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-brevisurl-0.9.3.tar.gz (9.4 kB view details)

Uploaded Source

File details

Details for the file django-brevisurl-0.9.3.tar.gz.

File metadata

File hashes

Hashes for django-brevisurl-0.9.3.tar.gz
Algorithm Hash digest
SHA256 9685172fa9a2f69e23133f2c9150b94bc034633cf3bbacf9450ef8acad050d74
MD5 877a87d38c946bffd86872936a9c7eda
BLAKE2b-256 305b6fc125580830464a1c372b6db1fc776bd960aef1ad576d7c369fed120210

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page