Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

CMSPlugin Redactor

This is a Django-CMS plugin providing Django-RedactorMedia and thus Django-Redactor to the CMS. Django-Redactor itself is a Django app providing the Redactor Javascript WYSIWYG-editor in Django. Please note: While this software is licensed under MIT the Redactor Javascript editor and Django-Redactor are not. See the Django-Redactor license.

Installation

For now you have to install from the Bitbucket repository. One requirement is Django-Redactor. Install as they suggest. Currently there is no PyPi package for it.

Installing manual from Bitbucket

To install from the source do:

$ hg clone http://code.alien8.de/django-redactormedia
$ cd django-redactormedia

Install the module:

$ python setup.py install

Or:

$ pip install .

Or copy the redactormedia sub dir to your Python path or Django project root dir:

$ cp django-redactormedia/redactormedia $PYTHONPATH

Now, add the redactormedia application to your INSTALLED_APPS setting.

Usage

The redactormedia app provides a Django widget called RedactorWithMediaEditor. It is a drop-in replacement for any TextArea widget. Example usage:

from django import forms
from django.db import models

from redactormedia.widgets import RedactorWithMediaEditor

class MyForm(forms.Form):
    about_me = forms.TextField(widget=RedactorWithMediaEditor())

You can also customize any of the Redactor editor's settings when instantiating the widget:

class MyForm(forms.Form):

    about_me = forms.TextField(widget=RedactorWithMediaEditor(redactor_settings={
        'autoformat': True,
        'overlay': False,
        'imageUpload': reverse('upload_files'),
        'imageGetJson': reverse('recent_files'),
    }))

Django-redactormedia also includes a widget with some some customizations that make it function and look better in the Django admin:

class MyAdmin(admin.ModelAdmin):
    formfield_overrides = {
            models.TextField: {'widget': AdminRedactorWithMediaEditor},
    }

Finally, you can connect a custom CSS file to the editable area of the editor:

class MyForm(forms.Form):
    about_me = forms.CharField(widget=RedactorWithMediaEditor(
        redactor_css="styles/text.css")
    )

Paths used to specify CSS can be either relative or absolute. If a path starts with '/', 'http://' or 'https://', it will be interpreted as an absolute path, and left as-is. All other paths will be prepended with the value of the STATIC_URL setting (or MEDIA_URL if static is not defined).

Templating

If you are using a redactor widget outside the admin, you'll need to be sure that you render the form's media. Redactor widgets need to include some CSS and JavaScript to work properly:

<form>
    {{ myform.media }}
    {{ myform.as_p }}
    <input type="submit"/>
</form>

Acknowledgment

This code is heavily based on this Blog article by Patrick Altman and its comments. Thanks guys.

License

Django-Redactormedia is licensed under the MIT License. Please note the dependency Django-Redactor license.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.