This package marries Django with CodeMirror
Project description
This package marries Django with CodeMirror.
usage
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
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 forms.Textarea.
from django import forms
from django_mirror.widgets import MirrorTextarea
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:
attrs, as the other Django form widgets.
addons, a list of CodeMirror addons to include as form assets.
Any of CodeMirror’s config options, in both camelCase and snake_case.
The addons and config options are merged with 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',
})
)
similar projects
There are at least two other packages that would offer alternative takes on adding CodeMirror to Django:
licence
GPL. You can do what you want with this code as long as you let others do the same.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_mirror-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0984b4968ad254f0af384d663dd3a30e6d641a24b3dec080186f2b79cc0e6c44 |
|
MD5 | e95e5ada6c7d61144c05a97a1de125d2 |
|
BLAKE2b-256 | 9f786edaf5f88486f655fe932c0b0e9bbeb138ccfb499865f4ae16c408ca8bba |