cone.fileupload


Namecone.fileupload JSON
Version 0.8 PyPI version JSON
download
home_pagehttp://github.com/conestack/cone.fileuplaod
SummaryjQuery File Upload integration for cone.app
upload_time2025-10-25 11:01:42
maintainerNone
docs_urlNone
authorCone Contributors
requires_pythonNone
licenseSimplified BSD
keywords node pyramid cone web
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/cone.fileupload.svg
    :target: https://pypi.python.org/pypi/cone.fileupload
    :alt: Latest PyPI version

.. image:: https://img.shields.io/pypi/dm/cone.fileupload.svg
    :target: https://pypi.python.org/pypi/cone.fileupload
    :alt: Number of PyPI downloads

.. image:: https://travis-ci.org/bluedynamics/cone.fileupload.svg?branch=master
    :target: https://travis-ci.org/bluedynamics/cone.fileupload

.. image:: https://coveralls.io/repos/github/bluedynamics/cone.fileupload/badge.svg?branch=master
    :target: https://coveralls.io/github/bluedynamics/cone.fileupload?branch=master

This package integrates
`jQueryFileUpload <https://github.com/blueimp/jQuery-File-Upload>`_ in cone.

Currently, version 10.32.0 is included.

Included files of jQuery File Upload:

* jquery.iframe-transport.js
* jquery.fileupload.js
* jquery.fileupload-process.js
* jquery.fileupload-ui.js
* jquery.fileupload-validate.js

Additionally, v3.20.0 of
`Javascript-Templates <https://github.com/blueimp/JavaScript-Templates>`_
is included.


Usage
-----

Since ``cone.app`` not knows about the underlying data, ``cone.fileupload``
only provides an abstract server implementation.

So first we need to provide a model.

.. code-block:: python

    from cone.app.model import BaseNode
    from pyramid.security import ALL_PERMISSIONS
    from pyramid.security import Allow
    from pyramid.security import Deny
    from pyramid.security import Everyone

    ACL = [
        (Allow, 'role:manager', ['add', 'delete']),
        (Allow, Everyone, ['login']),
        (Deny, Everyone, ALL_PERMISSIONS),
    ]

    class Container(BaseNode):
        __acl__ = ACL

        def __call__(self):
            """Persistence happens here.
            """

    class File(BaseNode):
        __acl__ = ACL

        # allow setting any value types
        child_constraints = None

Now we need to provide a concrete ``FileUploadHandle`` implementation for
our model.

.. code-block:: python

    from cone.fileupload.browser.fileupload import FileUploadHandle
    from pyramid.view import view_config

    @view_config(
        name='fileupload_handle',
        context=Container, # <- here the view gets bound to our model
        accept='application/json',
        renderer='json',
        permission='add')
    class ContainerFileUploadHandle(FileUploadHandle):

        def create_file(self, stream, filename, mimetype):
            # this function gets called for persisting uploaded files
            file = self.model[filename] = File()
            file['body'] = stream.read()
            return {
                'name': filename,
                'size': len(file['body']),
                'view_url': '/{0}'.format(file.name),
                'download_url': '/{0}/download'.format(file.name),
                'delete_url': '/{0}/filedelete_handle'.format(file.name),
                'delete_type': 'GET',
            }

        def read_existing(self):
            # this function gets called for initial reading of existing files
            files = list()
            for node in self.model.values():
                files.append({
                    'name': node.name,
                    'size': len(node['body']),
                    'view_url': '/{0}'.format(node.name),
                    'download_url': '/{0}/download'.format(node.name),
                    'delete_url': '/{0}/filedelete_handle'.format(node.name),
                    'delete_type': 'GET',
                })
            return files

Optionally we might want to provide a custom fileupload tile for our model.

