From 2434b5d434f7e086ff26bdc85ead11da8dff1769 Mon Sep 17 00:00:00 2001 From: Thomas Wajs Date: Thu, 19 Feb 2015 17:15:08 +0100 Subject: [PATCH] Replace system-specific path separator by a slash on file urls --- .../plugins/form_elements/fields/file/fobi_form_elements.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py index 8ed98e25..4b540710 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py @@ -4,6 +4,8 @@ __copyright__ = 'Copyright (c) 2014 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('FileInputPlugin',) +import os + from django.forms.fields import FileField from django.forms.widgets import ClearableFileInput from django.utils.translation import ugettext_lazy as _ @@ -56,7 +58,8 @@ class FileInputPlugin(FormFieldPlugin): # Handle the upload saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path) # Overwrite ``cleaned_data`` of the ``form`` with path to moved file. - form.cleaned_data[self.data.name] = "{0}{1}".format(settings.MEDIA_URL, saved_file) + file_relative_url = saved_file.replace(os.path.sep, '/') + form.cleaned_data[self.data.name] = "{0}{1}".format(settings.MEDIA_URL, file_relative_url) # It's critically important to return the ``form`` with updated ``cleaned_data`` return form