Skip to content

[FIX] First commit on adoption, compatible with django 2.1+, python 3.6+ #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ajax_upload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Provides AJAX file upload functionality for FileFields and ImageFields with a simple widget replacement in the form."""

VERSION = (0, 5, 5)
VERSION = (0, 5, 6)

__version__ = '.'.join(map(str, VERSION))
2 changes: 1 addition & 1 deletion ajax_upload/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class UploadedFileAdmin(admin.ModelAdmin):
list_display = ('__unicode__',)
list_display = ('__str__',)
date_hierarchy = 'creation_date'
search_fields = ('file',)

Expand Down
Empty file.
4 changes: 2 additions & 2 deletions ajax_upload/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Meta:
verbose_name = _('uploaded file')
verbose_name_plural = _('uploaded files')

def __unicode__(self):
return unicode(self.file)
def __str__(self):
return f"{self.file}"

def delete(self, *args, **kwargs):
super(UploadedFile, self).delete(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions ajax_upload/static/ajax_upload/js/ajax-upload-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
this.$element.on('change', function(evt) {
self.upload();
});
this.$changeButton = $('<button type="button" class="btn-change"></button>')
this.$changeButton = $('<button type="button" class="btn btn-change"></button>')
.text(this.options.changeButtonText)
.on('click', function(evt) {
self.$element.show();
$(this).hide();
});
this.$element.after(this.$changeButton);

this.$removeButton = $('<button type="button" class="btn-remove"></button>')
this.$removeButton = $('<button type="button" class="btn btn-remove"></button>')
.text(this.options.removeButtonText)
.on('click', function(evt) {
if(self.options.onRemove) {
Expand Down
2 changes: 1 addition & 1 deletion ajax_upload/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_submit_form_with_external_file_path_returns_error(self):
}
try:
self.client.post(reverse('ajax-uploads-test'), post_data)
except AjaxUploadException, err:
except AjaxUploadException as err:
self.assertTrue(str(err).startswith(_('File path not allowed:')))
else:
self.fail()
Expand Down
9 changes: 5 additions & 4 deletions ajax_upload/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf.urls import patterns, url
from django.conf.urls import url
from ajax_upload.views import upload


urlpatterns = patterns('ajax_upload.views',
url(r'^$', 'upload', name='ajax-upload'),
)
urlpatterns = [
url(r'^$', upload, name='ajax-upload'),
]
8 changes: 4 additions & 4 deletions ajax_upload/widgets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django import forms
from django.conf import settings
from django.core.files import File
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

import urllib2
from urllib import parse

from ajax_upload.models import UploadedFile

Expand All @@ -18,7 +18,7 @@ class AjaxClearableFileInput(forms.ClearableFileInput):
template_with_clear = '' # We don't need this
template_with_initial = '%(input)s'

def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):
attrs = attrs or {}
if value:
filename = u'%s%s' % (settings.MEDIA_URL, value)
Expand All @@ -45,7 +45,7 @@ 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 url base
relative_path = file_path[len(settings.MEDIA_URL):]
relative_path = urllib2.unquote(relative_path.encode('utf8')).decode('utf8')
relative_path = parse.unquote(relative_path)
try:
uploaded_file = UploadedFile.objects.get(file=relative_path)
except UploadedFile.DoesNotExist:
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Framework :: Django',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Topic :: Software Development'
],
author='Zach Mathew',
Expand Down