##// END OF EJS Templates
some small template fixes
some small template fixes

File last commit:

r395:e8af467b default
r409:9b6c1de4 default
Show More
forms.py
330 lines | 13.9 KiB | text/x-python | PythonLexer
Marcin Kuzminski
initial commit.
r0 """ this is forms validation classes
http://formencode.org/module-formencode.validators.html
for list off all availible validators
we can create our own validators
The table below outlines the options which can be used in a schema in addition to the validators themselves
pre_validators [] These validators will be applied before the schema
chained_validators [] These validators will be applied after the schema
allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
filter_extra_fields False If True, then keys that aren't associated with a validator are removed
if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
<name> = formencode.validators.<name of validator>
<name> must equal form name
list=[1,2,3,4,5]
fixed menu in home page, and added login html with forms that validates username and password.
r186 for SELECT use formencode.All(OneOf(list), Int())
Marcin Kuzminski
initial commit.
r0
"""
Added lastlogin to user after login, model db update
r242 from formencode import All
Rewrite of user managment, improved forms, added some user info
r238 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \
Email, Bool, StringBoolean
fixed menu in home page, and added login html with forms that validates username and password.
r186 from pylons import session
from pylons.i18n.translation import _
from pylons_app.lib.auth import get_crypt_password
from pylons_app.model import meta
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 from pylons_app.model.db import User, Repository
fixed menu in home page, and added login html with forms that validates username and password.
r186 from sqlalchemy.exc import OperationalError
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from webhelpers.pylonslib.secure_form import authentication_token
Added lastlogin to user after login, model db update
r242 import datetime
Marcin Kuzminski
initial commit.
r0 import formencode
fixed menu in home page, and added login html with forms that validates username and password.
r186 import logging
Added new application settings,Push ssl and repositories path
r388 import os
import pylons_app.lib.helpers as h
fixed menu in home page, and added login html with forms that validates username and password.
r186 log = logging.getLogger(__name__)
Marcin Kuzminski
initial commit.
r0
fixed menu in home page, and added login html with forms that validates username and password.
r186 #this is needed to translate the messages using _() in validators
class State_obj(object):
_ = staticmethod(_)
#===============================================================================
# VALIDATORS
#===============================================================================
Marcin Kuzminski
initial commit.
r0 class ValidAuthToken(formencode.validators.FancyValidator):
messages = {'invalid_token':_('Token mismatch')}
def validate_python(self, value, state):
if value != authentication_token():
fixed menu in home page, and added login html with forms that validates username and password.
r186 raise formencode.Invalid(self.message('invalid_token', state,
search_number=value), value, state)
Added extra validation in creating users....
r357
def ValidUsername(edit, old_data):
class _ValidUsername(formencode.validators.FancyValidator):
def validate_python(self, value, state):
if value in ['default', 'new_user']:
raise formencode.Invalid(_('Invalid username'), value, state)
#check if user is uniq
sa = meta.Session
old_un = None
if edit:
old_un = sa.query(User).get(old_data.get('user_id')).username
if old_un != value or not edit:
if sa.query(User).filter(User.username == value).scalar():
raise formencode.Invalid(_('This username already exists') ,
value, state)
meta.Session.remove()
return _ValidUsername
Rewrite of user managment, improved forms, added some user info
r238
class ValidPassword(formencode.validators.FancyValidator):
def to_python(self, value, state):
fixed bug for user update, when password was always set.
r347 if value:
return get_crypt_password(value)
Rewrite of user managment, improved forms, added some user info
r238
fixed menu in home page, and added login html with forms that validates username and password.
r186 class ValidAuth(formencode.validators.FancyValidator):
messages = {
'invalid_password':_('invalid password'),
'invalid_login':_('invalid user name'),
'disabled_account':_('Your acccount is disabled')
}
#error mapping
e_dict = {'username':messages['invalid_login'],
'password':messages['invalid_password']}
CHanged form error when user account is disabled.
r227 e_dict_disable = {'username':messages['disabled_account']}
fixed menu in home page, and added login html with forms that validates username and password.
r186
def validate_python(self, value, state):
sa = meta.Session
crypted_passwd = get_crypt_password(value['password'])
username = value['username']
try:
changed naming convention for db modules.
r234 user = sa.query(User).filter(User.username == username).one()
fixed menu in home page, and added login html with forms that validates username and password.
r186 except (NoResultFound, MultipleResultsFound, OperationalError) as e:
log.error(e)
user = None
Rewrite of user managment, improved forms, added some user info
r238 raise formencode.Invalid(self.message('invalid_password',
state=State_obj), value, state,
error_dict=self.e_dict)
fixed menu in home page, and added login html with forms that validates username and password.
r186 if user:
if user.active:
if user.username == username and user.password == crypted_passwd:
from pylons_app.lib.auth import AuthUser
auth_user = AuthUser()
auth_user.username = username
auth_user.is_authenticated = True
auth_user.is_admin = user.admin
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 auth_user.user_id = user.user_id
added session remove in forms, and added name and lastname to auth user
r355 auth_user.name = user.name
auth_user.lastname = user.lastname
fixed menu in home page, and added login html with forms that validates username and password.
r186 session['hg_app_user'] = auth_user
session.save()
logging info change on login form
r201 log.info('user %s is now authenticated', username)
Added lastlogin to user after login, model db update
r242
try:
user.last_login = datetime.datetime.now()
sa.add(user)
sa.commit()
except (OperationalError) as e:
log.error(e)
sa.rollback()
fixed menu in home page, and added login html with forms that validates username and password.
r186 return value
else:
log.warning('user %s not authenticated', username)
raise formencode.Invalid(self.message('invalid_password',
state=State_obj), value, state,
error_dict=self.e_dict)
else:
log.warning('user %s is disabled', username)
raise formencode.Invalid(self.message('disabled_account',
state=State_obj),
CHanged form error when user account is disabled.
r227 value, state,
error_dict=self.e_dict_disable)
fixed menu in home page, and added login html with forms that validates username and password.
r186
Added new style error display,...
r356 meta.Session.remove()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 class ValidRepoUser(formencode.validators.FancyValidator):
def to_python(self, value, state):
sa = meta.Session
try:
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
r328 self.user_db = sa.query(User)\
.filter(User.active == True)\
.filter(User.username == value).one()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 except Exception:
raise formencode.Invalid(_('This username is not valid'),
value, state)
Added new style error display,...
r356 meta.Session.remove()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 return self.user_db.user_id
Added new style error display,...
r356 def ValidRepoName(edit, old_data):
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 class _ValidRepoName(formencode.validators.FancyValidator):
def to_python(self, value, state):
slug = h.repo_name_slug(value)
fixed bug when user is capable of creating _admin repository which is a link to admin interface
r310 if slug in ['_admin']:
raise formencode.Invalid(_('This repository name is disallowed'),
value, state)
Added new style error display,...
r356 if old_data.get('repo_name') != value or not edit:
sa = meta.Session
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems....
r367 if sa.query(Repository).filter(Repository.repo_name == slug).scalar():
Added new style error display,...
r356 raise formencode.Invalid(_('This repository already exists') ,
value, state)
meta.Session.remove()
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 return slug
Added new style error display,...
r356
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 return _ValidRepoName
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296
class ValidPerms(formencode.validators.FancyValidator):
messages = {'perm_new_user_name':_('This username is not valid')}
def to_python(self, value, state):
perms_update = []
perms_new = []
#build a list of permission to update and new permission to create
for k, v in value.items():
if k.startswith('perm_'):
if k.startswith('perm_new_user'):
new_perm = value.get('perm_new_user', False)
new_user = value.get('perm_new_user_name', False)
if new_user and new_perm:
if (new_user, new_perm) not in perms_new:
perms_new.append((new_user, new_perm))
else:
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes....
r299 usr = k[5:]
if usr == 'default':
if value['private']:
#set none for default when updating to private repo
v = 'repository.none'
perms_update.append((usr, v))
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 value['perms_updates'] = perms_update
value['perms_new'] = perms_new
sa = meta.Session
for k, v in perms_new:
try:
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
r328 self.user_db = sa.query(User)\
.filter(User.active == True)\
.filter(User.username == k).one()
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 except Exception:
msg = self.message('perm_new_user_name',
state=State_obj)
raise formencode.Invalid(msg, value, state, error_dict={'perm_new_user_name':msg})
return value
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
r320
class ValidSettings(formencode.validators.FancyValidator):
def to_python(self, value, state):
#settings form can't edit user
if value.has_key('user'):
del['value']['user']
Added new application settings,Push ssl and repositories path
r388 return value
class ValidPath(formencode.validators.FancyValidator):
def to_python(self, value, state):
isdir = os.path.isdir(value.replace('*', ''))
if (value.endswith('/*') or value.endswith('/**')) and isdir:
return value
elif not isdir:
msg = _('This is not a valid path')
else:
msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)')
raise formencode.Invalid(msg, value, state,
error_dict={'paths_root_path':msg})
fixed menu in home page, and added login html with forms that validates username and password.
r186 #===============================================================================
# FORMS
#===============================================================================
implemented admin page login
r45 class LoginForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
username = UnicodeString(
strip=True,
min=3,
not_empty=True,
messages={
'empty':_('Please enter a login'),
'tooShort':_('Enter a value %(min)i characters long or more')}
)
Marcin Kuzminski
initial commit.
r0
implemented admin page login
r45 password = UnicodeString(
strip=True,
min=3,
not_empty=True,
messages={
'empty':_('Please enter a password'),
'tooShort':_('Enter a value %(min)i characters long or more')}
)
Marcin Kuzminski
initial commit.
r0
fixed menu in home page, and added login html with forms that validates username and password.
r186 #chained validators have access to all data
chained_validators = [ValidAuth]
Added extra validation in creating users....
r357 def UserForm(edit=False, old_data={}):
Rewrite of user managment, improved forms, added some user info
r238 class _UserForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
Added extra validation in creating users....
r357 username = All(UnicodeString(strip=True, min=3, not_empty=True), ValidUsername(edit, old_data))
Rewrite of user managment, improved forms, added some user info
r238 if edit:
new_password = All(UnicodeString(strip=True, min=3, not_empty=False), ValidPassword)
added admin flag to users editing
r329 admin = StringBoolean(if_missing=False)
Rewrite of user managment, improved forms, added some user info
r238 else:
Added extra validation in creating users....
r357 password = All(UnicodeString(strip=True, min=8, not_empty=True), ValidPassword)
Rewrite of user managment, improved forms, added some user info
r238 active = StringBoolean(if_missing=False)
name = UnicodeString(strip=True, min=3, not_empty=True)
lastname = UnicodeString(strip=True, min=3, not_empty=True)
email = Email(not_empty=True)
return _UserForm
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265
Added user registration, changed login url schema, moved it into _admin/ for safety
r363 RegisterForm = UserForm
Added new style error display,...
r356 def RepoForm(edit=False, old_data={}):
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 class _RepoForm(formencode.Schema):
allow_extra_fields = True
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 filter_extra_fields = False
Added new style error display,...
r356 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 description = UnicodeString(strip=True, min=3, not_empty=True)
private = StringBoolean(if_missing=False)
if edit:
user = All(Int(not_empty=True), ValidRepoUser)
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
r296 chained_validators = [ValidPerms]
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 return _RepoForm
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
r320
Added new style error display,...
r356 def RepoSettingsForm(edit=False, old_data={}):
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
r320 class _RepoForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
Added new style error display,...
r356 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
r320 description = UnicodeString(strip=True, min=3, not_empty=True)
private = StringBoolean(if_missing=False)
chained_validators = [ValidPerms, ValidSettings]
return _RepoForm
Added application settings, are now customizable from database...
r350 def ApplicationSettingsForm():
class _ApplicationSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
cleared global application settings....
r381 hg_app_title = UnicodeString(strip=True, min=3, not_empty=True)
hg_app_realm = UnicodeString(strip=True, min=3, not_empty=True)
Added application settings, are now customizable from database...
r350
return _ApplicationSettingsForm
Added new application settings,Push ssl and repositories path
r388 def ApplicationUiSettingsForm():
class _ApplicationUiSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
web_push_ssl = OneOf(['true', 'false'], if_missing='false')
paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=3, not_empty=True))
Added hooks managment into application settings
r395 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False)
hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False)
Added new application settings,Push ssl and repositories path
r388
return _ApplicationUiSettingsForm
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
r320