跳转到主要内容

Plone的多文件上传

项目描述

使Plone文件上传变得简单

使用uploadify为Plone提供多文件上传

Plone集成

上传文件夹选项卡操作默认安装。您可以通过portal_quickinstaller或通过控制面板中的插件部分进行安装。

配置

以下设置可以在site_properties中完成。(请只使用字符串属性!)

  • ul_auto_upload – true/false(默认:false)

    设置为true,如果您希望在文件被选中时上传文件。

  • ul_allow_multi – true/false(默认:true)

    设置为true,如果您希望允许多个文件上传。

  • ul_sim_upload_limit – 数字 1-n(默认:4)

    您希望允许的同时上传文件数量的限制。

  • ul_queue_size_limit – 数字 1-n(默认:999)

    一次上传可以选择的文件数量的限制。

  • ul_size_limit – 字节数(默认:空)

    代表每次上传字节数限制的数字。

  • ul_file_description – 文本(默认:空)

    将在浏览对话框底部出现的文本。

  • ul_file_extensions – 扩展名列表(默认:*.*;)

    您希望允许上传的文件扩展名列表。格式如*.ext1;*.ext2;*.ext3。使用此选项时需要FileDesc。

  • ul_button_text – 文本(默认:BROWSE)

    您希望在默认按钮上出现的文本。

  • ul_button_image – 图片路径(默认:空)

    浏览按钮将使用的图片路径。注意:如果您使用的是**不同大小的按钮图片*,您必须设置 ul_height 和 ul_width,否则 ul_button_image 将被拉伸到默认值(110x30)

  • ul_hide_button – true/false(默认:false)

    如果想要隐藏按钮图片,请设置为 true。

  • ul_script_access – always/sameDomain(默认:sameDomain)

    Flash 文件中脚本的访问模式。如果您正在本地测试,请设置为 `always`。

  • ul_width – 数字(默认:110)

    使用不同大小的 ul_button_image 时应设置的 ul_width 值

  • ul_height – 数字(默认:30)

    使用不同大小的 ul_button_image 时应设置的 ul_height 值

  • ul_scale_image_size – x,y

    这两个值定义了图像的最大 x,y 尺寸(像素)。将图像按比例缩小到最多 ul_scale_image_size 大小,同时保持宽高比。例如:800,600 设置最大尺寸为 800x600 像素

  • ul_content_field – Contenttype.field

    上传的文件将包含到特定的字段中,特定于 Contenttype。例如:File.file 上传到字段 file,内容类型为 File

添加自定义文件突变工具

如果您想在文件在门户中创建之前进行一些特殊处理,可以简单地注册一个新的提供 IFileMutator 接口的新工具。

在内容将在门户中创建之前,您的工具将使用 file_name, file_data, content_type 被调用。

示例

一个简单的工具,它将“photo-”前缀添加到图像文件名中

configure.zcml

<!-- An Utility to give images an "photo-" prefix -->
<utility component=".utility.prefix_image_filename"
         name="prefix-image-filename"/>

utility.py

from zope import interface

def prefix_image_filename(file_name, file_data, content_type):
    """ Prefix all images with 'photo-<filename>'
    """
    # we only handle image files
    if not content_type.startswith("image"):
        return (file_name, file_data, content_type)

    if not file_name.startswith("photo"):
        file_name = "-".join(["photo", file_name])
    return (file_name, file_data, content_type)


interface.directlyProvides(prefix_image_filename,
                           IFileMutator)

针对特定 BrowserLayer 的定制

