{ "info": { "author": "Piotr Husiaty\u0144ski", "author_email": "phusiatynski@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "======================\nDjango Dynamic Widgets\n======================\n\n\nDjango dynamic widgets is a library that allow you to define HTML and expose\nchunks, that will be load on page using XHR request.\n\nThere are few reasons why would you want to do this. The most obvious are:\n\n* caching the whole page while still displaying *hello **username** * in the\n top right corner,\n* load content only on certain actions - user clicked or hovered on certain\n element\n\n\nInstallation\n------------\n\nMake sure that `django.contrib.staticfiles` is set up properly and add\n`dynamicwidgets` to your `INSTALLED_APPS` setting::\n\n INSTALLED_APPS = (\n # ...\n 'django.contrib.staticfiles',\n # ...\n 'dynamicwidgets',\n )\n\n\nURL configuration\n~~~~~~~~~~~~~~~~~\n\nTo autodiscover your widget routing, you have to import all your handlers.\nThis can be done using `dynamicwidgets.handlers.default.autodiscover()`. After\nthat, you have to place handler view somewhere in the urls tree. Good place\nmight be applications `urls.py` file::\n\n from dynamicwidgets import handlers\n\n handlers.default.autodiscover()\n\n urlpatterns = patterns('',\n # ...\n url(r'^dynamicwidget/', include('dynamicwidgets.urls')),\n )\n\nJavascript setup\n~~~~~~~~~~~~~~~~\n\nDynamic widgets library is using javascript to dynamicly load HTML chunks and\ndepends on jQuery.\n\nOn page that you will use dynamic widges, include both jQuery and dynamic\nwidges libraries::\n\n\n {# include jQuery #}\n \n\nIn addition, **before** including above libraries, preferably in `
` tag,\nspecify path to widgets view::\n\n \n\n\nUsage\n-----\n\nTo use a widget, you have to define handler that will build and return a\ncontent and a tag in the HTML document that content will be load into.\n\nWidget handler\n~~~~~~~~~~~~~~\n\nWidget handler is a function that always takes two parameters - `request` and\na list of `widgets`. To define a handler, decorate it with\n`dynamicwidgets.decorators.widget_handler`::\n\n\n from articles.models import Article\n from dynamicwidgets.decorators import widget_handler\n\n\n @widget_handler(r'^user-name$')\n def user_name(request, widgets):\n if request.user.is_anonymous():\n return {'user-name': {'html': 'anonymous'}}\n return {'user-name': {'html': request.user.username}}\n\n\nEvery handler should return a dictionary, where keys are widget names and\nvalues are dictionaries. If value dictionary contains `html` key, it's value\nwill be rendered on page as widget content.\n\n\nFor performance reasons, all widget matches are aggregated and within single\nrequest and every widget handler is called not more than once. Because of\nthat, you can save some queries to the database::\n\n @widget_handler(r'^article-details:(?P