Permalink
Browse files

Merge pull request #14 from kalkehcoisa/master

Changed the way thumbnails are generated with removing of sorl-thumbnail. Thanks to @kalkehcoisa.
  • Loading branch information...
2 parents 1d59700 + df920b1 commit 493b8f09952592c33fdf42b7ef9e9e9980dba528 @garmoncheg committed Oct 7, 2013
Showing with 3,874 additions and 2,251 deletions.
  1. +1 −17 CHANGELOG
  2. +22 −39 README
  3. +2 −2 django_multiuploader/multiuploader/__init__.py
  4. +32 −5 django_multiuploader/multiuploader/admin.py
  5. +8 −0 django_multiuploader/multiuploader/context_processors.py
  6. +89 −0 django_multiuploader/multiuploader/default_settings.py
  7. +91 −0 django_multiuploader/multiuploader/forms.py
  8. BIN django_multiuploader/multiuploader/locale/ru/LC_MESSAGES/django.mo
  9. +133 −0 django_multiuploader/multiuploader/locale/ru/LC_MESSAGES/django.po
  10. 0 django_multiuploader/multiuploader/management/__init__.py
  11. 0 django_multiuploader/multiuploader/management/commands/__init__.py
  12. +29 −0 django_multiuploader/multiuploader/management/commands/clean_uploads.py
  13. +15 −0 django_multiuploader/multiuploader/management/commands/clear_sorlthumbnails.py
  14. +0 −42 django_multiuploader/multiuploader/media/multiuploader/scripts/application.js
  15. +0 −789 django_multiuploader/multiuploader/media/multiuploader/scripts/jquery.fileupload-ui.js
  16. +0 −1,113 django_multiuploader/multiuploader/media/multiuploader/scripts/jquery.fileupload.js
  17. BIN django_multiuploader/multiuploader/media/multiuploader/site_graphics/pbar-ani.gif
  18. +36 −0 django_multiuploader/multiuploader/migrations/0001_initial.py
  19. 0 django_multiuploader/multiuploader/migrations/__init__.py
  20. +62 −24 django_multiuploader/multiuploader/models.py
  21. +43 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/collectfiles.js
  22. +407 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/jquery-ui.min.js
  23. +686 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/jquery.fileupload-ui.js
  24. +752 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/jquery.fileupload.js
  25. +21 −35 django_multiuploader/multiuploader/{media → static}/multiuploader/scripts/jquery.iframe-transport.js
  26. +4 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/jquery.min.js
  27. +1 −0 django_multiuploader/multiuploader/static/multiuploader/scripts/jquery.tmpl.min.js
  28. +563 −0 django_multiuploader/multiuploader/static/multiuploader/styles/jquery-ui.css
  29. +29 −3 django_multiuploader/multiuploader/{media → static}/multiuploader/styles/jquery.fileupload-ui.css
  30. +214 −0 django_multiuploader/multiuploader/templates/multiuploader/form.html
  31. +0 −92 django_multiuploader/multiuploader/templates/multiuploader/multiuploader_main.html
  32. +9 −0 django_multiuploader/multiuploader/templates/multiuploader/noscript.html
  33. +0 −1 django_multiuploader/multiuploader/templates/multiuploader/one_image.html
  34. 0 django_multiuploader/multiuploader/templatetags/__init__.py
  35. +70 −3 django_multiuploader/multiuploader/templatetags/multiuploader.py
  36. +0 −1 django_multiuploader/multiuploader/templatetags/verbatim.py
  37. 0 django_multiuploader/multiuploader/tests.py
  38. +214 −0 django_multiuploader/multiuploader/thumbs.py
  39. +17 −16 django_multiuploader/multiuploader/urls.py
  40. +161 −0 django_multiuploader/multiuploader/utils.py
  41. +163 −69 django_multiuploader/multiuploader/views.py
