{ "info": { "author": "Jonas Lundberg", "author_email": "jonas@5monkeys.se", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": ".. image:: https://raw.github.com/5monkeys/django-viewlet/master/docs/django_viewlet.png\n\nRender template parts with extended cache control.\n\n.. image:: https://travis-ci.org/5monkeys/django-viewlet.png?branch=master\n :target: http://travis-ci.org/5monkeys/django-viewlet\n\n.. image:: https://coveralls.io/repos/5monkeys/django-viewlet/badge.png?branch=master\n :target: https://coveralls.io/r/5monkeys/django-viewlet?branch=master\n\nInstallation\n------------\n\nInstall django-viewlet in your python environment\n\n.. code-block:: sh\n\n $ pip install django-viewlet\n\nSupports ``Django`` versions 1.3 - 2.0 and ``Python`` versions 2.6 - 3.6.\n\n\nConfiguration\n-------------\n\nAdd ``viewlet`` to your ``INSTALLED_APPS`` setting so Django can find the template tag\n\n.. code-block:: python\n\n INSTALLED_APPS = (\n ...\n 'viewlet',\n )\n\nJinja2\n______\n\nIf you're using ``Jinja2`` as your template engine for Django versions < 1.8,\nput this in your Django settings:\n\n.. code-block:: python\n\n VIEWLET_TEMPLATE_ENGINE = 'jinja2'\n\n\nIf you're using ``Coffin`` or ``Jingo``, add the ``ViewletExtension`` to their settings,\nand optionally switch to their respective environment.\n\n**Coffin:**\n\n.. code-block:: python\n\n JINJA2_EXTENSIONS = (\n ...\n 'viewlet.loaders.jinja2_loader.ViewletExtension',\n )\n\n VIEWLET_JINJA2_ENVIRONMENT = 'coffin.common.env'\n\n**Jingo:**\n\n.. code-block:: python\n\n JINJA_CONFIG = {\n 'extensions': (\n ...\n 'viewlet.loaders.jinja2_loader.ViewletExtension',\n ),\n }\n\n VIEWLET_JINJA2_ENVIRONMENT = 'jingo.get_env'\n\n**Django 1.8+:**\n\nAdd ``ViewletExtension`` to the list of extensions of Jinja2 template engine\n\n.. code-block:: python\n\n TEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.jinja2.Jinja2',\n # ...\n 'OPTIONS': {\n # ...\n 'extensions': [\n # ...\n 'viewlet.loaders.jinja2_loader.ViewletExtension',\n ],\n }\n }\n ],\n\n\nUsage\n-----\n\nA viewlet is almost like a function based django view, taking a template context\nas first argument instead of request.\nPlace your viewlets in ``viewlets.py`` or existing ``views.py`` in your django app directory.\n\n.. code-block:: python\n\n from django.template.loader import render_to_string\n from viewlet import viewlet\n\n @viewlet\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n\nYou can then render the viewlet with the ``viewlet`` template tag:\n\n.. code-block:: html\n\n {% load viewlets %}\n

{% viewlet hello_user request.user.username %}

\n\n\n... and in your Jinja2 templates:\n\n.. code-block:: html\n\n

{% viewlet 'host_sponsors', host.id) %}

\n\n\nSpecifying cache backend\n________________________\n\nBy default viewlet will try using ``viewlet`` cache alias, falling back to ``default``. You can specify\nwhich alias should be used in settings:\n\n.. code-block:: python\n\n VIEWLET_DEFAULT_CACHE_ALIAS = 'template_cache'\n\n CACHES = {\n # ...\n 'template_cache': {\n # ...\n },\n # ...\n }\n\nAdditionally, you can override cache alias in viewlet decorator with ``using`` argument\n\n.. code-block:: python\n\n @viewlet(using='super_cache')\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n\nRefreshing viewlets\n___________________\n\nA cached viewlet can be re-rendered and updated behind the scenes with ``viewlet.refresh``\n\n.. code-block:: python\n\n import viewlet\n viewlet.refresh('hello_user', 'monkey')\n # or\n hello_user.refresh('monkey')\n\n\nThe decorator\n_____________\n\n.. code-block:: python\n\n @viewlet(name, template, key, timeout)\n\n\n* name\n Optional reference name for the viewlet, defaults to function name.\n* template\n Optional path to template. If specified the viewlet must return a context dict,\n otherwise it is responsible to return the rendered output itself.\n* key\n Optional cache key, if not specified a dynamic key will be generated ``viewlet:name(args...)``\n* timeout\n Cache timeout. Defaults to configured cache backend default timeout, None = eternal, 0 = uncached.\n\n\nExamples\n________\n\nThe content returned by the viewlet will by default be cached. Use the ``timeout`` argument to change this.\n\n.. code-block:: python\n\n @viewlet(timeout=30*60)\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n..\n\n **Tip:** Set ``timeout`` to ``None`` to cache forever and use ``viewlet.refresh`` to update the cache.\n\n\nDjango viewlet will by default build a cache key ``viewlet:name(args...)``.\nTo customize this key pass a string to the viewlet decorator argument ``key`` that includes string mod operators for each\nviewlet argument.\n\n.. code-block:: python\n\n @viewlet(timeout=30*60, key='some_cache_key_%s')\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n\nDjango viewlet will cache returned context instead of html by using the ``template`` decorator argument.\nThis is useful if cached html is too heavy, or your viewlet template needs to be rendered on every call.\nThe specified template will then be rendered with the viewlet context merged with the parent context, usually a ``RequestContext``.\n\n.. code-block:: python\n\n @viewlet(template='hello_user.html', timeout=30*60)\n def hello_user(context, name):\n return {'name': name}\n\n..\n\n **Note:** Return context dict for the template, not rendered html/text\n\n\nIf there is no need for caching, set the viewlet decorator argument ``timeout`` to 0.\n\n.. code-block:: python\n\n @viewlet(timeout=0)\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n\nBy default your viewlets will be named as the function. To override this you can set the decorator argument ``name``\n\n.. code-block:: python\n\n @viewlet(name='greeting')\n def hello_user(context, name):\n return render_to_string('hello_user.html', {'name': name})\n\n\nA powerful usage of ``viewlet.refresh`` is to use it together with Django signals:\n\n.. code-block:: python\n\n class Product(Model):\n name = CharField(max_length=255)\n\n @viewlet(timeout=None)\n def product_teaser(context, id):\n product = get_context_object(Product, id, context)\n return render_to_string('product_teaser.html', locals())\n\n def refresh_product_teaser(instance, **kwargs):\n viewlet.refresh('product_teaser', instance.id)\n\n post_save.connect(refresh_product_teaser, Product)\n\n\nViewlets can also be accesses with AJAX by adding ``viewlet.urls`` to your Django root urls:\n\n.. code-block:: python\n\n urlpatterns = patterns('',\n (r'^viewlet/', include('viewlet.urls')),\n )\n\n\nThe url ends with the viewlet name followed by a querystring used as ``kwargs`` to the viewlet:\n\n..\n\n http://localhost:8000/viewlet/[name]/?arg=1...\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/5monkeys/django-viewlet/tarball/1.5.1", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/5monkeys/django-viewlet", "keywords": "django", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-viewlet", "package_url": "https://pypi.org/project/django-viewlet/", "platform": "any", "project_url": "https://pypi.org/project/django-viewlet/", "project_urls": { "Download": "https://github.com/5monkeys/django-viewlet/tarball/1.5.1", "Homepage": "http://github.com/5monkeys/django-viewlet" }, "release_url": "https://pypi.org/project/django-viewlet/1.5.1/", "requires_dist": null, "requires_python": "", "summary": "Render template parts with extended cache control.", "version": "1.5.1" }, "last_serial": 3379736, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "84678ff53757666cc224ab121570b604", "sha256": "51d49acee3aac9b6a69ddf040b95a6e7eddc0397e95434a64e717fea4411a961" }, "downloads": -1, "filename": "django-viewlet-1.0.1.tar.gz", "has_sig": false, "md5_digest": "84678ff53757666cc224ab121570b604", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9552, "upload_time": "2013-03-26T17:59:38", "url": "https://files.pythonhosted.org/packages/1e/cc/eac27b32ba7360718d87f7638e4eb84744ce61518a1fe665261d1f4d3cbd/django-viewlet-1.0.1.tar.gz" } ], "1.0c1": [ { "comment_text": "", "digests": { "md5": "9b120c92080a7f2696b8ef721502e532", "sha256": "39b28385f5584b98d8bf43e9d7eda39f7a8d1a66f20f142dd426fe175c0b7f3d" }, "downloads": -1, "filename": "django-viewlet-1.0c1.tar.gz", "has_sig": false, "md5_digest": "9b120c92080a7f2696b8ef721502e532", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7699, "upload_time": "2012-11-17T21:05:42", "url": "https://files.pythonhosted.org/packages/88/ed/a434ea13aff353b37ce4de723f453d303bd2fa42878ae766cf57317326af/django-viewlet-1.0c1.tar.gz" }, { "comment_text": "", "digests": { "md5": "8cd6a3aaab262127f5cbdd416b719cc5", "sha256": "be74e0c9742cd1b276f48bb5b1ccc6ee8d3674786f353aa7b79bb56263d686b6" }, "downloads": -1, "filename": "django-viewlet-1.0c1.zip", "has_sig": false, "md5_digest": "8cd6a3aaab262127f5cbdd416b719cc5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15415, "upload_time": "2012-11-17T21:05:44", "url": "https://files.pythonhosted.org/packages/49/66/22440b3f572db9d0ea55e44de4d52ff5072de0e486391281a693551355e6/django-viewlet-1.0c1.zip" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "305279c874b9236b62f0704fec9e077d", "sha256": "0cf4cc57ee0943a2f585166a73013b205ca123ddb5b3549d7a06c7908b1ef4fd" }, "downloads": -1, "filename": "django-viewlet-1.1.tar.gz", "has_sig": false, "md5_digest": "305279c874b9236b62f0704fec9e077d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10883, "upload_time": "2013-05-17T17:46:42", "url": "https://files.pythonhosted.org/packages/65/b1/561fe1852d7664f8643a0427556f5a8c2520ec846351f457be84d09db454/django-viewlet-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "0521997d6b0ceb269835736915d13892", "sha256": "25fc220592fec7c9281c90acfe1fe5e748137c70d5a0bcc4c48bfb2e65a78db3" }, "downloads": -1, "filename": "django-viewlet-1.2.tar.gz", "has_sig": false, "md5_digest": "0521997d6b0ceb269835736915d13892", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11117, "upload_time": "2013-05-21T14:51:54", "url": "https://files.pythonhosted.org/packages/8b/8e/7b658d39ec6a5e4cff1065332d5cbba168e11b1e725000981968adbc3f42/django-viewlet-1.2.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "1fad91ca510077f1f49e75caaeaf1c5f", "sha256": "6b58ff58db9eafc4698b18c18e4f7fe87178c9dec53325338bf496b20485b917" }, "downloads": -1, "filename": "django-viewlet-1.2.1.tar.gz", "has_sig": false, "md5_digest": "1fad91ca510077f1f49e75caaeaf1c5f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11173, "upload_time": "2013-05-27T11:11:16", "url": "https://files.pythonhosted.org/packages/68/44/7a0877d77c88866b7cdfcf88cd6b7cae1af971809d762441cb374c95b6ca/django-viewlet-1.2.1.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "b2967b557bdc08ae0cdf1c155f090d91", "sha256": "6bdb467e524e9766d7327cad548c3dbe2df204ba467375e9aabd683e44953879" }, "downloads": -1, "filename": "django-viewlet-1.3.tar.gz", "has_sig": false, "md5_digest": "b2967b557bdc08ae0cdf1c155f090d91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11409, "upload_time": "2013-08-22T09:44:33", "url": "https://files.pythonhosted.org/packages/6c/7e/cd1e2e411c1a7e417cd81c985537882dabb6670b94aebea63403650f58be/django-viewlet-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "a988a988eaaedf0d1545d51a61a54b8c", "sha256": "1cf84792ffde41dc68d123aa8dbdfd31e87a28ec9a6787fe600d76c63364cd8c" }, "downloads": -1, "filename": "django-viewlet-1.4.tar.gz", "has_sig": false, "md5_digest": "a988a988eaaedf0d1545d51a61a54b8c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12609, "upload_time": "2014-09-26T15:28:39", "url": "https://files.pythonhosted.org/packages/68/89/c7bedbc103261b9357c51262155d3b73c63194689ac6c74d2366a029352a/django-viewlet-1.4.tar.gz" } ], "1.5": [ { "comment_text": "", "digests": { "md5": "ff34b99d86e09f25926ee1b7cdad7eb0", "sha256": "a85ad62c859b2de25402617395992459f35ba1bb72560c873cf813e17a41776d" }, "downloads": -1, "filename": "django-viewlet-1.5.tar.gz", "has_sig": false, "md5_digest": "ff34b99d86e09f25926ee1b7cdad7eb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13207, "upload_time": "2017-11-09T11:45:04", "url": "https://files.pythonhosted.org/packages/0c/f3/01f7263a904f3a9d7c7fe4ae65f7fe289853654d838bf15f2317d1a6d1fe/django-viewlet-1.5.tar.gz" } ], "1.5.1": [ { "comment_text": "", "digests": { "md5": "9174558330883589299c43c289c9c1df", "sha256": "eabd039df2b1f079f9004d49afff77d4effecdb8473443b6c45e934607e85afb" }, "downloads": -1, "filename": "django-viewlet-1.5.1.tar.gz", "has_sig": false, "md5_digest": "9174558330883589299c43c289c9c1df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14001, "upload_time": "2017-12-01T09:54:53", "url": "https://files.pythonhosted.org/packages/2b/50/55e95faf14de5f6ab4b4c9e14201ef5ee63b9db61f9b0210f6f97bec13e2/django-viewlet-1.5.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9174558330883589299c43c289c9c1df", "sha256": "eabd039df2b1f079f9004d49afff77d4effecdb8473443b6c45e934607e85afb" }, "downloads": -1, "filename": "django-viewlet-1.5.1.tar.gz", "has_sig": false, "md5_digest": "9174558330883589299c43c289c9c1df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14001, "upload_time": "2017-12-01T09:54:53", "url": "https://files.pythonhosted.org/packages/2b/50/55e95faf14de5f6ab4b4c9e14201ef5ee63b9db61f9b0210f6f97bec13e2/django-viewlet-1.5.1.tar.gz" } ] }