.. code-block:: python

    from cone.tile import tile
    from cone.fileupload.browser.fileupload import FileUploadTile

    @tile(
        name='fileupload',
        path='cone.fileupload:browser/fileupload.pt',
        interface=Container,
        permission='add')
    class ContainerFileUploadTile(FileUploadTile):
        accept_file_types = r'/(\.|\/)(gif|jpg)$/i'

The file upload actions are either rendered as dedicated tile by name
``fileupload_toolbar`` or integrated into the context menu. If it's desired to
display the action in the context menu, ``fileupload_contextmenu_actions``
flag must be set on model ``properties``.


Contributors
============

- Robert Niederreiter


Changes
=======

0.8 (2025-10-25)
----------------

- Pin upper versions of dependencies.
  [rnix]

- Replace deprecated use of ``allow_non_node_children`` by ``child_constraints``.
  [rnix]


0.7 (2022-01-19)
----------------

- Modernize JavaScript setup.

- Add ``i18n_messages_src``, ``upload_template_src`` and
  ``download_template_src`` attributes to ``FileUploadTile``.

- Add optional ``download_url`` to file data dict.

- Remove ``thumbnailUrl`` from file data dict.

**Breaking Changes**

- Rename ``url`` to ``view_url`` in file data dict.

- Rename ``deleteUrl`` to ``delete_url`` in file data dict.

- Rename ``deleteType`` to ``delete_type`` in file data dict.


0.6 (2021-11-21)
----------------

- Fileupload actions optionally work from contextmenu.
  [rnix]

- Move button toolbar into dedicated tile for customization.
  [rnix]

- Reduce included files and plugins of jquery fileupload to required ones.
  [rnix]

- Update jquery fileupload to version 10.32.0.
  [rnix]


0.5 (2021-11-08)
----------------

- Rename deprecated ``allow_non_node_childs`` to ``allow_non_node_children``
  in tests and documentation.
  [rnix]


0.4 (2020-05-30)
----------------

- Initial pypi release
  [rnix]


0.3
---

- Python 3 compatibility.
  [rnix]

- Convert doctests to unittests.
  [rnix]

- Use ``cone.app.main_hook`` decorator.
  [rnix]

- Move resource registration to main hook.
  [rnix]

- Upgrade to ``cone.app`` 1.0b1.
  [rnix]


0.2
---

- Code organization.
  [rnix]


0.1
---

- Make it work
  [rnix]


License
=======

