Skip to content

richardcornish/django-emobar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emo

Emo is a Django app and template filter that enhances the admin's textareas with a Markdown-emoji enhanced toolbar.

Emo toolbar screenshot

Features

Emo uses the markItUp toolbar for adding Markdown to textareas. Its toolbar is themed to complement the minimalism of the admin.

The toolbar's emoji icons use the Apple iOS emoji icon set. Although emoji became a Unicode standard, some browsers (ahem, Chrome) still do not support the emoji HTML entities. Emo instead uses the GitHub-flavored Markdown codes and a filter to replace the emoji text codes with their respective image equivalents.

Installation

Install it with the pip package manager.

pip install -e git+https://github.com/richardcornish/django-emo.git#egg=django-emo

Remember to update to your requirements.txt file. In your project directory:

pip freeze > requirements.txt

Edit your settings.py:

INSTALLED_APPS = (
    # ...
    'emo',
)

Append class Media parts to admin classes in each of your apps' admin.py. Example:

from django.contrib import admin
from .models import Post

class PostAdmin(admin.ModelAdmin):

    # ...

    class Media:
        css = {
            'all': ('emo/css/style.min.css',)
        }
        js = ('emo/js/alias.min.js', 'emo/js/markitup.min.js', 'emo/js/emo.min.js',)

admin.site.register(Post, PostAdmin)

Override the admin's change_form.html template for the app of your choosing.

<!-- blog/templates/admin/blog/post/change_form.html -->

{% extends "admin/change_form.html" %}

{% block extrahead %}
    {{ block.super }}
    <script>
        django.jQuery(function () {
            'use strict';
            Emo.addToolbar('#id_body'); // Selector of desired textarea
        });
    </script>
{% endblock %}

More at:

Remember to add static file handling to your local settings or run python manage.py collectstatic in the correct django project directory live and restart the server as necessary.

Usage

Load the template tag in your template. Run it on an attribute of a variable:

{% load emo_tags %}

{{ post.body|emo }}

Note that the django.contrib.markup module has been deprecated since Django 1.5 and that a textarea using Markdown will not render HTML. Assuming you either bring back the module or you install a third-party Markdown solution, and add the package to your INSTALLED_APPS, the template would probably more closely resemble:

{% load markup emo_tags %}

{{ post.body|markdown|emo }}

If you do copy the old markup.py module, please alter the last section of the source by including the security update.

About

A Django emoji toolbar for the admin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published