{ "info": { "author": "David Danier", "author_email": "david.danier@team23.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.8", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5" ], "description": "django-textformat\n=================\n\n|pypi-badge| |build-status|\n\n.. |build-status| image:: https://travis-ci.org/team23/django_textformat.svg\n :target: https://travis-ci.org/team23/django_textformat\n\n.. |pypi-badge| image:: https://img.shields.io/pypi/v/django-textformat.svg\n :target: https://pypi.python.org/pypi/django-textformat\n\n**django-textformat** makes it easy to configure and compose text formats.\nA text format is simply a set of text filters that are applied in a defined\norder. A text filter is a function that takes a markup string and returns a the\nformatted string.\n\nBuilt in filters are:\n\n``html_escape``\n It's the same as Django's ``escape`` template filter, available as text\n filter.\n\n``linebreaks_and_paragraphs``\n It's the same as Django's ``linebreaks`` template filter, available as text\n filter.\n\n``linebreaks``\n It's the same as Django's ``linebreaksbr`` template filter, available as text\n filter.\n\n``striptags``\n It's the same as Django's ``striptags`` template filter, available as text\n filter.\n\n``urlize``\n It's the same as Django's ``urlize`` template filter, available as text\n filter.\n\ndjango-textformat does not provide any text formats by default, but to give you\nan idea, a text format might consist of the builtin filters ``html_escape``,\n``urlize``, ``linebreaks_and_paragraphs``.\n\nThat would allow you to group those filters into a format and use it\nconsistently throuhgout your project.\n\n\nUsage\n-----\n\nThe default use case for django-textformat might look like this in your model:\n\n.. code-block:: python\n\n from django.db import models\n from django_textformat import TextFormatField\n\n\n class Article(models.Model):\n title = models.CharField(max_length=50)\n content = models.TextField()\n content_format = TextFormatField()\n\n\nThen you can use the selected format for the article in your template like\nthis:\n\n.. code-block:: django\n\n {% load textformat %}\n\n {{ article.content|apply_format:article.content_format }}\n\n\nInitially creating text formats\n-------------------------------\n\nIn order to use a model like ``Article`` above, you already need to have a\n``django_textformat.models.TextFormat`` instance defined. You can either create\nthe format by hand or use a data migration. We suggest using a data migration\nwhich will make sure that all instances of your project (e.g. for all devs)\nhave the same formats available.\n\nTo do so, create an empty migration in one of your websites apps, like::\n\n python manage.py makemigrations blog --empty\n\nNow make the newly created migration look something like this:\n\n.. code-block:: python\n\n # -*- coding: utf-8 -*-\n from __future__ import unicode_literals\n\n from django.db import migrations, models\n\n\n def add_format(apps, schema_editor):\n TextFormat = apps.get_model('django_textformat', 'TextFormat')\n\n markdown_format = TextFormat.objects.create(\n slug='article',\n name='Article Format')\n markdown_format.filters.create(\n name='html_escape',\n sort=1)\n markdown_format.filters.create(\n name='urlize',\n sort=2)\n markdown_format.filters.create(\n name='linebreaks_and_paragraphs',\n sort=3)\n\n\n def remove_format(apps, schema_editor):\n TextFormat = apps.get_model('django_textformat', 'TextFormat')\n\n format = TextFormat.objects.get(slug='article')\n format.delete()\n\n\n class Migration(migrations.Migration):\n\n dependencies = [\n ('django_textformat', '0001_initial'),\n ]\n\n operations = [\n migrations.RunPython(\n add_format,\n remove_format,\n ),\n ]\n\n\nAdding custom text filters\n--------------------------\n\nIt's easy to add custom text filters. In order to add one, you need a\n``text_fitlers.py`` file in your app. Then add a function that takes a string\nand returns the formatted string.\n\nHere is an example:\n\n.. code-block:: python\n\n # in your_app/text_filters.py\n\n from django_textformat.registry import registry\n import markdown\n\n\n @registry.register\n def markdown(value):\n return markdown.markdown(value, extensions=['extra'])\n\nNow you have a text filter called ``'markdown'`` available for use in your text\nformats.\n\nDevelopment\n-----------\n\nInstall the dependencies (including the test dependencies) with::\n\n pip install -r requirements.txt\n\nThen you can run all tests with::\n\n tox\n\n\nChangelog\n=========\n\n0.1.0\n-----\n\n- Initial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/team23/django_textformat", "keywords": null, "license": "BSD licence, see LICENSE file", "maintainer": null, "maintainer_email": null, "name": "django-textformat", "package_url": "https://pypi.org/project/django-textformat/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-textformat/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/team23/django_textformat" }, "release_url": "https://pypi.org/project/django-textformat/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Provides a TextFormatField for Django models and allows to build text formats out of simple filters.", "version": "0.1.0" }, "last_serial": 4304477, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "adca83f2c53d6e3a65b9925cbb483b76", "sha256": "876899fda891622e7c1cf0e1a7889eee5d51a36dc8f65c8f5f3b4450d5f10e27" }, "downloads": -1, "filename": "django-textformat-0.1.0.tar.gz", "has_sig": false, "md5_digest": "adca83f2c53d6e3a65b9925cbb483b76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8014, "upload_time": "2016-04-05T08:21:24", "url": "https://files.pythonhosted.org/packages/37/a9/cd216308a67725f08a515b6df936b8fa0a8dd7b426df2e4b8fbf42f643a3/django-textformat-0.1.0.tar.gz" } ], "0.1.1.dev1": [] }, "urls": [ { "comment_text": "", "digests": { "md5": "adca83f2c53d6e3a65b9925cbb483b76", "sha256": "876899fda891622e7c1cf0e1a7889eee5d51a36dc8f65c8f5f3b4450d5f10e27" }, "downloads": -1, "filename": "django-textformat-0.1.0.tar.gz", "has_sig": false, "md5_digest": "adca83f2c53d6e3a65b9925cbb483b76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8014, "upload_time": "2016-04-05T08:21:24", "url": "https://files.pythonhosted.org/packages/37/a9/cd216308a67725f08a515b6df936b8fa0a8dd7b426df2e4b8fbf42f643a3/django-textformat-0.1.0.tar.gz" } ] }