1. Igor Katson
  2. django-aloha

Overview

HTTPS SSH

django-aloha

What is django-aloha

django-aloha is a django app to easily integrate editing with Aloha WYSIWIG editor in django apps.

You just edit the blocks of text on your pages, no admin needed.

How it works

django-aloha wraps editable text fields into separate forms. See how to do it in the "Usage" section.

Installation

  1. download aloha-editor from GitHub https://github.com/alohaeditor/Aloha-Editor

    my version was commit 787859e2313337f171f32b7574cec23393fa6a77

  2. For existing JS and CSS to work (this is optional, you can create your own ones) place the aloha files into your {{MEDIA_URL}}js/aloha/, so that the "lib" directory is in {{MEDIA_URL}}js/aloha/lib/.

  3. Install django-aloha into your python:

    easy_install django-aloha
    
  4. Add "django-aloha" to INSTALLED_APPS in settings.py

  5. Make sure you have jquery enabled.

  6. (Optional) add existing JS and CSS to your templates, where you usually place JS and CSS:

    {% include 'aloha/includes/js.html' %}
    {% include 'aloha/includes/css.html' %}
    

    Or you can just copy these files into your TEMPLATES dir, and edit according to your needs.

Usage

Use in your templates like this.

  1. Option one - you want to edit a certain field on a model instance:

    {% load aloha_tags %}
    
    {% aloha my_object_from_the_database 'fieldname_where_text_is' [url_to_save] %}
       {{ my_object_from_the_database.fieldname_where_text_is|safe }}
    {% endaloha %}
    

    If you want, you can add an optional "url" parameter to do custom POST processing. If not provided, aloha.views.save will be used.

  2. Option two - you want to edit arbitrary text, and optionally, provide and url to save it:

    {% load aloha_tags %}
    
    {% aloha [url_to_save_to] %}
       <p>Place here what you want to edit</p>
    {% endaloha %}
    

The custom save URL should process POST requests, and accepts following parameters:

  • object_name
  • field_name
  • object_pk
  • content

All of these are generated by the tag, no need to worry about them.

TODO

  • Add more strict permission processing (not it just uses request.user.is_staff to check for permissions)
  • Process thourgh AJAX instead of raw POSTS (to protect data loss on errors)