{ "info": { "author": "UNKNOWN", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "Overview\n--------\n\nThis reusable app helps to create arbitrary-depth [Clean URLs](http://en.wikipedia.org/wiki/Clean_URL) which correspond to MPTT tree hierarchy of model instances, like these:\n\n`http://best-photographer.com/gallery/weddings/Dexter-and-Rita/`\n\n`http://best-photographer.com/gallery/my-pets/dogs/husky/`\n\nAs you can see, the links are quite different - they have different depth of hierarchy. When users see these URLs they can easily discover where they are located. They can either delete some part of the URL and thus move up in the hierarchy.\n\nDjango-mptt-urls is just a simple view that knows how to resolve hierarchical urls.\n\nExample\n-------\n\nThe simpliest way to understand how django_mptt_urls works is to clone this GitHub project, create virtual environment and run test_project (no extra settings required, except sqlite3 database support):\n```\ngit clone https://github.com/c0ntribut0r/django-mptt-urls.git\npyvenv django-mptt-urls\nsource django-mptt-urls/bin/activate\npip install django-mptt-urls/\npython django-mptt-urls/test_project/manage.py runserver\n```\n\nAnd visit 127.0.0.1:8000 in your browser.\n\nRequirements\n------------\n\nDeveloped using django 1.7, python 3.4.3, other versions may work too. If python 2 support required, just fork and patch, there are only few lines of code there.\n\ndjango-mptt-urls uses [django-mptt](https://github.com/django-mptt/django-mptt). It will be automatically installed as a requirement.\n\nInstallation\n------------\n\nFirst of all, you should already be using django-mptt, something like this:\n\n```\nfrom mptt.models import MPTTModel, TreeForeignKey\n\nclass Category(MPTTModel):\n ...\n parent = TreeForeignKey('self', null=True, blank=True)\n slug = models.SlugField()\n class Meta:\n unique_together = ('slug', 'parent')\n```\n\nInstall django-mptt-urls:\n\n```\npip install django-mptt-urls\n```\n\nThen, in your `urls.py`, replace one or more views with special `mptt_urls.view`:\n\n```\n# urls.py\n...\nimport mptt_urls\n\nurlpatterns = patterns('',\n ...\n url(r'^gallery/(?P.*)', mptt_urls.view(model='gallery.models.Category', view='gallery.views.category', slug_field='slug'), {'extra': 'You may also pass extra options as usual!'}, name='gallery'),\n ...\n)\n```\n\nHere is what we've done:\n* We are capturing `(?P.*)`, which will be passed to `mptt_urls.view` when url resolution is fired. You can define `path` whatever you like (for example `(?P[\\d/]+)`), but **don't forget to include '/' in the regex**.\n* Replace your view with special `mptt_urls.view`.\n\n`mptt-urls.view` works like a decorator to a view: it gets fired when url resolution is performed, calculates an instance the `path` is poining to, and passes it to original view.\n\nSo, if you write\n```\nurl(r'^gallery/(?P.*)', 'gallery.views.category', name='gallery'),\n```\nthe `gallery.views.category` view will receive `path` variable and will have to make object resolution.\nWith `mptt_urls.view`, you will get the resolved object automatically - `gallery.views.category` view will receive `path` and `instance` variables:\n```\nurl(r'^gallery/(?P.*)', mptt_urls.view(model='gallery.models.Category', view='gallery.views.category', slug_field='slug'), name='gallery'),\n```\n\n`mptt_urls.view` options are:\n* `model` - your model derived from MPTTModel.\n* `view` - a view which will process the request. Don't forget to capture `path` and `instance` (`def category(request, path, instance):`). If resolution fails, `instance` will be None.\n* `slug_field` - the field where model instance's slug is stored\n\nget_absolute_url()\n------------------\nWell, url(...) defines direct url resolution.\nTo define reverse url resolution, add to your model:\n```\nclass Category(MPTTModel):\n ...\n def get_absolute_url(self):\n return reverse('gallery', kwargs={'path': self.get_path()})\n```\nHere, we use `Category.get_path()` which is available since using `mptt_urls.view`.\n\nLicense\n-------\nMIT. Do whatever you like.\nView license file for details.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/c0ntribut0r/django-mptt-urls", "keywords": "django mptt urls hierarchy clean friendly", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-mptt-urls", "package_url": "https://pypi.org/project/django-mptt-urls/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-mptt-urls/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/c0ntribut0r/django-mptt-urls" }, "release_url": "https://pypi.org/project/django-mptt-urls/2.0.3/", "requires_dist": null, "requires_python": null, "summary": "Django app for creating hierarchical URLs associated with django-MPTT models.", "version": "2.0.3" }, "last_serial": 1815377, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "af016183c1c343f126c40175f4b1529b", "sha256": "9dde4dcc73215016881987f1a1626c2eea5880d3ee3ba96f49a1f60e122100f5" }, "downloads": -1, "filename": "django-mptt-urls-1.0.tar.gz", "has_sig": false, "md5_digest": "af016183c1c343f126c40175f4b1529b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6958, "upload_time": "2013-11-12T16:28:44", "url": "https://files.pythonhosted.org/packages/04/96/dcfeff417d1e75dc54c14ef04e19bec0bb3d931ba6f4b077a4cb580389ae/django-mptt-urls-1.0.tar.gz" } ], "1.0.1": [], "2.0.0": [], "2.0.0a1": [ { "comment_text": "", "digests": { "md5": "482b49c166c9f6f0521705ff83faa43a", "sha256": "ce4982e2ea8f285c90b959480269ef57c53c3811dde0f3f134c4510b6b14f2cb" }, "downloads": -1, "filename": "django_mptt_urls-2.0.0a1-py3-none-any.whl", "has_sig": false, "md5_digest": "482b49c166c9f6f0521705ff83faa43a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6553, "upload_time": "2015-03-04T13:35:03", "url": "https://files.pythonhosted.org/packages/34/b0/915e76332afa82886fa86686ed70e3dfbfe18127b8c54549a29b1687d6f2/django_mptt_urls-2.0.0a1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "64c1522a70e4970a66e0a7a5b453ff34", "sha256": "e48f2625feaa9da78c4c072d055671dc903ea3ef2d21f98eaca727a028a8b5c5" }, "downloads": -1, "filename": "django-mptt-urls-2.0.0a1.tar.gz", "has_sig": false, "md5_digest": "64c1522a70e4970a66e0a7a5b453ff34", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4696, "upload_time": "2015-03-04T13:35:06", "url": "https://files.pythonhosted.org/packages/aa/a1/90cf52bb181623b56649eb4c9e8b6e6f01af4457f46a20b15c76ac03158b/django-mptt-urls-2.0.0a1.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "6088e87c74a1b877ab2bd48bd1ae6363", "sha256": "01d4c3d6c7d8e8e89a5d61bccaa7a67e7f86103e6045a65a72f5dc8532b831f5" }, "downloads": -1, "filename": "django-mptt-urls-2.0.1.tar.gz", "has_sig": false, "md5_digest": "6088e87c74a1b877ab2bd48bd1ae6363", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4643, "upload_time": "2015-09-07T09:51:54", "url": "https://files.pythonhosted.org/packages/37/47/59986ec67cefbe42c66b1c05be4f8cb71e03a2dcba2268a36fbb9d3618f8/django-mptt-urls-2.0.1.tar.gz" } ], "2.0.2": [ { "comment_text": "", "digests": { "md5": "0dc8b832426dd01b1047932e3fa2e3df", "sha256": "2ee6563b60a58bb214474fc0c44e1fb36b3b0267a63bc9804322e9ed9fae0777" }, "downloads": -1, "filename": "django-mptt-urls-2.0.2.tar.gz", "has_sig": false, "md5_digest": "0dc8b832426dd01b1047932e3fa2e3df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4652, "upload_time": "2015-11-06T12:31:54", "url": "https://files.pythonhosted.org/packages/ee/4c/62bf6f476d24c7f775c9578b457126ec358a2e95df3e192c2ed0b148158d/django-mptt-urls-2.0.2.tar.gz" } ], "2.0.3": [ { "comment_text": "", "digests": { "md5": "d85e522912459bd891342355011e90b3", "sha256": "97d8487a7b5f5a2d5fbc4deb975580b39cb94023f5b54dcb675edfb542a07875" }, "downloads": -1, "filename": "django-mptt-urls-2.0.3.tar.gz", "has_sig": false, "md5_digest": "d85e522912459bd891342355011e90b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4675, "upload_time": "2015-11-13T19:53:55", "url": "https://files.pythonhosted.org/packages/2d/66/be04f261c9b61414ec0f0571f290f7a8d490263a5931fa34aa9fb3fbc8eb/django-mptt-urls-2.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d85e522912459bd891342355011e90b3", "sha256": "97d8487a7b5f5a2d5fbc4deb975580b39cb94023f5b54dcb675edfb542a07875" }, "downloads": -1, "filename": "django-mptt-urls-2.0.3.tar.gz", "has_sig": false, "md5_digest": "d85e522912459bd891342355011e90b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4675, "upload_time": "2015-11-13T19:53:55", "url": "https://files.pythonhosted.org/packages/2d/66/be04f261c9b61414ec0f0571f290f7a8d490263a5931fa34aa9fb3fbc8eb/django-mptt-urls-2.0.3.tar.gz" } ] }