Copyright (c) 2013-2021, BlueDynamics Alliance, Austria
Copyright (c) 2021-2022, Cone Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
  list of conditions and the following disclaimer in the documentation and/or
  other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/conestack/cone.fileuplaod",
    "name": "cone.fileupload",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "node pyramid cone web",
    "author": "Cone Contributors",
    "author_email": "dev@conestack.org",
    "download_url": "https://files.pythonhosted.org/packages/31/f0/059db8deae2d11f7c733c82922ee808603d1edb31cf88e6f589252a0cc8f/cone_fileupload-0.8.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/cone.fileupload.svg\n    :target: https://pypi.python.org/pypi/cone.fileupload\n    :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/dm/cone.fileupload.svg\n    :target: https://pypi.python.org/pypi/cone.fileupload\n    :alt: Number of PyPI downloads\n\n.. image:: https://travis-ci.org/bluedynamics/cone.fileupload.svg?branch=master\n    :target: https://travis-ci.org/bluedynamics/cone.fileupload\n\n.. image:: https://coveralls.io/repos/github/bluedynamics/cone.fileupload/badge.svg?branch=master\n    :target: https://coveralls.io/github/bluedynamics/cone.fileupload?branch=master\n\nThis package integrates\n`jQueryFileUpload <https://github.com/blueimp/jQuery-File-Upload>`_ in cone.\n\nCurrently, version 10.32.0 is included.\n\nIncluded files of jQuery File Upload:\n\n* jquery.iframe-transport.js\n* jquery.fileupload.js\n* jquery.fileupload-process.js\n* jquery.fileupload-ui.js\n* jquery.fileupload-validate.js\n\nAdditionally, v3.20.0 of\n`Javascript-Templates <https://github.com/blueimp/JavaScript-Templates>`_\nis included.\n\n\nUsage\n-----\n\nSince ``cone.app`` not knows about the underlying data, ``cone.fileupload``\nonly provides an abstract server implementation.\n\nSo first we need to provide a model.\n\n.. code-block:: python\n\n    from cone.app.model import BaseNode\n    from pyramid.security import ALL_PERMISSIONS\n    from pyramid.security import Allow\n    from pyramid.security import Deny\n    from pyramid.security import Everyone\n\n    ACL = [\n        (Allow, 'role:manager', ['add', 'delete']),\n        (Allow, Everyone, ['login']),\n        (Deny, Everyone, ALL_PERMISSIONS),\n    ]\n\n    class Container(BaseNode):\n        __acl__ = ACL\n\n        def __call__(self):\n            \"\"\"Persistence happens here.\n            \"\"\"\n\n    class File(BaseNode):\n        __acl__ = ACL\n\n        # allow setting any value types\n        child_constraints = None\n\nNow we need to provide a concrete ``FileUploadHandle`` implementation for\nour model.\n\n.. code-block:: python\n\n    from cone.fileupload.browser.fileupload import FileUploadHandle\n    from pyramid.view import view_config\n\n    @view_config(\n        name='fileupload_handle',\n        context=Container, # <- here the view gets bound to our model\n        accept='application/json',\n        renderer='json',\n        permission='add')\n    class ContainerFileUploadHandle(FileUploadHandle):\n\n        def create_file(self, stream, filename, mimetype):\n            # this function gets called for persisting uploaded files\n            file = self.model[filename] = File()\n            file['body'] = stream.read()\n            return {\n                'name': filename,\n                'size': len(file['body']),\n                'view_url': '/{0}'.format(file.name),\n                'download_url': '/{0}/download'.format(file.name),\n                'delete_url': '/{0}/filedelete_handle'.format(file.name),\n                'delete_type': 'GET',\n            }\n\n        def read_existing(self):\n            # this function gets called for initial reading of existing files\n            files = list()\n            for node in self.model.values():\n                files.append({\n                    'name': node.name,\n                    'size': len(node['body']),\n                    'view_url': '/{0}'.format(node.name),\n                    'download_url': '/{0}/download'.format(node.name),\n                    'delete_url': '/{0}/filedelete_handle'.format(node.name),\n                    'delete_type': 'GET',\n                })\n            return files\n\nOptionally we might want to provide a custom fileupload tile for our model.\n\n.. code-block:: python\n\n    from cone.tile import tile\n    from cone.fileupload.browser.fileupload import FileUploadTile\n\n    @tile(\n        name='fileupload',\n        path='cone.fileupload:browser/fileupload.pt',\n        interface=Container,\n        permission='add')\n    class ContainerFileUploadTile(FileUploadTile):\n        accept_file_types = r'/(\\.|\\/)(gif|jpg)$/i'\n\nThe file upload actions are either rendered as dedicated tile by name\n``fileupload_toolbar`` or integrated into the context menu. If it's desired to\ndisplay the action in the context menu, ``fileupload_contextmenu_actions``\nflag must be set on model ``properties``.\n\n\nContributors\n============\n\n- Robert Niederreiter\n\n\nChanges\n=======\n\n0.8 (2025-10-25)\n----------------\n\n- Pin upper versions of dependencies.\n  [rnix]\n\n- Replace deprecated use of ``allow_non_node_children`` by ``child_constraints``.\n  [rnix]\n\n\n0.7 (2022-01-19)\n----------------\n\n- Modernize JavaScript setup.\n\n- Add ``i18n_messages_src``, ``upload_template_src`` and\n  ``download_template_src`` attributes to ``FileUploadTile``.\n\n- Add optional ``download_url`` to file data dict.\n\n- Remove ``thumbnailUrl`` from file data dict.\n\n**Breaking Changes**\n\n- Rename ``url`` to ``view_url`` in file data dict.\n\n- Rename ``deleteUrl`` to ``delete_url`` in file data dict.\n\n- Rename ``deleteType`` to ``delete_type`` in file data dict.\n\n\n0.6 (2021-11-21)\n----------------\n\n- Fileupload actions optionally work from contextmenu.\n  [rnix]\n\n- Move button toolbar into dedicated tile for customization.\n  [rnix]\n\n- Reduce included files and plugins of jquery fileupload to required ones.\n  [rnix]\n\n- Update jquery fileupload to version 10.32.0.\n  [rnix]\n\n\n0.5 (2021-11-08)\n----------------\n\n- Rename deprecated ``allow_non_node_childs`` to ``allow_non_node_children``\n  in tests and documentation.\n  [rnix]\n\n\n0.4 (2020-05-30)\n----------------\n\n- Initial pypi release\n  [rnix]\n\n\n0.3\n---\n\n- Python 3 compatibility.\n  [rnix]\n\n- Convert doctests to unittests.\n  [rnix]\n\n- Use ``cone.app.main_hook`` decorator.\n  [rnix]\n\n- Move resource registration to main hook.\n  [rnix]\n\n- Upgrade to ``cone.app`` 1.0b1.\n  [rnix]\n\n\n0.2\n---\n\n- Code organization.\n  [rnix]\n\n\n0.1\n---\n\n- Make it work\n  [rnix]\n\n\nLicense\n=======\n\nCopyright (c) 2013-2021, BlueDynamics Alliance, Austria\nCopyright (c) 2021-2022, Cone Contributors\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this\n  list of conditions and the following disclaimer in the documentation and/or\n  other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n",
    "bugtrack_url": null,
    "license": "Simplified BSD",
    "summary": "jQuery File Upload integration for cone.app",
    "version": "0.8",
    "project_urls": {
        "Homepage": "http://github.com/conestack/cone.fileuplaod"
    },
    "split_keywords": [
        "node",
        "pyramid",
        "cone",
        "web"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "29e483a4f7c7063a6832fe94284c23f6385edffb6dc0c7c4ab80c06e713cbbd9",
                "md5": "0e78d54aa508ed66738070e5a04d67fd",
                "sha256": "14916f9471f616163e3600e775cef4bc5235ee95fa5eab3fb795ae56e56184bb"
            },
            "downloads": -1,
            "filename": "cone_fileupload-0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e78d54aa508ed66738070e5a04d67fd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 52655,
            "upload_time": "2025-10-25T11:01:39",
            "upload_time_iso_8601": "2025-10-25T11:01:39.924786Z",
            "url": "https://files.pythonhosted.org/packages/29/e4/83a4f7c7063a6832fe94284c23f6385edffb6dc0c7c4ab80c06e713cbbd9/cone_fileupload-0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "31f0059db8deae2d11f7c733c82922ee808603d1edb31cf88e6f589252a0cc8f",
                "md5": "d60399a88c59546149fa0f54ee58e2da",
                "sha256": "9550d18ab35c37a197a2933fb05b23b0cbb9abddf0ebd8a6fa7a34a81da4c5bb"
            },
            "downloads": -1,
            "filename": "cone_fileupload-0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "d60399a88c59546149fa0f54ee58e2da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 45932,
            "upload_time": "2025-10-25T11:01:42",
            "upload_time_iso_8601": "2025-10-25T11:01:42.125969Z",
            "url": "https://files.pythonhosted.org/packages/31/f0/059db8deae2d11f7c733c82922ee808603d1edb31cf88e6f589252a0cc8f/cone_fileupload-0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-25 11:01:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "conestack",
    "github_project": "cone.fileuplaod",
    "github_not_found": true,
    "lcname": "cone.fileupload"
}
        
Elapsed time: 1.47660s