Package: cone.fileupload
This package integratesjQueryFileUploadin cone.Currently, version 10.32.0 is included.Included files of jQuery File Upload:jquery.iframe-transport.jsjquery.fileupload.jsjquery.fileupload-process.jsjquery.fileupload-ui.jsjquery.fileupload-validate.jsAdditionally, v3.20.0 ofJavascript-Templatesis included.UsageSincecone.appnot knows about the underlying data,cone.fileuploadonly provides an abstract server implementation.So first we need to provide a model.fromcone.app.modelimportBaseNodefrompyramid.securityimportALL_PERMISSIONSfrompyramid.securityimportAllowfrompyramid.securityimportDenyfrompyramid.securityimportEveryoneACL=[(Allow,'role:manager',['add','delete']),(Allow,Everyone,['login']),(Deny,Everyone,ALL_PERMISSIONS),]classContainer(BaseNode):__acl__=ACLdef__call__(self):"""Persistence happens here.
        """classFile(BaseNode):__acl__=ACL# allow setting any value typesallow_non_node_children=TrueNow we need to provide a concreteFileUploadHandleimplementation for
our model.fromcone.fileupload.browser.fileuploadimportFileUploadHandlefrompyramid.viewimportview_config@view_config(name='fileupload_handle',context=Container,# <- here the view gets bound to our modelaccept='application/json',renderer='json',permission='add')classContainerFileUploadHandle(FileUploadHandle):defcreate_file(self,stream,filename,mimetype):# this function gets called for persisting uploaded filesfile=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',}defread_existing(self):# this function gets called for initial reading of existing filesfiles=list()fornodeinself.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',})returnfilesOptionally we might want to provide a custom fileupload tile for our model.fromcone.tileimporttilefromcone.fileupload.browser.fileuploadimportFileUploadTile@tile(name='fileupload',path='cone.fileupload:browser/fileupload.pt',interface=Container,permission='add')classContainerFileUploadTile(FileUploadTile):accept_file_types=r'/(\.|\/)(gif|jpg)$/i'The file upload actions are either rendered as dedicated tile by namefileupload_toolbaror integrated into the context menu. If it’s desired to
display the action in the context menu,fileupload_contextmenu_actionsflag must be set on modelproperties.ContributorsRobert NiederreiterChanges0.7 (2022-01-19)Modernize JavaScript setup.Addi18n_messages_src,upload_template_srcanddownload_template_srcattributes toFileUploadTile.Add optionaldownload_urlto file data dict.RemovethumbnailUrlfrom file data dict.Breaking ChangesRenameurltoview_urlin file data dict.RenamedeleteUrltodelete_urlin file data dict.RenamedeleteTypetodelete_typein 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 deprecatedallow_non_node_childstoallow_non_node_childrenin tests and documentation.
[rnix]0.4 (2020-05-30)Initial pypi release
[rnix]0.3Python 3 compatibility.
[rnix]Convert doctests to unittests.
[rnix]Usecone.app.main_hookdecorator.
[rnix]Move resource registration to main hook.
[rnix]Upgrade tocone.app1.0b1.
[rnix]0.2Code organization.
[rnix]0.1Make it work
[rnix]LicenseCopyright (c) 2013-2021, BlueDynamics Alliance, Austria
Copyright (c) 2021, 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.