Skip to main content

Intuitive text editing for humans using Django.

Project description

Join the chat at https://gitter.im/antonagestam/django-text Get downloads at https://pypi.python.org/pypi/django-text See latest build status at https://circleci.com/gh/antonagestam/django-text/tree/master Coverage

Intuitive text editing for humans using Django.

The django-text toolbar

This project is in early development, please test it out and report any bugs!

Installation

Install the package with pip.

$ pip install django-text

Add text to your installed packages.

# settings.py

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

Add text.middleware.TextMiddleware and 'text.middleware.ToolbarMiddleware' to your middleware classes.

# settings.py

MIDDLEWARE_CLASSES = (
    # ...
    'text.middleware.TextMiddleware',
    'text.middleware.ToolbarMiddleware',
)

Make sure these context processors are installed, they come with Django.

# settings.py

TEMPLATE_CONTEXT_PROCESSORS = (
    # ...
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
)

Append text.urls to your urlpatterns in urls.py.

# urls.py

from django.conf.urls import patterns, include, url

from text.urls import urlpatterns as django_text_patterns


urlpatterns = patterns('',
    url(r'^django_text/', include(django_text_patterns, namespace='django_text')),
)

Run migrate.

$ python manage.py migrate

Usage

The text tag

Add editable tags to your templates.

{% load text %}

<h1>{% text "header" "My Header" %}</h1>

<div class="content">
    {% text "text_body" %}
</div>

The text tag takes a default text as the second argument. If no default text is passed, the name of the text node (i.e. the first argument) will be used if there is no corresponding text node in the database.

The blocktext tag

You can also use the blocktext tag that let’s you wrap content to use as the default text.

{% load text %}

<div class="content">
    <h1>
        {% blocktext "header" %}
            Read My Awesome Text
        {% endblocktext %}
    </h1>

    {% blocktext "content" %}
        Put your default text here!
    {% endblocktext %}
</div>

The blocktext tags works with translation tags inside of it. So if you already have a translated site, you can wrap your content with this tag and only add text nodes for some of the languages that you support.

Specifying content type

Both the text and the blocktext tags support specifying the content type of its default text. The choices are “html”, “markdown” and “text” which is the default.

{% text "html_node" "<h1>Hello World!</h1>" "html" %}

{% blocktext "markdown_node" "markdown" %}
# Hello there,

I can have markdown in my templates!
{% endblocktext %}

If content type is not provided both will default to text.

Disable instant updating

By default the templatetags will wrap all text nodes with a span element to enable “instant updating”, if TEXT_TOOLBAR_INSTANT_UPDATE is set to True. Sometimes this can cause trouble, for instance when you want to have editable texts inside <title> or <meta> elements.

You can disable instant updating on per-node basis by setting the templatetag keyword argument instant_update to False:

<title>{% text "title" "Welcome!" instant_update=False %}</title>

<title>
    {% blocktext "block_title" instant_update=False %}
    Welcome one, welcome all!
    {% endblocktext %}
</title>

Content editing

The toolbar allows you to edit texts directly on your pages if you’re signed in as staff and have the permission 'text.change_text' or if you’re signed is as a superuser.

Missing text nodes will be added to the database automatically when their template tags are rendered.

Settings

AUTOPOPULATE_TEXT

Default: True

Set to false to disable django-text from adding missing text nodes to the database.

TEXT_TOOLBAR_ENABLED

Default: True

Set to false to disable the toolbar interface.

TEXT_TOOLBAR_FORM_PREFIX

Default: 'djtext_form'

This is passed to the toolbar form and can be changed to avoid name conflicts.

TEXT_TOOLBAR_INSTANT_UPDATE

Default: True

Set to false to disable instant updating of the DOM when saving texts in the toolbar.

TEXT_INLINE_WRAPPER

Default: ('<span data-text-name="{0}" class="{1}">', '</span>')

A tuple of two that gets wrapped around texts in the template to enable instant updating.

TEXT_INLINE_WRAPPER_CLASS

Default: 'dj_text_inline_wrapper'

Change this to change the class of the element that gets wrapped around texts.

Contribution

Contribution is very welcome. Use issues to report bugs and propose features. For pull requests to be accepted they need to be well tested.

Running tests

Install test dependencies.

$ pip install -r test-requirements.txt

Run tests.

$ make test

Run tests with coverage.

$ make test-coverage

License

Copyright (c) 2015 Anton Agestam. django-text is released under the MIT license. See the LICENSE file for more information and licenses for bundled code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-text-1.7.5.tar.gz (57.1 kB view details)

Uploaded Source

Built Distribution

django_text-1.7.5-py2.py3-none-any.whl (71.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-text-1.7.5.tar.gz.

File metadata

  • Download URL: django-text-1.7.5.tar.gz
  • Upload date:
  • Size: 57.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-text-1.7.5.tar.gz
Algorithm Hash digest
SHA256 a4a5265a28e1e15fd34c58192e817a36ba17fee700130526a9fab50fb8cfaab5
MD5 c1fabb2ca4903c45d03d292afca2b2b3
BLAKE2b-256 be897a3b946f7a2f8940a967a7990378d2d2ca97dbe792bc18b15544842c108b

See more details on using hashes here.

Provenance

File details

Details for the file django_text-1.7.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_text-1.7.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1eecb150695829b0c5b77d95b68b8f6cf664c1e2ffba20efd08b619a43218e9
MD5 30a81fce10831636f8d78eafa7408fb6
BLAKE2b-256 5abcda27e371d07dbfe9daaa7dcc9f201e6276d321e5283cdf7ddcc64e70aa14

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page