Skip to main content

django-urlconverter: Django automatic view parameters conversion

The django-urlconverter package provides an easy way to convert view arguments from simple types to complex ones, like models, or just do some processing using robust syntax. Most interesting application of the package is to convert view arguments which are object ids (from database via ORM) to the instances of those objects (Models).

https://api.travis-ci.org/paylogic/django-urlconverter.png https://pypip.in/v/django-urlconverter/badge.png https://coveralls.io/repos/paylogic/django-urlconverter/badge.png?branch=master

Installation

pip install django-urlconverter

Usage

models.py:

from django.db import models


class FooBar(models.Model):
    """Foo Bar model."""
    title = models.CharField(max_length=100)

converters.py:

from .models import FooBar


class Foo(object):
    """Foo converter. Convert an object id to FooBar instance."""
    def __init__(self, **kwargs):
        self.kwargs = kwargs

    def __call__(self, value, request, *args, **kwargs):
        return FooBar.objects.get(pk=value)

settings.py:

URL_CONVERTERS = {
    'Foo': 'converters.Foo',  # Converts to 'FooBar instance'
}

urls.py:

from django.conf.urls.defaults import patterns
from django_urlconverter import converted_arguments_url

urlpatterns = patterns('views',
    converted_arguments_url(r'^foos/<Foo:foo2>/', 'bar'),
)

views.py:

def bar(request, foo2):
    """View function which gets a converted foo2.
    the foo2 will be a converted parameter, which is the result of Foo converter
    """
    return foo2.title

Contact

If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.

License

This software is licensed under the MIT license

See https://github.com/paylogic/django-urlconverter/blob/master/LICENSE.txt

© 2013 Paylogic International.

Changelog

1.0.0

  • Initial public release

Metadata

Release files for django-urlconverter 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-urlconverter 1.0.0
File Size Uploaded
django-urlconverter-1.0.0.tar.gz 5.5 kB Details

Release files / django-urlconverter-1.0.0.tar.gz

Download URL django-urlconverter-1.0.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
46d2c40adb44c7132b29ad744052cacaa50f19e16ad61f06cc972e3a79aa983d
BLAKE2b-256 checksum
How to use checksums
b7b420bfcb04c2afea531e7d3b56c294ca34c7b7bbece82ed005c51edafd4569
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page