Mercurial > kallithea
comparison pylons_app/model/forms.py @ 388:3bcf9529d221
Added new application settings,Push ssl and repositories path
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 05 Aug 2010 22:31:23 +0200 |
parents | 55377fdc1fc6 |
children | e8af467b5a60 |
comparison
equal
deleted
inserted
replaced
387:2a18192fbd1e | 388:3bcf9529d221 |
---|---|
23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ | 23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ |
24 Email, Bool, StringBoolean | 24 Email, Bool, StringBoolean |
25 from pylons import session | 25 from pylons import session |
26 from pylons.i18n.translation import _ | 26 from pylons.i18n.translation import _ |
27 from pylons_app.lib.auth import get_crypt_password | 27 from pylons_app.lib.auth import get_crypt_password |
28 import pylons_app.lib.helpers as h | |
29 from pylons_app.model import meta | 28 from pylons_app.model import meta |
30 from pylons_app.model.db import User, Repository | 29 from pylons_app.model.db import User, Repository |
31 from sqlalchemy.exc import OperationalError | 30 from sqlalchemy.exc import OperationalError |
32 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound | 31 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound |
33 from webhelpers.pylonslib.secure_form import authentication_token | 32 from webhelpers.pylonslib.secure_form import authentication_token |
34 import datetime | 33 import datetime |
35 import formencode | 34 import formencode |
36 import logging | 35 import logging |
36 import os | |
37 import pylons_app.lib.helpers as h | |
37 log = logging.getLogger(__name__) | 38 log = logging.getLogger(__name__) |
38 | 39 |
39 | 40 |
40 #this is needed to translate the messages using _() in validators | 41 #this is needed to translate the messages using _() in validators |
41 class State_obj(object): | 42 class State_obj(object): |
216 def to_python(self, value, state): | 217 def to_python(self, value, state): |
217 #settings form can't edit user | 218 #settings form can't edit user |
218 if value.has_key('user'): | 219 if value.has_key('user'): |
219 del['value']['user'] | 220 del['value']['user'] |
220 | 221 |
221 return value | 222 return value |
223 | |
224 class ValidPath(formencode.validators.FancyValidator): | |
225 def to_python(self, value, state): | |
226 isdir = os.path.isdir(value.replace('*', '')) | |
227 if (value.endswith('/*') or value.endswith('/**')) and isdir: | |
228 return value | |
229 elif not isdir: | |
230 msg = _('This is not a valid path') | |
231 else: | |
232 msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)') | |
233 | |
234 raise formencode.Invalid(msg, value, state, | |
235 error_dict={'paths_root_path':msg}) | |
236 | |
222 #=============================================================================== | 237 #=============================================================================== |
223 # FORMS | 238 # FORMS |
224 #=============================================================================== | 239 #=============================================================================== |
225 class LoginForm(formencode.Schema): | 240 class LoginForm(formencode.Schema): |
226 allow_extra_fields = True | 241 allow_extra_fields = True |
300 hg_app_title = UnicodeString(strip=True, min=3, not_empty=True) | 315 hg_app_title = UnicodeString(strip=True, min=3, not_empty=True) |
301 hg_app_realm = UnicodeString(strip=True, min=3, not_empty=True) | 316 hg_app_realm = UnicodeString(strip=True, min=3, not_empty=True) |
302 | 317 |
303 return _ApplicationSettingsForm | 318 return _ApplicationSettingsForm |
304 | 319 |
305 | 320 def ApplicationUiSettingsForm(): |
306 | 321 class _ApplicationUiSettingsForm(formencode.Schema): |
322 allow_extra_fields = True | |
323 filter_extra_fields = False | |
324 web_push_ssl = OneOf(['true', 'false'], if_missing='false') | |
325 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=3, not_empty=True)) | |
326 | |
327 return _ApplicationUiSettingsForm | |
328 |