django-mirror
This package marries Django with CodeMirror. It provides (1) a customisable form widget, and (2) a shorthand way to use this widget in the admin. In both cases the relevant static files (including mode/theme/addon files) are automatically included as form assets.
installation
This is a Python 3 package with no other dependencies apart from Django and it is offered at the Cheese Shop:
# usually inside a virtual environment
pip install django-mirror
The CodeMirror files (version 5.63.3) are included in the package. The supported Django versions are 2.2, 3.0, 3.1, and 3.2.
settings
# add 'django_mirror' to your INSTALLED_APPS if you want the package to be
# handled by Django's collectstatic command
INSTALLED_APPS += ['django_mirror']
# use DJANGO_MIRROR_DEFAULTS to specify default options for your widgets
# see the next section for more info about the options
DJANGO_MIRROR_DEFAULTS = {
'mode': 'rst',
'addons': ['mode/overlay'],
'line_wrapping': True,
}
widget
Bascially this package provides a form widget called MirrorArea that extends Django’s Textarea widget.
from django import forms
from django_mirror.widgets import MirrorArea
class CommentForm(forms.Form):
text = forms.CharField(
widget=MirrorArea(
attrs={'rows': 20}, # the parent class' attrs still works
mode='markdown', # the other kwargs are forwarded to CodeMirror
)
)
The MirrorArea widget can be initialised with the following arguments:
Any of CodeMirror’s config options. These can be specified in either camelCase or snake_case (e.g. both tabSize and tab_size would work). The css/js files associated with the mode, if provided, are included as form assets.
addons, a list of CodeMirror addons, e.g. dialog/dialog. The css/js files associated with the addons are recursively included as form assets.
attrs, just as Django’s form widgets.
The addons and config options are merged with and override DJANGO_MIRROR_DEFAULTS if the setting has been defined.
admin
If you want to use the widget in the admin panel, you can subclass the MirrorAdmin mixin, which provides the mirror_fields model admin option:
from django.contrib import admin
from django_mirror.admin import MirrorAdmin
from weblog.models import Comment
@admin.register(Comment)
class CommentAdmin(MirrorAdmin, admin.ModelAdmin):
mirror_fields = ('comment',) # default options
mirror_fields = ( # with custom options
('comment', {
'mode': 'markdown',
'line_wrapping': True,
}),
)
The mixin also includes a bit of css to make CodeMirror look more like regular admin textarea fields.
similar projects
There are several other packages that provide customisable CodeMirror widgets:
licence
GNU LGPLv3. Please refer to COPYING for the base GPLv3 licence and to COPYING.LESSER for the additional permissions on top that constitute LGPLv3.
Metadata
Release files for django-mirror 0.1.13
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-mirror-0.1.13.tar.gz | 607.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_mirror-0.1.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.4 MB
Release files / django-mirror-0.1.13.tar.gz
| Download URL | django-mirror-0.1.13.tar.gz |
|---|---|
| Size | 607.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd72333c7b5e4223601b66b3a44a34588fc9bb349e8ce09548d42aa3affe1454
|
|
BLAKE2b-256 checksum How to use checksums |
91fc6b91b46fb59e58f96dc78e242194095d7443e1401c9974bd36032d09921a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / django_mirror-0.1.13-py3-none-any.whl
| Download URL | django_mirror-0.1.13-py3-none-any.whl |
|---|---|
| Size | 773.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
014d49976326b3b3c2ef1804891ad52899c73a6fdcfc46e1296d24ea9b9ae6c8
|
|
BLAKE2b-256 checksum How to use checksums |
b1bf79cfc8addae7bb9b48fbe5717d207152c63822282e16b2b5f01172ec9da2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Security for django-mirror 0.1.13
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.