{ "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\\d+)$')\n def article_details(request, widgets):\n articles = Article.objects.filter(\n id__in=[w.params.art_id for w in widgets])\n article_by_id = {art.id: art for art in articles}\n\n response = {}\n for widget in widgets:\n article = article_by_id[int(widget.params.art_id)]\n html = '

article {}: {}

'.format(article.id, article.title)\n response[widget.wid] = {'html': html}\n return response\n\n\nEvery `widget` object contains two attributes:\n\n* `wid` that holds the name of the widget, mached by regular expression which\n view was decorated with\n* `params` holding zero or more parameters extracted from decorator's regular\n expression\n\n\nHTML attributes\n~~~~~~~~~~~~~~~\n\nWhenever you want to use a widget, add `dw` attribute to an element. Those can\nbe:\n\n* `dw-load` for widgets that should be loaded once the document is ready,\n* `dw-click` for widgets that should be loaded on `click` event,\n* `dw-hover` for widgets that should be loaded on `mouseover` event.\n\nUsing them can be as simple as::\n\n
\n \n
\n
\n click to show article\n hover to show article\n
\n\nIn addition, you can add `dw-once` attribute, to make sure widget content will\nbe fetched only once::\n\n hover to show article\n\nBut simple replacing of the content might not be enough. That's why full\nformat of the attribute value can be build using multiple chunks, separated by\ncomma character::\n\n dw-=\",,\"\n\n* `` is used to match handler function. That's the only required\n part of the value string,\n* `` is any valid jQuery input method like `html`, `append`,\n `prepend`. Default value is `html`,\n* `` is sizzle selector with one addition. Selector\n starting with `@` character is always narrowed to element that `dw`\n attribute was declarated. Default value is `@`.\n\nKnowing all above, it's easy to make dropdown menu with dynamic content load::\n\n\n \n\n
\n Menu\n \n Loading...\n \n
", "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/husio/django-dynamicwidgets/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-dynamicwidgets", "package_url": "https://pypi.org/project/django-dynamicwidgets/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-dynamicwidgets/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/husio/django-dynamicwidgets/" }, "release_url": "https://pypi.org/project/django-dynamicwidgets/1.0/", "requires_dist": null, "requires_python": null, "summary": "UNKNOWN", "version": "1.0" }, "last_serial": 931360, "releases": { "1.0": [] }, "urls": [] }