diff --git a/ajax_upload/static/ajax_upload/js/ajax-upload-widget.js b/ajax_upload/static/ajax_upload/js/ajax-upload-widget.js index 6411266..dda78f0 100644 --- a/ajax_upload/static/ajax_upload/js/ajax-upload-widget.js +++ b/ajax_upload/static/ajax_upload/js/ajax-upload-widget.js @@ -5,6 +5,7 @@ var AjaxUploadWidget = global.AjaxUploadWidget = function(element, options) { this.options = { + hideInput: false, changeButtonText: 'Change', removeButtonText: 'Remove', previewAreaClass: 'ajax-upload-preview-area', @@ -48,8 +49,14 @@ this.$changeButton = $('') .text(this.options.changeButtonText) .on('click', function(evt) { - self.$element.show(); - $(this).hide(); + if(self.options.hideInput){ + self.$element.hide(); + self.$element.trigger('click'); + } + else{ + self.$element.show(); + $(this).hide(); + } }); this.$element.after(this.$changeButton); @@ -133,9 +140,15 @@ this.$element.hide(); } else { this.$previewArea.slideUp(); - this.$changeButton.hide(); this.$removeButton.hide(); - this.$element.show(); + if(this.options.hideInput){ + this.$changeButton.show(); + this.$element.hide(); + } + else{ + this.$changeButton.hide(); + this.$element.show(); + } } }; diff --git a/ajax_upload/widgets.py b/ajax_upload/widgets.py index 2aaa1c3..71227f4 100644 --- a/ajax_upload/widgets.py +++ b/ajax_upload/widgets.py @@ -1,6 +1,7 @@ from django import forms from django.conf import settings from django.core.files import File +from django.core.files.storage import DefaultStorage from django.core.urlresolvers import reverse from django.utils.safestring import mark_safe from django.utils.translation import ugettext as _ @@ -43,6 +44,8 @@ def value_from_datadict(self, data, files, name): elif file_path.startswith(settings.MEDIA_URL): # Strip and media url to determine the path relative to media root relative_path = file_path[len(settings.MEDIA_URL):] + if not relative_path.startswith('ajax_uploads'): + return None try: uploaded_file = UploadedFile.objects.get(file=relative_path) except UploadedFile.DoesNotExist: