Skip to content
Open
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
9 changes: 7 additions & 2 deletions ajax_upload/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.translation import ugettext as _

import urllib2
import urlparse

from ajax_upload.models import UploadedFile

Expand Down Expand Up @@ -42,9 +43,13 @@ def value_from_datadict(self, data, files, name):
file_path = data.get(name)
if not file_path:
return False # False means clear the existing file
elif file_path.startswith(settings.MEDIA_URL):

parsed_file_url = urlparse.urlparse(file_path)
parsed_media_url = urlparse.urlparse(settings.MEDIA_URL)

if parsed_file_url.hostname == parsed_media_url.hostname:
# Strip and media url to determine the path relative to media url base
relative_path = file_path[len(settings.MEDIA_URL):]
relative_path = parsed_file_url.path[len(parsed_media_url.path):]
relative_path = urllib2.unquote(relative_path.encode('utf8')).decode('utf8')
try:
uploaded_file = UploadedFile.objects.get(file=relative_path)
Expand Down