from django import forms
from django.core.exceptions import ValidationError
-from django.utils.http import urlquote
from filex.models import Favorite
from filex.utils import host_validator, path_validator, name_validator
-def clean_path(path):
- return urlquote(os.path.normpath(path), safe='/~')
-
-
class FavoriteForm(forms.ModelForm):
class Meta:
model = Favorite
path = forms.CharField(label=u'Ścieżka', max_length=1024, validators=[path_validator], widget=forms.HiddenInput())
def clean_path(self):
- return clean_path(self.cleaned_data['path'])
+ return os.path.normpath(self.cleaned_data['path'])
class HostPathNameForm(HostPathForm):
name = forms.CharField(label=u'Nazwa', max_length=256, validators=[name_validator])
def clean_name(self):
- return clean_path(self.cleaned_data['name'])
+ return os.path.normpath(self.cleaned_data['name'])
class HostItemsForm(HostForm):
e.message += ' - ' + name
errors.append(e)
else:
- cleaned.append(clean_path(name))
+ cleaned.append(os.path.normpath(name))
if errors:
raise ValidationError(errors)
dst = forms.CharField(label=u'Nowa nazwa', max_length=1024, validators=[path_validator])
def clean_src(self):
- return clean_path(self.cleaned_data['src'])
+ return os.path.normpath(self.cleaned_data['src'])
def clean_dst(self):
- return clean_path(self.cleaned_data['dst'])
+ return os.path.normpath(self.cleaned_data['dst'])
class ExtractForm(HostPathForm):
dst = forms.CharField(label=u'Katalog docelowy', max_length=1024, validators=[path_validator])
def clean_dst(self):
- return clean_path(self.cleaned_data['dst'])
+ return os.path.normpath(self.cleaned_data['dst'])
class CompressForm(HostPathForm):
e.message += ' - ' + name
errors.append(e)
else:
- cleaned.append(clean_path(name))
+ cleaned.append(os.path.normpath(name))
if errors:
raise ValidationError(errors)
return cleaned
def clean_archive(self):
- return clean_path(self.cleaned_data['archive'])
+ return os.path.normpath(self.cleaned_data['archive'])
class ArchiveForm(CompressForm):