{ "info": { "author": "Stefano Parmesan", "author_email": "s.parmesan@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "-----------------\ndjango-urls-sugar\n-----------------\n\ndjango-urls-sugar aims to make defining complex urls in django easier.\nIt provides a `patterns' method that extends the django.conf.urls.defaults functionalities, allowing to define more complex structured urls.\n\nIts implementation takes inspiration from django-templatetags-sugar_.\n\n\nInstallation\n============\n\nJust run ``pip install django-urls-sugar`` in a terminal to do the magic.\n\n\nUsage\n=====\n\nIn order to use django-urls-sugar you just need to slightly alter your urls.py files, using the redefined patterns (which just extends the default one, allowing you to define usual urls as well). For example::\n \n from django.conf.urls.defaults import url\n from urls_sugar.utils import patterns, url_sugar\n from urls_sugar.classes import Constant, Variable\n \n urlpatterns = patterns('',\n url('^home$', home_view, name='home'),\n url_sugar([Constant('page'),\n Variable('pk', '\\d+'),\n ], page_view, name='page'),\n ...\n\n\nThis two urls will handle::\n\n /home/\n /page/(?P\\d+)/\n\n\nThe first parameter of url_sugar is a list of urls_sugar elements, which can be any of the following:\n\nConstant\n--------\nA constant is, as the name suggests, a constant part of the url. It accepts a single parameter, that can be eather a string or a list of strings (in which case multiple urls will be generated). For example\n\n* ``Constant('home')`` will generate the simple url ``^home/$``;\n* ``Constant(['home', 'homepage'])`` will generate two urls, ``^home/$`` and ``^homepage$``, pointing to the same view.\n\nThis allows you to define in a simple way multiple (constant) urls, avoiding redirects or allowing to translate urls.\n\n\nVariable\n--------\nA variable is more complex. In general, it allows to define a variable in the url that will be passed to the view, as for usual urls. It accepts two parameters, the variable name, and the regular expression to be matched. A simple example is:\n\n* ``Variable('language', '[a-z]{2}')`` which will, easy to guess, generate the url ``^(?P[a-z]{2}')$``.\n\nVariables allows however more complex interaction. Suppose you want the variable to be an hyphen-separated list of something. Variable allows you to specify this with a simple\n\n* ``Variable('languages', '[a-z]{2}', separator='-')``.\n\nYou can also set the ``min`` and ``max`` parameters to specify a lower / upper bound for such list.\n\n\nOptional\n--------\nThe Optional element allows us to define optional parts in the url. Optional takes (multiple) urls_sugar elements as parameters. For example:\n\n* ``Optional(Constant('home'), Constant('index'))`` will generate ``^/$`` and ``^home/index/$``, while\n* ``Optional(Constant('home')), Optional(Constant('index'))`` will generate ``^/$``, ``^home/$``, ``^index/$`` and ``^home/index/$``.\n\n\nSpecial cases\n=============\n\nPrefix and Suffix\n-----------------\nConstant and Variable allow to specify a prefix and a suffix, which are by default respectively ``''`` and ``'/'``. In this way, ``Constant('home')`` generates ``^home/$``. Using custom prefixes and suffixes can be useful for example when handling special resource types::\n\n url_sugar([Constant('resource'),\n Variable('slug', '[a-z0-9-]+', suffix=''),\n Variable('type', '[a-z]+', prefix='.'),\n ], resource_view, name='resource')\n\nThis will handle urls like ``/resource/my-awesome-resource.json``\n\n\nVariable disambiguation\n-----------------------\nWhen having too many optional variables, it may become impossible for Django to understand which variable should get the given value. For example::\n\n url_sugar([Constant('pages'),\n Optional(Variable('language', '[a-z]{2}')),\n Optional(Variable('filter', [a-z]+')),\n ], page_view, name='page')\n\nIn this case it is impossible to distinguish between ``/pages/it/`` and ``pages/blogposts/``. Variable allows then to be disambiguated, setting the ``unambiguous`` flag::\n\n url_sugar([Constant('pages'),\n Optional(Variable('language', '[a-z]{2}', unambiguous=True)),\n Optional(Variable('filter', [a-z]+'), unambiguous=True),\n ], page_view, name='page')\n\nWhich will handle urls such as ``/pages/language:it/``, ``/pages/filter:blogposts/`` or ``/pages/language:it/filter:blogposts/``.\n\n.. _django-templatetags-sugar: http://github.com/alex/django-templatetag-sugar", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/ahref/django-urls-sugar", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-urls-sugar", "package_url": "https://pypi.org/project/django-urls-sugar/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-urls-sugar/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/ahref/django-urls-sugar" }, "release_url": "https://pypi.org/project/django-urls-sugar/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "A library for making complex urls in Django easier.", "version": "0.1.4" }, "last_serial": 790952, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "30ca0013d8f43996fa52ebca50536a74", "sha256": "169b515420c1b52ee396256ef133b4b1e2130284e29540f3566598a30d75f69a" }, "downloads": -1, "filename": "django-urls-sugar-0.1.tar.gz", "has_sig": false, "md5_digest": "30ca0013d8f43996fa52ebca50536a74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3870, "upload_time": "2011-12-02T16:48:11", "url": "https://files.pythonhosted.org/packages/31/e7/eebdeb7a22a49eb4eb73b0debab7ee09e2d545d9a8e58ad71ef43e9101d1/django-urls-sugar-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "6f5824ffeb8e445464586e371e17d57c", "sha256": "972d6c267e430b8b31d140128620dad6eb54e7e05e77b7e75b78b170bc5d3036" }, "downloads": -1, "filename": "django-urls-sugar-0.1.1.tar.gz", "has_sig": false, "md5_digest": "6f5824ffeb8e445464586e371e17d57c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4993, "upload_time": "2011-12-02T16:54:06", "url": "https://files.pythonhosted.org/packages/1b/04/44f332f961229cc51c87d046ba75547275b61b405110c30e6ed01061c39e/django-urls-sugar-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "7bffe9d0719865a4f0b55abd0d3712fc", "sha256": "5b69e9bfec42f9e8a5dfc0484916a43dbf97f478cc13eaa83d5897a11acbaf1b" }, "downloads": -1, "filename": "django-urls-sugar-0.1.2.tar.gz", "has_sig": false, "md5_digest": "7bffe9d0719865a4f0b55abd0d3712fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4738, "upload_time": "2012-02-17T09:08:57", "url": "https://files.pythonhosted.org/packages/aa/ec/78dd1602e63783b7cfa29b06ccb4c10f9d9f0a15a88cb50b6c86a93a7271/django-urls-sugar-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "207a25a81a82144a04d8b436d3e7ddfe", "sha256": "266f0f060f9ab5d8c17b8a557eb0e96956a0951dbce3239bbaf6f4016d90fddc" }, "downloads": -1, "filename": "django-urls-sugar-0.1.3.tar.gz", "has_sig": false, "md5_digest": "207a25a81a82144a04d8b436d3e7ddfe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5008, "upload_time": "2012-02-17T09:12:32", "url": "https://files.pythonhosted.org/packages/ae/aa/126b8f4a8645a71679a3da4743a213935829c0d4698ad6ca0ba813db7082/django-urls-sugar-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "f8a7f96d9833b42c681198111be4d2a5", "sha256": "a22bf7fc2084f4a4d4621c2fb21565bc68d9ec174626c564ebe2191500949f42" }, "downloads": -1, "filename": "django-urls-sugar-0.1.4.tar.gz", "has_sig": false, "md5_digest": "f8a7f96d9833b42c681198111be4d2a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5157, "upload_time": "2012-11-19T13:19:57", "url": "https://files.pythonhosted.org/packages/04/ad/95d323d50f74f47996d7c601bd39eda87f302477c67d589c6e70c388d291/django-urls-sugar-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f8a7f96d9833b42c681198111be4d2a5", "sha256": "a22bf7fc2084f4a4d4621c2fb21565bc68d9ec174626c564ebe2191500949f42" }, "downloads": -1, "filename": "django-urls-sugar-0.1.4.tar.gz", "has_sig": false, "md5_digest": "f8a7f96d9833b42c681198111be4d2a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5157, "upload_time": "2012-11-19T13:19:57", "url": "https://files.pythonhosted.org/packages/04/ad/95d323d50f74f47996d7c601bd39eda87f302477c67d589c6e70c388d291/django-urls-sugar-0.1.4.tar.gz" } ] }