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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-02-23 08:48:09 UTC
  • mfrom: (1673 trunk)
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: grantw@unimelb.edu.au-20100223084809-du6dvsxrjhw15ytr
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
18
import re
19
 
import datetime
20
19
 
21
20
import formencode
22
21
import formencode.validators
107
106
            ctx['error_value'] = errors
108
107
 
109
108
 
110
 
VALID_URL_NAME = re.compile(r'^[a-z0-9][a-z0-9_\+\.\-]*$')
 
109
VALID_URL_NAME = re.compile(r'^[a-z0-9][a-z0-9\+\.\-]*$')
111
110
 
112
111
 
113
112
class URLNameValidator(formencode.validators.UnicodeString):
115
114
        super(URLNameValidator, self).validate_python(value, state)
116
115
        if not VALID_URL_NAME.match(value):
117
116
            raise formencode.Invalid(
118
 
                'Must consist of a lowercase alphanumeric character followed '
119
 
                'by any number of lowercase alphanumerics, ., +, - or _.',
 
117
                'Must consist of an alphanumeric character followed by any '
 
118
                'number of alphanumerics, ., + or -.',
120
119
                value, state)
121
 
 
122
 
class DateTimeValidator(formencode.validators.FancyValidator):
123
 
    """Accepts a date/time in YYYY-MM-DD HH:MM:SS format. Converts to a
124
 
    datetime.datetime object."""
125
 
    def _to_python(self, value, state):
126
 
        """Validate and convert."""
127
 
        try:
128
 
            return datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
129
 
        except ValueError, e:
130
 
            raise formencode.Invalid("Must be a timestamp in "
131
 
                "YYYY-MM-DD HH:MM:SS format", value, state)
132
 
    def _from_python(self, value, state):
133
 
        try:
134
 
            return value.strftime("%Y-%m-%d %H:%M:%S")
135
 
        except AttributeError:
136
 
            raise formencode.Invalid("Must be a datetime.datetime object")