django-cms插件用于django-filer
项目描述
一组cms插件,用django-filer的文件字段版本替换了django-cms中提供的插件。
警告
Starting with version 1.1.0, support for Python 2.6, Django 1.7 or lower and django CMS 3.0.x and lower was dropped. Please pin your dependencies to ``cmsplugin-filer<1.1.0`` for older projects. Starting with version 0.10 support for django CMS 2.x was dropped (table renaming magic removal). Pin your dependencies to ``cmsplugin-filer<0.10`` for django-cms 2.x projects.
依赖关系
django-filer >= 1.2
Django >= 1.8
django-cms >= 3.1
django-sekizai >= 0.4.2
easy_thumbnails >= 1.0
django-appconf
djangocms-attributes-field
安装
要开始使用cmsplugin-filer
使用pip安装
$ pip install cmsplugin-filer
按照https://django-filer.readthedocs.io/en/latest/installation.html#configuration中的文档配置django-filer
将插件添加到INSTALLED_APPS
INSTALLED_APPS = ( ... 'cmsplugin_filer_file', 'cmsplugin_filer_folder', 'cmsplugin_filer_link', 'cmsplugin_filer_image', 'cmsplugin_filer_teaser', 'cmsplugin_filer_video', ... )
运行migrate。
您还可以在您的settings.py中设置FILER_IMAGE_USE_ICON,以配置cmsplugin_filer_image插件使用32x32图标来表示插件实例。
cmsplugin_filer_image 的默认模板期望启用主题位置功能。请参考:https://django-filer.readthedocs.io/en/latest/installation.html#subject-location-aware-cropping
升级到版本 1.1
版本 1.1 有两个不兼容的更改
迁移布局
迁移已移动到标准位置。为了使 cmsplugin_filer 1.1 正常工作,必须删除与 cmsplugin_filer 相关的 MIGRATION_MODULE 设置项
移除 ThumbnailOption 模型
ThumbnailOption 已移动到 filer(自 filer 1.2 起开始)。您必须更新引用 ThumbnailOption 的模型和迁移才能使其正常工作。
升级过程包括更新您的模型和迁移。
model.py
添加
try: from filer.models import ThumbnailOption thumbnail_model = 'filer.ThumbnailOption' except ImportError: from cmsplugin_filer_image.models import ThumbnailOption thumbnail_model = 'cmsplugin_filer_image.ThumbnailOption'
如果您使用字符串语法(例如: thumb_field = models.ForeignKey('cmsplugin_filer_image.ThumbnailOption')),请使用上面定义的 thumbnail_model 字符串(例如: thumb_field = models.ForeignKey(thumbnail_model)。如果直接使用模型,则不需要更改字段定义
Django 1.7+ 迁移
对于每个引用 ThumbnailOption 的迁移文件,请添加以下导入
from myapp.models import thumbnail_model
并将所有 'cmsplugin_filer_image.ThumbnailOption' 更改为 thumbnail_model
South 迁移
在每个迁移文件中添加以下导入
from myapp.models import thumbnail_model
并将所有 'cmsplugin_filer_image.ThumbnailOption' 更改为 thumbnail_model 和 u"orm['cmsplugin_filer_image.ThumbnailOption']" 更改为 u"orm['%s']" % thumbnail_model。
cmsplugin_filer_image 的默认模板期望启用主题位置功能。请参考:http://django-filer.readthedocs.org/en/0.9.2/installation.html#subject-location-aware-cropping
请注意,当前的开发版本已将插件包从 src 目录移动到项目根目录。在升级过程中可能会破坏您的安装。请卸载任何以前的 cmsplugin_filer 安装(无论是来自 PyPI 还是 github 存储库),然后重新安装。
集成
djangocms-text-ckeditor
cmsplugin_filer_image 提供了与 djangocms-text-ckeditor 的集成。添加此设置以启用它
TEXT_SAVE_IMAGE_FUNCTION='cmsplugin_filer_image.integrations.ckeditor.create_image_plugin'
这允许在 Firefox 和 IE 的新版本中将图片拖入文本编辑器。
自定义
大多数插件(文件、文件夹、图片和摘要)支持配置自定义“样式”(模板)。
例如,为图片插件添加以下设置
CMSPLUGIN_FILER_IMAGE_STYLE_CHOICES = ( ('default', 'Default'), ('boxed', 'Boxed'), ) CMSPLUGIN_FILER_IMAGE_DEFAULT_STYLE = 'boxed'
现在,如果模板存在于 cmsplugin_filer_image/plugins/image/boxed.html,则将使用它。如果不存在,则回退到 cmsplugin_filer_image/plugins/image/default.html。如果默认模板中的 CSS 类足够,则可以使用 {{ instance.style }} 在模板中使用它。
为了向后兼容,插件在存在的情况下将始终使用 cmsplugin_filer_image/image.html。在迁移到新结构后,请删除该模板。
类
例如 left、center、right 和 img-responsive 等类由插件提供,可在您的项目中使用。