django-embedded-media
- Author:
- Version:
0.1.0
- License:
Ever run into a situation where it would just be so incredibly handy to be able to render inline CSS or JS in your Django form media?
This lets you do that.
It all started with ticket #13978, which I championed for a while. However, I no longer think this is a good feature to have in Django. After using the #13978 patch for a while, I’ve come to realize that it’s just too damn easy to rely on it too much. No one wants to see a two-dozen line string of jQueryfied JS in the middle of their Django form class.
However, if you’ve got the need for spee^H^H^H^Hembedded media – and you think you’re disciplined enough to not start writing all your CSS and JS as strings in your .py files – then django-embedded-media makes it possible.
Installation
Use pip, obviously:
$ pip install django-embedded-media
Usage
There’s no special configuration needed. It’s a Django app, technically, but you don’t need to put it into INSTALLED_APPS. Just install the package and start embedding your styles and scripts.
Works on forms:
>>> from django import forms
>>> import embedded_media as emb
>>>
>>> class MyForm(forms.Form):
... class Media:
... css = {'all': (emb.CSS('.mywidget { display: none; }'),)}
... js = (emb.JS('init_mywidget();'),)
>>> print MyForm.media
<style type="text/css" media="all">.mywidget { display: none; }</style>
<script type="text/javascript">init_mywidget();</script>
>>>
Works on form widgets:
>>> from django import forms
>>> import embedded_media as emb
>>>
>>> class MyWidget(forms.TextInput):
... class Media:
... css = {'all': (emb.CSS('.mywidget { display: none; }'),)}
... js = (
... 'whizbang.js',
... emb.JS('init_mywidget();'),
... )
>>> print MyWidget().media
<style type="text/css" media="all" >.mywidget { display: none; }</style>
<script type="text/javascript" src="/static/whizbang.js"></script>
<script type="text/javascript">init_mywidget();</script>
>>>
Works as a dynamic media property:
>>> from django import forms
>>> import embedded_media as emb
>>>
>>> class MyForm(forms.Form):
... def _media(self):
... return Media(
... css={'all': (emb.CSS('.mywidget { display: none; }'),)},
... js=(emb.JS('init_mywidget();'),)
... )
... media = property(_media)
>>> print MyForm().media
<style type="text/css" media="all">.mywidget { display: none; }</style>
<script type="text/javascript">init_mywidget();</script>
>>>
Testing
The tests require Django, coverage, and pep8, which are conveniently listed in requirements.txt:
$ pip install -r requirements.txt $ python setup.py test
Metadata
Release files for django-embedded-media 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-embedded-media-0.1.0.tar.gz | 4.9 kB | Without provenance | Details |
Release files / django-embedded-media-0.1.0.tar.gz
| Download URL | django-embedded-media-0.1.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
299fcd173dae5e87f6cd7e94c3b8de4ada4e2beafe45783513b69281211f0eb5
|
|
BLAKE2b-256 checksum How to use checksums |
3a1a4c2899c91d5c7497e0e0d2f4d998ae10d5f031074970b47ec776070a4e70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-embedded-media 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.