Git Product home page Git Product logo

django_typograph's Introduction

Типограф для Django 1.7+

Установка

pip install django_typograph

В settings.py INSTALLED_APPS добавить

django_typograph

Использование

Импортировать

from django_typograph.fields import TypographyField

Добавить поле в модель

 _text = models.TextField()
text = TypographyField(source="_text")

Выполнить миграции

Пример модели

from django.db import models
from django_typograph.fields import TypographyField

class TestModel(models.Model):
    title = models.CharField(max_length=200, verbose_name='Название')
    _text = models.TextField()
    text = TypographyField(source='_text')

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = 'TestModel'    

Доступные настройки у поля TypographyField

  • source — Из какого поля брать исходный код для типографики
  • engine — Использовать другой движок для типографики именно у этого поля
  • options — настройки для указанного движка. Если движок не указан, то настройки всё равно будут применены к текущим

Настройка

Для тонкой настройки нужно переопределить AppCfg приложения

Создайте файл project_root/project_name/apps/django_typograph.py со следующим содержимым

    from django_typograph.apps import DjangoTypographConfig
    
    
    class CustomTypographConfig(DjangoTypographConfig):
        engines = {
            'EMT': {
                'path': 'django_typograph.engine.EMT.driver.typography',
                'options': {},
            },
            'EMT_SAFE': {
                'path': 'django_typograph.engine.EMT.driver.typography',
                'options': {
                    'OptAlign.all': 'off',
                    'OptAlign.oa_oquote': 'off',
                    'OptAlign.oa_obracket_coma': 'off',
                    'OptAlign.layout': 'off',
                    'Text.paragraphs': 'off',
                    'Text.auto_links': 'off',
                    'Text.breakline': 'off',
                    'Text.no_repeat_words': 'off',
                }
            }
        }
        default_engine = "EMT"

Старые записи

Присутствует management команда type_records. Вся ее суть в том, что она просто пересохраняет текущий контент моделей у которых прописано поле TypographyField.


А теперь рисуем сову собственно.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.