{ "info": { "author": "Tim Heap", "author_email": "tim@timheap.me", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "django-template-media\n=======================\n\nThis module allows template writers to manipulate form media in templates.\nThis allows multiple forms on a page to share scripts with out including them twice.\n\nAll of the media included in the page using these tools\nare collected into a single 'global'[1]_ ``Media`` instance for that page.\nAll operations are performed on this 'global'[1]_ ``Media`` instance.\n\nInstalling\n==========\n\nInstall this package, using pip::\n\n $ pip install django-template-media\n\nAdd it to your ``INSTALLED_APPS`` and ``TEMPLATE_CONTEXT_PROCESSORS``::\n\n INSTALLED_APPS += (\n 'django_template_media',\n )\n\n TEMPLATE_CONTEXT_PROCESSORS += (\n 'django_template_media.context_processors.template_media',\n )\n\nLoad the template tags in your templates by loading the ``media_tags`` library::\n\n {% load media_tags %}\n\nUsing\n=====\n\nThe tools are designed to work with the template heirarchy in a sane manner.\nThe examples will assume a ``site.html`` base template that defines a block named ``media``,\nand two ``{% print_media %}`` tags to print the accumulated media files::\n\n \n \n \n Example site\n\n {# Define the media for the page. This block is not printed #}\n {% load media_tags %}\n {% block media %}{% media %}\n {% add_css \"screen\" \"css/bootstrap.css\" %}\n {% add_css \"screen\" \"css/site.css\" %}\n {% add_css \"print\" \"css/print.css\" %}\n\n {% add_js \"js/jquery.js\" %}\n {% media %}{% endblock %}\n\n {# print out CSS media in the #}\n {% print_media \"css\" %}\n\n \n \n\n {% block body %}\n\n {# print out JS media at the end of the #}\n {% print_media \"js\" %}\n\n \n \n\nThe ``media`` block is used by child templates to add media to the site media.\nThe block does not have to be named ``media``,\nit just has to be named the same thing on all templates.\nThe block must appear *before* any calls to ``{% print_media %}``\n\nPrinting the media\n------------------\n\nThe ``{% print_media %}`` tag prints all of the media accumulated on the page so far.\nA sensible place to put this is in your base template.\n\nCalling this tag with no arguments will print out all of the accumulated media.\n\nYou can print out just the ``css`` or ``js`` by supplying a second argument::\n\n {% print_media \"css\" %}\n\n {% print_media \"js\" %}\n\nBuilding media in the template\n------------------------------\n\nIf you want to construct an ad-hoc media instance,\nfor site-wide media or fancy pages,\nyou can use the ``{% media %}`` block.\nThe ``Media()`` instance generated will be added to the current page media.\nJust as in ``Media`` classes on forms, the same file can be named multiple times \u2014\nonly the first instance will be used.\nYou can safely name all dependencies of the current page,\nwithout worrying about including the dependency multiple times::\n\n {% extends \"site.html\" %}\n\n {% load media_tags %}\n {% block media %}\n {% media %}\n\n {% add_js \"js/jquery.js\" %}\n {% add_js \"js/jquery.lib.js\" %}\n {% add_js \"js/bootstrap.js\" %}\n {% add_js \"js/bootstrap.lib.js\" %}\n\n {% add_css \"screen\" \"css/bootstrap.css\" %}\n {% add_css \"screen\" \"css/widget.css\" %}\n\n {% if user.is_anonymous %}\n {% add_media login_form.media %}\n {% endif %}\n\n {% endmedia %}\n\n {# This is called **after** adding all the media #}\n {{ block.super }}\n {% endblock %}\n\nThe three possible tags in the ``{% media %}`` block are as follows:\n\n``{% add_js path %}``\n Add the JavaScript file ``path`` to the media.\n Multiple files can be specified in the one tag,\n or just place them one after another as a series of tags.\n\n``{% add_css media_type path %}``\n Add the CSS file ``path`` to the media, with ``media_type``.\n Multiple files can be specified in the one tag,\n or just place them one after another as a series of tags.\n\n``{% add_media media %}``\n Adds the named form media to the current media.\n Multiple media instances can be added at once by naming them all.\n or just place them one after another as a series of tags.\n\nAdding media from forms\n-----------------------\n\nIf you just want to add a single JavaScript file or CSS file,\nor a single form media instance,\nyou do not need to wrap everything in a ``{% media %}`` block::\n\n {% extends 'site.html' %}\n\n {% load media_tags %}\n\n {% block body %}\n
\n {% csrf_token %}\n {{ form }}\n \n
\n {% endblock %}\n\n {% block media %}\n {% add_media form.media %}\n {{ block.super }}\n {% endblock %}\n\nThe ``{% add_media %}`` tag accepts multiple media instances,\nso if you have multiple forms, you can add the media for all of them at once::\n\n {% add_media form_1.media form_2.media %}\n\nWorking with template hierarchies\n---------------------------------\n\nIn sub-templates, the call to ``{{ block.super }}``\n*must* be placed *after* all calls that modify the media.\nAs the media is printed out in an ancestor's ``{% block media %}``,\nthe sub-template must add all of the media it needs\nbefore calling ``{{ block.super }}``.\n\n``{% add_js %}``, ``{% add_css %}`` and ``{% add_media %}`` tags outside of\n``{% media %}`` blocks always *prepend* new media to the current page media.\nThis is because templates are rendered from the child to the parent,\nand parent media should precede child media.\nThus, if you have multiple ``{% add_media %}`` or ``{% media %}`` tags in once page,\nthe media will be printed out in reverse order to its appearance on the page.\nAs such, you are encouraged to have only one\n``{% add_media %}`` or ``{% media %}`` block per template,\nto prevent confusion.\n\nIn a ``{% media %}`` block, calls to ``{% add_media %}``, ``{% add_js %}`` and\n``{% add_css %}`` append media to the current ad-hoc media instance.\n\n------------------------\n\n.. [1]\n The 'global' ``Media`` instance is stored in the currently rendering template context.\n It is only global to the whole page that is currently being constructed,\n not across all templates.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/tim_heap/django-template-media", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-template-media", "package_url": "https://pypi.org/project/django-template-media/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-template-media/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/tim_heap/django-template-media" }, "release_url": "https://pypi.org/project/django-template-media/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "Simple tools to extend the django admin site", "version": "0.3.0" }, "last_serial": 1240417, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "e5adbd20446be741d91b1ebd76fa2360", "sha256": "c100217dd1ba66954411ec0be70bb26322f67d9833c1e7c276ace19bd8cef40d" }, "downloads": -1, "filename": "django-template-media-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e5adbd20446be741d91b1ebd76fa2360", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4481, "upload_time": "2013-07-24T00:32:56", "url": "https://files.pythonhosted.org/packages/ab/45/32c5a52725299f11a746f0ab2a6d55b034e6b6240af4a6dae01434aeb86d/django-template-media-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "998a12a236da8999b42a52b155f49609", "sha256": "bc87c8605067022f4ee68a614eb791ec8b6ebca04bdcc2290f1b0f3ecab53fb0" }, "downloads": -1, "filename": "django-template-media-0.2.0.tar.gz", "has_sig": false, "md5_digest": "998a12a236da8999b42a52b155f49609", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5156, "upload_time": "2013-09-30T02:37:28", "url": "https://files.pythonhosted.org/packages/e0/a4/d8b57e4f562f38035bc704d5f5f504e83598cd6e6ea6067ed6d343d68666/django-template-media-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "97b2669e3fd1ec4fc5ba1366e695873f", "sha256": "d15359e031787fb7cfb82060756d6f0b39960699427d573dbd25c1bfd21eb5f1" }, "downloads": -1, "filename": "django-template-media-0.3.0.tar.gz", "has_sig": false, "md5_digest": "97b2669e3fd1ec4fc5ba1366e695873f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5053, "upload_time": "2014-09-28T01:25:54", "url": "https://files.pythonhosted.org/packages/9d/a9/d40874a8fadaef2aa9e9e8887f5102acc656b54f2d59e3d11e270a301fc8/django-template-media-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "97b2669e3fd1ec4fc5ba1366e695873f", "sha256": "d15359e031787fb7cfb82060756d6f0b39960699427d573dbd25c1bfd21eb5f1" }, "downloads": -1, "filename": "django-template-media-0.3.0.tar.gz", "has_sig": false, "md5_digest": "97b2669e3fd1ec4fc5ba1366e695873f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5053, "upload_time": "2014-09-28T01:25:54", "url": "https://files.pythonhosted.org/packages/9d/a9/d40874a8fadaef2aa9e9e8887f5102acc656b54f2d59e3d11e270a301fc8/django-template-media-0.3.0.tar.gz" } ] }