|
17 | 17 |
|
18 | 18 |
|
19 | 19 | class _Dropzone(object):
|
20 |
| - @staticmethod |
21 |
| - def load(js_url="", css_url="", version="5.9.3"): |
22 |
| - """Load Dropzone resources with given version and init dropzone configuration. |
23 |
| -
|
24 |
| - .. versionchanged:: 1.4.3 |
25 |
| - Added ``js_url`` and ``css_url`` parameters to pass custom resource URL. |
26 |
| -
|
27 |
| - .. versionchanged:: 1.4.4 |
28 |
| - This method was deprecated due to inflexible. Now it's divided into three methods: |
29 |
| - 1. Use ``load_css()`` to load css resources. |
30 |
| - 2. Use ``load_js()`` to load js resources. |
31 |
| - 3. Use ``config()`` to configure Dropzone. |
32 |
| -
|
33 |
| - :param js_url: The JavaScript url for Dropzone.js. |
34 |
| - :param css_url: The CSS url for Dropzone.js. |
35 |
| - :param version: The version of Dropzone.js. |
36 |
| - """ |
37 |
| - warnings.warn("The method will be removed in 2.0, see docs for more details.") |
38 |
| - js_filename = "dropzone.min.js" |
39 |
| - css_filename = "dropzone.min.css" |
40 |
| - |
41 |
| - upload_multiple = current_app.config["DROPZONE_UPLOAD_MULTIPLE"] |
42 |
| - parallel_uploads = current_app.config["DROPZONE_PARALLEL_UPLOADS"] |
43 |
| - |
44 |
| - if upload_multiple in [True, "true", "True", 1]: |
45 |
| - upload_multiple = "true" |
46 |
| - else: |
47 |
| - upload_multiple = "false" |
48 |
| - |
49 |
| - serve_local = current_app.config["DROPZONE_SERVE_LOCAL"] |
50 |
| - size = current_app.config["DROPZONE_MAX_FILE_SIZE"] |
51 |
| - param = current_app.config["DROPZONE_INPUT_NAME"] |
52 |
| - redirect_view = current_app.config["DROPZONE_REDIRECT_VIEW"] |
53 |
| - |
54 |
| - if redirect_view is not None: |
55 |
| - redirect_js = """ |
56 |
| - this.on("queuecomplete", function(file) { |
57 |
| - // Called when all files in the queue finish uploading. |
58 |
| - window.location = "%s"; |
59 |
| - });""" % url_for(redirect_view) |
60 |
| - else: |
61 |
| - redirect_js = "" |
62 |
| - |
63 |
| - if not current_app.config["DROPZONE_ALLOWED_FILE_CUSTOM"]: |
64 |
| - allowed_type = allowed_file_extensions[ |
65 |
| - current_app.config["DROPZONE_ALLOWED_FILE_TYPE"] |
66 |
| - ] |
67 |
| - else: |
68 |
| - allowed_type = current_app.config["DROPZONE_ALLOWED_FILE_TYPE"] |
69 |
| - |
70 |
| - max_files = current_app.config["DROPZONE_MAX_FILES"] |
71 |
| - default_message = current_app.config["DROPZONE_DEFAULT_MESSAGE"] |
72 |
| - invalid_file_type = current_app.config["DROPZONE_INVALID_FILE_TYPE"] |
73 |
| - file_too_big = current_app.config["DROPZONE_FILE_TOO_BIG"] |
74 |
| - server_error = current_app.config["DROPZONE_SERVER_ERROR"] |
75 |
| - browser_unsupported = current_app.config["DROPZONE_BROWSER_UNSUPPORTED"] |
76 |
| - max_files_exceeded = current_app.config["DROPZONE_MAX_FILE_EXCEED"] |
77 |
| - cancelUpload = current_app.config["DROPZONE_CANCEL_UPLOAD"] |
78 |
| - removeFile = current_app.config["DROPZONE_REMOVE_FILE"] |
79 |
| - cancelConfirmation = current_app.config["DROPZONE_CANCEL_CONFIRMATION"] |
80 |
| - uploadCanceled = current_app.config["DROPZONE_UPLOAD_CANCELED"] |
81 |
| - |
82 |
| - timeout = current_app.config["DROPZONE_TIMEOUT"] |
83 |
| - if timeout: |
84 |
| - timeout_js = "timeout: %d," % timeout |
85 |
| - else: |
86 |
| - timeout_js = "" |
87 |
| - |
88 |
| - if serve_local: |
89 |
| - js = '<script src="%s"></script>\n' % url_for( |
90 |
| - "dropzone.static", filename=js_filename |
91 |
| - ) |
92 |
| - css = '<link rel="stylesheet" href="%s" type="text/css">\n' % url_for( |
93 |
| - "dropzone.static", filename=css_filename |
94 |
| - ) |
95 |
| - else: |
96 |
| - js = ( |
97 |
| - '<script src="https://cdn.jsdelivr.net/npm/dropzone@%s/dist/%s"></script>\n' |
98 |
| - % (version, js_filename) |
99 |
| - ) |
100 |
| - css = ( |
101 |
| - '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dropzone@%s/dist/min/%s"' |
102 |
| - ' type="text/css">\n' % (version, css_filename) |
103 |
| - ) |
104 |
| - |
105 |
| - if js_url: |
106 |
| - js = '<script src="%s"></script>\n' % js_url |
107 |
| - if css_url: |
108 |
| - css = '<link rel="stylesheet" href="%s" type="text/css">\n' % css_url |
109 |
| - |
110 |
| - return Markup( |
111 |
| - """ |
112 |
| - %s%s<script> |
113 |
| -Dropzone.options.myDropzone = { |
114 |
| - init: function() {%s}, |
115 |
| - uploadMultiple: %s, |
116 |
| - parallelUploads: %d, |
117 |
| - paramName: "%s", // The name that will be used to transfer the file |
118 |
| - maxFilesize: %d, // MB |
119 |
| - acceptedFiles: "%s", |
120 |
| - maxFiles: %s, |
121 |
| - dictDefaultMessage: "%s", // message display on drop area |
122 |
| - dictFallbackMessage: "%s", |
123 |
| - dictInvalidFileType: "%s", |
124 |
| - dictFileTooBig: "%s", |
125 |
| - dictResponseError: "%s", |
126 |
| - dictMaxFilesExceeded: "%s", |
127 |
| - dictCancelUpload: "%s", |
128 |
| - dictRemoveFile: "%s", |
129 |
| - dictCancelUploadConfirmation: "%s", |
130 |
| - dictUploadCanceled: "%s", |
131 |
| - %s // timeout |
132 |
| -}; |
133 |
| - </script> |
134 |
| - """ |
135 |
| - % ( |
136 |
| - css, |
137 |
| - js, |
138 |
| - redirect_js, |
139 |
| - upload_multiple, |
140 |
| - parallel_uploads, |
141 |
| - param, |
142 |
| - size, |
143 |
| - allowed_type, |
144 |
| - max_files, |
145 |
| - default_message, |
146 |
| - browser_unsupported, |
147 |
| - invalid_file_type, |
148 |
| - file_too_big, |
149 |
| - server_error, |
150 |
| - max_files_exceeded, |
151 |
| - cancelUpload, |
152 |
| - removeFile, |
153 |
| - cancelConfirmation, |
154 |
| - uploadCanceled, |
155 |
| - timeout_js, |
156 |
| - ) |
157 |
| - ) |
158 | 20 |
|
159 | 21 | @staticmethod
|
160 | 22 | def load_css(css_url=None, version="5.9.3"):
|
|
0 commit comments