如果您安装了自己的基于其自身的 BrowserLayer(默认为 IThemeSpecific)的皮肤,并想定制 collective.uploadify 的外观和感觉,可以覆盖上传视图和/或上传初始化回调视图

  • 自定义视图模板

    <configure
        xmlns="http://namespaces.zope.org/zope"
        xmlns:browser="http://namespaces.zope.org/browser">
    
        ...
    
        <!-- Customize collective.uploadify upload template -->
        <browser:page
            for="collective.uploadify.browser.interfaces.IUploadingCapable"
            name="upload"
            template="templates/upload.pt"
            permission="cmf.AddPortalContent"
            layer=".interfaces.IThemeSpecific"
            />
    
    </configure>
  • 自定义初始化模板

    from zope.i18n import translate
    from zope.component import getMultiAdapter
    from collective.uploadify.browser.upload import UploadInitalize
    from my.product import MyMessageFactory as _
    
    
    class MyCustomUploadInitalize(UploadInitalize):
        """ Initialize uploadify js
        """
    
        def upload_settings(self):
    
            portal_state = getMultiAdapter(
                (self.context, self.request), name="plone_portal_state")
    
            settings = super(MyCustomUploadInitalize, self).upload_settings()
            settings.update(dict(
                ul_height = 26,
                ul_width = 105,
                ul_button_text = translate(_('Choose images'), target_language= \
                                           self.request.get('LANGUAGE', 'de')),
                ul_button_image = portal_state.navigation_root_url() + \
                    '/button_upload.png',
            ))
    
            return settings

    不要忘记使用以下方式为您的 themespecific browserlayer 注册新的上传初始化视图

    <configure
         xmlns="http://namespaces.zope.org/zope"
         xmlns:browser="http://namespaces.zope.org/browser">
    
       ...
    
        <browser:page
            for="*"
            name="upload_initialize"
            class=".uploadify.MyCustomUploadInitalize"
            permission="cmf.AddPortalContent"
            layer=".interfaces.IThemeSpecific"
            />
    
    </configure>

collective.uploadify 安装

要安装 collective.uploadify 到全局 Python 环境(或工作环境),使用传统的 Zope 2 实例,您可以这样做

  • 当您阅读此内容时,您可能已经运行了 easy_install collective.uploadify。有关如何安装 setuptools(和 EasyInstall)的信息,请参阅:http://peak.telecommunity.com/DevCenter/EasyInstall

  • 如果您正在使用 Zope 2.9(不是 2.10),请获取 pythonproducts 并通过以下方式安装它

    python setup.py install --home /path/to/instance

到您的 Zope 实例中。

  • /path/to/instance/etc/package-includes 目录中创建一个名为 collective.uploadify-configure.zcml 的文件。该文件应仅包含以下内容

    <include package="collective.uploadify" />

或者,如果您正在使用 zc.buildout 和 plone.recipe.zope2instance 脚本管理您的项目,您可以这样做

  • collective.uploadify 添加到要安装的 eggs 和 zcml 的列表中,例如

    [buildout]
    ...
    eggs =
        ...
        collective.uploadify
    
    zcml =
        ...
        collective.uploadify
  • 重新运行 buildout,例如使用

    $ ./bin/buildout

更改日志

1.2 (2013-05-11)

  • 使与 dexterity (plone.app.contenttypes) 兼容 [pbauer]

  • 使用 IUserPreferredURLNormalizer 设置 id 的 [pbauer]

1.1 - 2012-10-11

  • 迁移到 GitHub [ramonski]

  • Plone 4.3 兼容性 [alert]

  • 添加了意大利语翻译。 [keul]

  • 清理 egg 格式,删除 bad zopeskel 元素 [keul]

  • 添加了默认的 genericsetup 配置文件,该配置文件为每个文件夹添加文件夹选项卡。 [garbas]

1.0 - 2011-05-05

  • 修复了 Plone > 3.3.5 时 IDNormalizer 丢失文件扩展名的问题。改为使用 IFileNameNormalizer 工具 [jakke, ramonski]

  • 添加了荷兰语翻译 [spereverde]

1.0rc5 - 2011-04-04

  • 支持不同的内容类型 [thor27]

  • 添加了巴斯克语翻译 [erral]

  • 添加了西班牙语翻译 [macagua]

1.0rc4 - 2011-01-31

  • 添加了德语翻译 [fRiSi]

  • 添加了台湾中文翻译 [marr]

  • 更新文档以显示默认页面上的上传操作 [fRiSi]

1.0rc3 - 2010-09-18

  • 为上传内容触发 Fire Archetypes ObjectInitializedEvent。[hannosch]

  • 更正了文档中的 i18n:domain 并将其消息包含到 pot 文件中。[hannosch]

  • 添加了 z3c.autoinclude 入口点,以避免在 Plone 3.3 及更高版本中需要 ZCML slugs。[hannosch]

  • 更改了权限为 cmf.AddPortalContent,这修复了 http://plone.org/products/collective.uploadify/issues/13。[ramonski]

  • mimetypes.guess_type(file_name) 现在在无法猜测类型时返回空字符串。这修复了 scale_image_size 工具的问题。[ramonski]

  • 文档更新 [ramonski]

