{ "info": { "author": "Philipp Bosch", "author_email": "hello@pb.io", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "django-sirtrevor\n================\n\n**django-sirtrevor** is a simple Django app that provides a content editing\nwidget based on the fantastic `Sir Trevor`_ project.\n\n\nQuick start\n-----------\n\n1. Install django-sirtrevor::\n\n pip install django-sirtrevor\n\n2. Add ``sirtrevor`` to your INSTALLED_APPS setting like this::\n\n INSTALLED_APPS = (\n ...\n 'sirtrevor',\n )\n\n3. Add sir trevor urls::\n\n url(r'^sirtrevor/', include('sirtrevor.urls')),\n\n4. Create a model that makes use of ``SirTrevorField``::\n\n from django.db import models\n from sirtrevor.fields import SirTrevorField\n\n class MyModel(models.Model):\n ...\n content = SirTrevorField()\n ...\n\n5. Now you can \u2026\n\n - see it in action in the Django admin\n - create a ``ModelForm`` from your model\n - create a plain ``Form`` and use ``sirtrevor.forms.SirTrevorFormField``\n - use ``sirtrevor.widgets.SirTrevorWidget`` as a widget replacement for a\n ``Textarea``\n\n\nConfiguration\n-------------\n\n`Sir Trevor`_ has a few `configuration options`_. You can customize most of\nthem project-wide in your ``settings.py`` or some on a per-widget basis as\n``kwargs`` for ``SirTrevorWidget``.\n\n\n**Available options** (``CONFIGURATION_SETTINGS`` / ``widget_kwargs``):\n\n\n``SIRTREVOR_BLOCK_TYPES`` / ``st_block_types``\n A list of block types to use with the editor.\n Defaults to ``['Text', 'List', 'Quote', 'Image', 'Video', 'Tweet', 'Heading']``\n\n``SIRTREVOR_DEFAULT_TYPE`` / ``st_default_type``\n The default block to start the editor with.\n Defaults to ``None``\n\n``SIRTREVOR_BLOCK_LIMIT`` / ``st_block_limit``\n The overall total number of blocks that can be displayed.\n Defaults to ``0``\n\n``SIRTREVOR_BLOCK_TYPE_LIMITS`` / ``st_block_type_limits``\n Limit on the number of blocks that can be displayed by its type.\n Defaults to ``{}``\n\n``SIRTREVOR_REQUIRED`` / ``st_required``\n Mandatory block types that are required for validatation.\n Defaults to ``None``\n\n``SIRTREVOR_UPLOAD_URL`` / ``st_upload_url``\n URL for AJAX image uploads.\n Defaults to ``/sirtrevor/attachments/`` (depending on where you include\n django-sirtrevor's URLs in ``urls.py``)\n\n``SIRTREVOR_UPLOAD_PATH``\n Path where to store uploaded images relative to ``MEDIA_ROOT``. (not\n configurable via widget kwargs)\n Defaults to ``attachments``\n\n``SIRTREVOR_ATTACHMENT_PROCESSOR``\n A string containing a dotted path to a function that will be run before\n saving an uploaded image. See `below`_ for more details. (not configurable via\n widget kwargs)\n Defaults to ``None``\n\n\nResizing Images\n---------------\n\nYou can resize uploaded images by implementing a function somewhere in your\ncode and pointing ``SIRTREVOR_ATTACHMENT_PROCESSOR`` to its location. The first\nargument will be the file object and the method must return a\n``SimpleUploadFile`` object.\n\nExample implemented in ``utils.py`` in an app called ``core``.\n``SIRTREVOR_ATTACHMENT_PROCESSOR`` set to ``core.utils.resize_attachment``::\n\n from PIL import Image\n from StringIO import StringIO\n from django.core.files.uploadedfile import SimpleUploadedFile\n\n\n def resize_attachment(file_):\n size = (1024, 9999)\n try:\n temp = StringIO()\n image = Image.open(file_)\n image.thumbnail(size, Image.ANTIALIAS)\n image.save(temp, 'jpeg')\n temp.seek(0)\n return SimpleUploadedFile(file_.name, temp.read(), content_type='image/jpeg')\n except Exception as ex:\n return file_\n\n\nCustom Blocks\n-------------\n\n*Sir Trevor* can be extended through `custom blocks`_. Starting with 0.2.1\n*django-sirtrevor* also has basic support for custom blocks.\n\nHere is a little step-by-step guide:\n\n**myapp/blocks.py**::\n\n from sirtrevor.blocks import BaseBlock\n\n class MyCustomBlock(BaseBlock):\n name = 'MyCustomName'\n\n class Media:\n js = ['sirtrevor/blocks/mycustomblock.js']\n\n\n**myapp/models.py**::\n\n import sirtrevor\n from .blocks import MyCustomBlock\n\n sirtrevor.register_block(MyCustomBlock)\n\n\n**myapp/static/sirtrevor/blocks/mycustomblock.js**::\n\n SirTrevor.Blocks.MyCustomName = SirTrevor.Block.extend({\n type: 'mycustomblock',\n // ...\n });\n\nPlease refer to *Sir Trevor*'s docs regarding `custom blocks`_ for details\nabout the JavaScript part of a custom block.\n\n\n**myapp/templates/sirtrevor/blocks/mycustomblock.html**::\n\n