~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/forms.py

Merge enforce-naming-constraints. Users, subjects, semesters, projects, groups exercises and worksheets now have restricted name character sets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
 
18
import re
 
19
 
18
20
import formencode
 
21
import formencode.validators
19
22
from genshi.filters import HTMLFormFiller
20
23
 
21
24
from ivle.webapp.base.xhtml import XHTMLView
22
25
 
 
26
 
23
27
class BaseFormView(XHTMLView):
24
28
    """A base form view."""
25
29
 
102
106
            ctx['error_value'] = errors
103
107
 
104
108
 
 
109
VALID_URL_NAME = re.compile(r'^[a-z0-9][a-z0-9_\+\.\-]*$')
 
110
 
 
111
 
 
112
class URLNameValidator(formencode.validators.UnicodeString):
 
113
    def validate_python(self, value, state):
 
114
        super(URLNameValidator, self).validate_python(value, state)
 
115
        if not VALID_URL_NAME.match(value):
 
116
            raise formencode.Invalid(
 
117
                'Must consist of a lowercase alphanumeric character followed '
 
118
                'by any number of lowercase alphanumerics, ., +, - or _.',
 
119
                value, state)