1.0rc2 - 2010-08-03

  • 引入了接口 “IFileMutator” – 提供此接口的工具可以在文件创建为内容类型之前对上传文件进行一些文件变更。[ramonski]

  • 注册了工具 scale_image_size – 此工具在图像上操作,可以使用 PIL 缩小图像大小,同时保留输入文件的宽高比。[ramonski]

  • id 选择器现在在线程锁之后被调用。这应该修复 #8。[ramonski]

  • 添加了适配器 cStringIO.OutputType -> IBlobbable 以兼容 plone.app.blob。仅在安装了 plone.app.blob 时注册此适配器。[ramonski]

  • 使用 folder_url 并移除 is_folderish() 和 wf-state 条件,使上传操作可以在私有文件夹或具有默认页面的文件夹中显示(修复了 http://plone.org/products/collective.uploadify/issues/12)[fRiSi]

  • 国际化添加了丹麦语翻译 [stonor]

1.0rc1 - 2010-04-25

  • 将资源 swfobject.js 重命名为 uploadify.swfobject.js。这修复了与 quintagroup.portlet.cumulus 的名称冲突。[ramonski]

  • 向包中添加了一些基本测试 [ramonski]

  • 将队列大小添加到 UploadInitialize flash 响应的设置中,以便用户可以自定义他们的上传队列大小。[zupo]

  • 文档更新。添加了关于自定义 uploadify 的上传视图和上传初始化视图模板的新章节。[saily]

  • 将高度和宽度添加到 UploadInitialize flash 响应的设置中,以便用户可以自定义他们的上传按钮。[saily]

  • 在每项上传后触发 ObjectModifiedEvent。(修复了 http://plone.org/products/collective.uploadify/issues/9)[saily]

0.10 - 2010-03-16

0.9 - 2009-10-29

  • 更新到 Uploadify v2.1.0 [ramonski]

  • 移除了 QUERY_STRING 的 cgi 解析器。现在我们通过 POST 接收数据 [ramonski]

  • 更新了 js、css 和 upload.pt [ramonski]

0.8 - 2009-10-27

  • 添加了 QUERY_STRING 的 cgi 解析器 [seletz, ramonski]

  • 添加了自定义字符串编码器/解码器 [seletz, ramonski]

  • 修复了德语 umlauts 的名称选择器 [ramonski]

0.7 - 2009-07-23

  • 重新修复了名称选择器 …gnaarf [ramonski]

  • 移除了愚蠢的日志记录 [ramonski]

0.6 - 2009-07-23

  • 将javascript中的资源路径从绝对路径更改为相对路径。这修复了一些导致 Uploadify - IOErrors 的奇怪行为。[ramonski]

  • 修复了 #2(AttributeError: aq_parent)- 当在门户网站根目录中进行上传时。[ramonski]

  • 上传文件夹现在也可以是私有状态。[ramonski]

0.5 - 2009-06-25

0.4 - 2009-06-23

  • 添加了取消按钮 [ramonski]

  • 可以在site_properties中设置uploadify设置 [ramonski]

  • 添加了一个名称选择器,以避免上传文件时发生id冲突 [ramonski]

0.3 - 2009-06-22

  • 修复了M$ IE浏览器中的bug,即“浏览”按钮不显示 [ramonski]

  • 将上传视图的权限更改为cmf.ModifyPortalContent [ramonski]

  • 添加了onAllComplete处理程序,该处理程序重新加载位置,并在文件夹列表宏中立即显示上传的文件 [ramonski]

  • 注册了uploadifyjavascript初始化的浏览器视图 [ramonski]

  • 注册了uploadify上传操作的浏览器视图 [ramonski]

  • 删除了未使用的代码 [ramonski]

0.2.2 - 2009-06-04

  • 在MANIFEST.in中添加了缺少的.txt扩展名 **gnarf**,我讨厌setuptools! [ramonski]

0.2.1 - 2009-06-04

  • 添加了缺少的MANIFEST.in文件 [ramonski]

0.2 - 2009-06-04

  • 删除了gs配置文件 [ramonski]

  • 为按钮添加了CSS样式 [ramonski]

  • 修复了与大小写文件扩展名相关的bug [ramonski]

0.1 - 2009-04-30

  • 初始版本 [ramonski]

贡献者

Ramon Bartl,作者

Stefan Eletzhofer,InQuant GmbH

Harald Friessnegger,Webmeisterei GmbH

Daniel Widerin,Kombinat Media Gestalter GmbH

Nejc Zupan,NiteoWeb Ltd.

Jan Van Hees,K.U.Leuven

Kim Paulissen,K.U.Leuven

Rok Garbas,http://www.garbas.si

Philip Bauer,bauer@starzel.de

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面