fix processing user defined choices in job templates
[qcg-portal.git] / filex / forms.py
index 17563b5..4f7c8dd 100644 (file)
@@ -3,17 +3,10 @@ import os
 
 from django import forms
 from django.core.exceptions import ValidationError
-from django.core.validators import RegexValidator
 from django.utils.http import urlquote
 
 from filex.models import Favorite
-
-
-msg = u'Invalid value'
-host_validator = RegexValidator(r'^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+'
-                                r'(?:[a-zA-Z]{2,6}\.?|[a-zA-Z0-9-]{2,}(?<!-)\.?))(?::\d+)?$', msg)
-path_validator = RegexValidator(r'^~?(?:/[^/\0]*)*$', msg)
-name_validator = RegexValidator(r'^[^/\0]+$', msg)
+from filex.utils import host_validator, path_validator, name_validator
 
 
 def clean_path(path):
@@ -26,6 +19,9 @@ class FavoriteForm(forms.ModelForm):
         fields = ('owner', 'host', 'path')
         widgets = {'owner': forms.HiddenInput()}
 
+    def clean_path(self):
+        return os.path.normpath(self.cleaned_data['path'])
+
 
 class HostForm(forms.Form):
     host = forms.CharField(label=u'Host', max_length=256, validators=[host_validator], widget=forms.HiddenInput())