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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2010-02-12 04:00:39 UTC
  • Revision ID: matt.giuca@gmail.com-20100212040039-vw9yf8p4s98g6nu9
Added an argument 'config' to every single get_permissions method throughout the program. All calls to get_permissions pass a config. This is to allow per-site policy configurations on permissions.

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
 
import datetime
20
 
 
21
18
import formencode
22
 
import formencode.validators
23
19
from genshi.filters import HTMLFormFiller
24
20
 
25
21
from ivle.webapp.base.xhtml import XHTMLView
26
22
 
27
 
 
28
23
class BaseFormView(XHTMLView):
29
24
    """A base form view."""
30
25
 
31
26
    @property
32
27
    def validator(self):
33
 
        """The FormEncode validator to use.
34
 
 
35
 
        The request will be passed in as state, after potentially being
36
 
        modified by populate_state().
37
 
        """
 
28
        """The FormEncode validator to use."""
38
29
        raise NotImplementedError()
39
30
 
40
31
    def populate_state(self, state):
107
98
            ctx['error_value'] = errors
108
99
 
109
100
 
110
 
VALID_URL_NAME = re.compile(r'^[a-z0-9][a-z0-9_\+\.\-]*$')
111
 
 
112
 
 
113
 
class URLNameValidator(formencode.validators.UnicodeString):
114
 
    def validate_python(self, value, state):
115
 
        super(URLNameValidator, self).validate_python(value, state)
116
 
        if not VALID_URL_NAME.match(value):
117
 
            raise formencode.Invalid(
118
 
                'Must consist of a lowercase alphanumeric character followed '
119
 
                'by any number of lowercase alphanumerics, ., +, - or _.',
120
 
                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")