View
@@ -1,19 +1,3 @@
Changelog for Django-multiuploader
-Django-multiuploader 1.2.0 27.07.2011
-==============================================================
-- add {% verbatim %} templatetag thanks to "dadon" issue #1
- (implements a "more right" way to escape jQuery UI code in django templates)
-- updated Sebastian's jQuery plugin to today's ver to fix known issues.
-
-Django-multiuploader 1.1.1 26.07.2011
-==============================================================
-- critical bugfix with JSON output
-
-Django-multiuploader 1.1.0 22.07.2011
-==============================================================
-- Bugfixes and options restyle
-
-Django-multiuploader 1.0.0 19.07.2011
-==============================================================
-- Stable version
+Removed the dependence to sorl-thumbnail (it's not needed anymore, just PIL)
View
61 README
@@ -5,68 +5,58 @@ Readme for plugin of Django Multiuploader using jQuery Plugin by Sebastian Tscha
This is a plugin, made using multiupload form from Sebastian Tschan.
It uses jQuey UI and jQuery instead of Flash uploader.
-On Django side it uses sorl-thumbnails and PIL.
-You can use it in your applications with simple inclusion tag
+On Django side it uses PIL. You can use it in your applications with a simple inclusion tag.
Requirements:
----------------------------------------------------------------------
- - PIL(Python Imaging Library) (for sorl)
- - sorl-thumbnail's(http://thumbnail.sorl.net/) (for thumbnails generation)
+ - PIL(Python Imaging Library)
- Django 1.2.5 +
Tested:
----------------------------------------------------------------------
-Currently Tested full functionality under Chrome, Firefox and Safari.
-Opera somehow fails to add multiple Photos.
-
-Will try to fix them as soon as possible.
+Currently Tested full functionality under Chrome and Firefox.
Example usage:
----------------------------------------------------------------------
-Adding this AJAX form to your web site is as simple, as adding this 2 tags to your template:
+Adding this AJAX form to your web site is almost as simple as adding this 2 tags to your template:
{% load multiuploader %}
{% multiupform %}
-Also I've done a demo app repo here at my github.
-It's called django_multiuploader_usage_demo.
-For those who can not figure out this manual.) Also feel free to comment it on my
-blog or send me a e-mail with your troubles/suggestions and usage experience...
-https://github.com/garmoncheg/django_multiuploader_example_usage/
+Just need to adjust some parameters.
+If you need any help, found any bugs, feel free to get in contact here in github.
+Soon there'll be a blog in which I'll provide some examples and help about this package.
Installation:
----------------------------------------------------------------------
-1.Install an app. Do it by adding:
+1.Download the package.
+
+This version is a branch, so the easiest way is:
+
+git clone git@github.com:kalkehcoisa/django_multiuploader.git
+
+And add the application to your project.
+
+2.Install the app. Do it by adding:
'multiuploader',
string to your settings.py -> INSTALLED_APPS = () dictionary.
-Note that is has to have 'sorl.thumbnail', working already.
-2.Register urls in your root urlconf urls.py adding string to your urlpatterns like so :
+3.Register urls in your root urlconf urls.py adding string to your urlpatterns like so :
url(r'', include('multiuploader.urls')),
-3.Copy or symlink files from plugins "media/" directory to your MEDIA_ROOT.
+4.Copy or symlink files from plugins "media/" directory to your MEDIA_ROOT.
-4.Edit templates and styles to meet your needs. (Optional)
+5.Edit templates and styles to meet your needs. (Optional)
(for e.g. changing the form design and/or behavior)
-5. Include the following js/css.
-
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" id="theme">
- <link rel="stylesheet" href="{{ static_url }}multiuploader/styles/jquery.fileupload-ui.css">
+6. Include the following js/css.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script src="js/vendor/jquery.ui.widget.js"></script>
- <script src="http://blueimp.github.com/JavaScript-Templates/tmpl.min.js"></script>
- <script src="http://blueimp.github.com/JavaScript-Load-Image/load-image.min.js"></script>
- <script src="http://blueimp.github.com/JavaScript-Canvas-to-Blob/canvas-to-blob.min.js"></script>
- <script src="{{ static_url }}multiuploader/scripts/jquery.fileupload.js"></script>
- <script src="{{ static_url }}multiuploader/scripts/jquery.fileupload-fp.js"></script>
- <script src="{{ static_url }}multiuploader/scripts/jquery.fileupload-ui.js"></script>
Settings:
----------------------------------------------------------------------
@@ -103,19 +93,12 @@ You can use it directly in your code like so:
image = get_object_or_404(MultiuploaderImage, key_data=key)
url = settings.MEDIA_URL+image.image.name
return render_to_response('multiuploader/one_image.html', {"multi_single_url":url,})
-
-And then in template:
-
- #'multiuploader/one_image.html'
- <img src="{{ multi_single_url }}">
-
-I will not stop on model usage here for long. Fell free to ask me any questions appeared...
Development plans:
----------------------------------------------------------------------
- Add a way to specify which model to use to store files.
-
-
+ - Make the application easier to be configured and used.
+ - Allow more customization and provide easier ways of integration.
Changes:
----------------------------------------------------------------------
View
@@ -1,2 +1,2 @@
-VERSION = (1, 2, 1)
-__version__ = '.'.join(map(str, VERSION))
+VERSION = (0, 2, 2)
+__version__ = '.'.join(map(str, VERSION))
View
@@ -1,9 +1,36 @@
-from models import MultiuploaderImage
+from django import forms
from django.contrib import admin
+from django.core.urlresolvers import reverse
+from django.forms.widgets import ClearableFileInput
+from django.contrib.admin.widgets import AdminFileWidget
-class MultiuploaderImageAdmin(admin.ModelAdmin):
+
+from models import MultiuploaderFile
+
+
+"""class MultiuploaderAdminFileWidget(AdminFileWidget):
+ def __init__(self, multiuploader_file, *args, **kwargs):
+ self.multiuploader_file = multiuploader_file
+ super(MultiuploaderAdminFileWidget, self).__init__(*args, **kwargs)
+
+ def render(self, name, value, attrs=None):
+ setattr(self.multiuploader_file, "url", reverse('multiuploader_file_link', kwargs={'pk': self.multiuploader_file.pk}))
+ return super(MultiuploaderAdminFileWidget, self).render(name, self.multiuploader_file, attrs)
+
+
+class MultiuploaderAdminForm(forms.ModelForm):
+ def __init__(self, *args, **kwargs):
+ super(MultiuploaderAdminForm, self).__init__(*args, **kwargs)
+ self.fields['file'].widget = MultiuploaderAdminFileWidget(multiuploader_file=self.instance)
+
+ class Meta:
+ model = MultiuploaderFile"""
+
+
+class MultiuploaderAdmin(admin.ModelAdmin):
+ #form = MultiuploaderAdminForm
search_fields = ["filename", "key_data"]
- list_display = ["filename", "image", "key_data"]
- list_filter = ["filename", "image", "key_data"]
+ list_display = ["filename", "upload_date", "file"]
+
-admin.site.register(MultiuploaderImage, MultiuploaderImageAdmin)
+admin.site.register(MultiuploaderFile, MultiuploaderAdmin)
@@ -0,0 +1,8 @@
+# -*- coding:utf-8 -*-
+from django.utils.crypto import get_random_string
+
+def booleans(request):
+ return {
+ 'True': True,
+ 'False': False
+ }
@@ -0,0 +1,89 @@
+# Expiration time in seconds, one hour as default
+
+# from django.conf import settings
+
+# TIME_ZONE = settings.TIME_ZONE
+# LOGGING_CONFIG = settings.LOGGING_CONFIG
+
+
+MULTIUPLOADER_FILE_EXPIRATION_TIME = 3600
+
+MULTIUPLOADER_FILES_FOLDER = 'multiuploader'
+
+
+MULTIUPLOADER_FORMS_SETTINGS = {
+ 'default': {
+ 'FILE_TYPES': ['jpg', 'jpeg', 'png', 'txt', 'zip', 'rar', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp', 'rtf'],
+ 'CONTENT_TYPES': [
+ 'image/jpeg',
+ 'image/png',
+ 'text/plain',
+ 'application/zip',
+ 'application/x-rar-compressed',
+ 'application/octet-stream',
+ 'application/msword',
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ 'application/vnd.ms-excel',
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ 'application/vnd.ms-powerpoint',
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ 'application/vnd.oasis.opendocument.text',
+ 'application/vnd.oasis.opendocument.spreadsheet',
+ 'application/vnd.oasis.opendocument.presentation',
+ 'text/rtf',
+ ],
+ 'MAX_FILE_SIZE': 10485760,
+ 'MAX_FILE_NUMBER': 5,
+ 'AUTO_UPLOAD': True
+ },
+ 'images': {
+ 'FILE_TYPES': ['jpg', 'jpeg', 'png', 'gif', 'svg', 'bmp', 'tiff', 'ico'],
+ 'CONTENT_TYPES': [
+ 'image/gif',
+ 'image/jpeg',
+ 'image/pjpeg',
+ 'image/png',
+ 'image/svg+xml',
+ 'image/tiff',
+ 'image/vnd.microsoft.icon',
+ 'image/vnd.wap.wbmp',
+ ],
+ 'MAX_FILE_SIZE': 10485760,
+ 'MAX_FILE_NUMBER': 5,
+ 'AUTO_UPLOAD': True
+ },
+ 'video': {
+ 'FILE_TYPES': ['flv', 'mpg', 'mpeg', 'mp4' ,'avi', 'mkv', 'ogg', 'wmv', 'mov', 'webm'],
+ 'CONTENT_TYPES': [
+ 'video/mpeg',
+ 'video/mp4',
+ 'video/ogg',
+ 'video/quicktime',
+ 'video/webm',
+ 'video/x-ms-wmv',
+ 'video/x-flv',
+ ],
+ 'MAX_FILE_SIZE': 10485760,
+ 'MAX_FILE_NUMBER': 5,
+ 'AUTO_UPLOAD': True
+ },
+ 'audio': {
+ 'FILE_TYPES': ['mp3', 'mp4', 'ogg', 'wma', 'wax', 'wav', 'webm'],
+ 'CONTENT_TYPES': [
+ 'audio/basic',
+ 'audio/L24',
+ 'audio/mp4',
+ 'audio/mpeg',
+ 'audio/ogg',
+ 'audio/vorbis',
+ 'audio/x-ms-wma',
+ 'audio/x-ms-wax',
+ 'audio/vnd.rn-realaudio',
+ 'audio/vnd.wave',
+ 'audio/webm'
+ ],
+ 'MAX_FILE_SIZE': 10485760,
+ 'MAX_FILE_NUMBER': 5,
+ 'AUTO_UPLOAD': True
+ },
+}
@@ -0,0 +1,91 @@
+import os
+import re
+import magic
+
+from django import forms
+from django.conf import settings
+from django.utils import simplejson
+from django.utils.html import mark_safe
+from django.utils.translation import ugettext_lazy as _
+from django.template.defaultfilters import filesizeformat
+
+from utils import format_file_extensions
+
+import multiuploader.default_settings as DEFAULTS
+
+
+class MultiuploadWidget(forms.MultipleHiddenInput):
+ def __init__(self, attrs={}):
+ super(MultiuploadWidget, self).__init__(attrs)
+
+ def render(self, name, value, attrs=None):
+ widget_ = super(MultiuploadWidget, self).render(name, value, attrs)
+ output = '<div id="hidden_container" style="display:none;">%s</div>' % widget_
+ return mark_safe(output)
+
+
+class MultiuploaderField(forms.MultiValueField):
+ widget = MultiuploadWidget()
+
+ def formfield(self, **kwargs):
+ kwargs['widget'] = MultiuploadWidget
+ return super(MultiuploaderField, self).formfield(**kwargs)
+
+ def validate(self, values):
+ super(MultiuploaderField, self).validate(values)
+
+ def clean(self, values):
+ super(MultiuploaderField, self).clean(values)
+ return values
+
+ def compress(self, value):
+ if value:
+ return value
+
+ return None
+
+
+class MultiUploadForm(forms.Form):
+ file = forms.FileField()
+
+ def __init__(self, *args, **kwargs):
+ multiuploader_settings = getattr(settings, "MULTIUPLOADER_FORMS_SETTINGS", DEFAULTS.MULTIUPLOADER_FORMS_SETTINGS)
+
+ form_type = kwargs.pop("form_type", "default")
+
+ options = {
+ 'maxFileSize': multiuploader_settings[form_type]["MAX_FILE_SIZE"],
+ 'acceptFileTypes': format_file_extensions(multiuploader_settings[form_type]["FILE_TYPES"]),
+ 'maxNumberOfFiles': multiuploader_settings[form_type]["MAX_FILE_NUMBER"],
+ 'allowedContentTypes': map(str.lower, multiuploader_settings[form_type]["CONTENT_TYPES"]),
+ 'autoUpload': multiuploader_settings[form_type]["AUTO_UPLOAD"]
+ }
+
+ self._options = options
+ self.options = simplejson.dumps(options)
+
+ super(MultiUploadForm, self).__init__(*args, **kwargs)
+
+ self.fields["file"].widget = forms.FileInput(attrs={'multiple': True})
+
+ def clean_file(self):
+ content = self.cleaned_data[u'file']
+
+ filename, extension = os.path.splitext(content.name)
+
+ if re.match(self._options['acceptFileTypes'], extension, flags=re.I) is None:
+ raise forms.ValidationError('acceptFileTypes')
+
+ content_type = magic.from_buffer(content.read(1024), mime=True)
+
+ if content_type.lower() in self._options['allowedContentTypes']:
+ if content._size > self._options['maxFileSize']:
+ raise forms.ValidationError("maxFileSize")
+ else:
+ raise forms.ValidationError("acceptFileTypes")
+
+ return content
+
+
+class MultiuploaderMultiDeleteForm(forms.Form):
+ id = MultiuploaderField()
Oops, something went wrong.

0 comments on commit 493b8f0

Please sign in to comment.