本文整理匯總了Python中libs.Form.Form.validate方法的典型用法代碼示例。如果您正苦於以下問題:Python Form.validate方法的具體用法?Python Form.validate怎麽用?Python Form.validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libs.Form.Form
的用法示例。
在下文中一共展示了Form.validate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_source_code
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def add_source_code(self):
form = Form(
box_uuid="Please select a box",
price="Please input a price for the source code",
description="Please enter a description",
)
if form.validate(self.request.arguments):
box = Box.by_uuid(self.get_argument('box_uuid'))
if box is not None:
if not 'source_archive' in self.request.files and 0 < len(self.request.files['source_archive']):
self.render('admin/upgrades/source_code_market.html',
errors=["No file data"]
)
else:
try:
price = abs(int(self.get_argument('price', 'NaN')))
self.create_source_code(box, price)
self.render('admin/upgrades/source_code_market.html',
errors=None
)
except ValueError:
self.render('admin/upgrades/source_code_market.html',
errors=["Price must be an integer"]
)
else:
self.render('admin/upgrades/source_code_market.html',
errors=["The selected box does not exist"]
)
else:
self.render('admin/upgrades/source_code_market.html',
errors=form.errors
)
示例2: buyout
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def buyout(self):
''' Buyout and unlock a level '''
form = Form(uuid="Level parameter missing")
user = self.get_current_user()
if form.validate(self.request.arguments):
level = GameLevel.by_uuid(self.get_argument('uuid', ''))
if level is not None and user is not None:
if level.buyout < user.team.money:
logging.info("%s (%s) payed buyout for level #%d" % (
user.handle, user.team.name, level.number
))
user.team.game_levels.append(level)
user.team.money -= level.buyout
dbsession.add(user.team)
event = self.event_manager.create_unlocked_level_event(user, level)
self.new_events.append(event)
self.redirect("/user/missions")
else:
self.render("missions/view.html",
team=user.team,
errors=[
"You do not have enough money to unlock this level"
]
)
else:
self.render("missions/view.html",
team=user.team,
errors=["Level does not exist"]
)
else:
self.render("missions/view.html",
team=user.team,
errors=form.errors
)
示例3: EquipArmorHandler
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
class EquipArmorHandler(UserBaseHandler):
''' This is the handler that allows to equiping of armors from the profile '''
def initialize(self, dbsession):
self.dbsession = dbsession
self.session_manager = SessionManager.Instance()
self.session = self.session_manager.get_session(
self.get_secure_cookie('auth'), self.request.remote_ip)
self.form = Form(
armor_id="You Must Select an Armor"
)
@authenticated
def post(self, *args, **kwargs):
''' Display the default user page '''
user = self.get_current_user()
if self.form.validate(self.request.arguments):
if user != None and self.get_argument('armor_id').isdigit():
new_armor = Armor.by_id(self.get_argument('armor_id'))
# Make sure that we have the weapon they are attemping to equip
if new_armor in user.get_all_armor():
if new_armor.required_level <= user.level:
old_armor = user.equiped_armor
old_armor.equiped = False
new_armor.equiped = True
self.dbsession.add(new_armor)
self.dbsession.add(old_armor)
self.dbsession.flush()
self.redirect('/user')
else:
self.redirect('/user?error=2')
示例4: edit_ipv6
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def edit_ipv6(self):
''' Add ipv6 addresses to a box (sorta edits the box object) '''
form = Form(box_uuid="Select a box", ipv6="Please provide a list of IPv6 addresses")
if form.validate(self.request.arguments):
errors = []
box = Box.by_uuid(self.get_argument('box_uuid'))
if box is not None:
ips_string = self.get_argument('ipv6').replace('\n', ',').lower()
ips = filter(lambda char: char in "1234567890abcdef:,", ips_string).split(",")
for ip in filter(lambda ip: 0 < len(ip), ips):
try:
box = Box.by_ip_address(ip)
if box is None:
addr = IpAddress(box_id=box.id, v6=ip)
dbsession.add(addr)
else:
errors.append(
"%s has already been assigned to %s." % (ip, box.name,)
)
except ValueError:
errors.append(
"'%s' is not a valid IPv6 address" % str(ip[:39])
)
dbsession.flush()
else:
errors.append("Box does not exist")
self.render("admin/view/game_objects.html", errors=errors)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
示例5: post
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def post(self, *args, **kwargs):
''' Creates a job based on the parameters '''
form = Form(
jobname="Please enter a job name",
algorithm_uuid="Please select an algorithm",
hashes="Please provide the target hashes",
)
if form.validate(self.request.arguments):
algo = Algorithm.by_uuid(self.get_argument('algorithm_uuid'))
user = self.get_current_user()
if algo is None:
self.render('cracking/jobs/create.html',
errors=['Invalid algorithm']
)
elif Job.by_job_name(self.get_argument('jobname')) is not None:
self.render('cracking/jobs/create.html',
errors=['Duplicate job name']
)
else:
job = self.create_job(user, algo)
dispatch = Dispatch.Instance()
dispatch.refresh()
self.render("cracking/jobs/created.html", job=job)
else:
self.render('cracking/jobs/create.html', errors=form.errors)
示例6: post
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def post(self, *args, **kwargs):
form = Form(
uuid="Armor not found",
)
if form.validate(self.request.arguments):
user = self.get_current_user()
armor = ArmoryArmor.by_uuid(self.request.arguments['uuid'][0])
if user == None or armor == None:
self.render("store/armor.html", errors=None, armors=ArmoryArmor.get_all_visible())
elif user.gold < armor.cost:
self.render("store/armor.html", errors=['You cannot afford this armor'], armors=ArmoryArmor.get_all_visible())
else:
user.gold -= armor.cost
new_armor = Armor(
user_id=user.id,
name=armor.name,
description=armor.description,
required_level=armor.required_level,
rating=armor.rating,
classification=armor.classification,
avatar=armor.avatar,
)
self.dbsession.add(new_armor)
self.dbsession.add(user)
self.dbsession.flush()
self.render("store/purchase.html", item=armor.name)
else:
self.render("store/armor.html", errors=form.errors, armors=ArmoryArmor.get_all_visible())
示例7: edit_users
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def edit_users(self):
''' Update user objects in the database '''
form = Form(
uuid="User not selected",
account="Please enter an account name",
handle="Please enter a handle name",
hash_algorithm="Please select a hash algorithm",
team_uuid="Please select a team",
)
if form.validate(self.request.arguments):
errors = []
user = User.by_uuid(self.get_argument('uuid'))
if user is not None:
# Update user account name
if user.account != self.get_argument('account'):
if User.by_account(self.get_argument('account')) is None:
logging.info("Updated user account %s -> %s" %
(user.account, self.get_argument('account'),))
user.account = unicode(self.get_argument('account'))
else:
errors.append("Account name is already in use")
# Update user handle
if user.handle != self.get_argument('handle'):
if User.by_handle(self.get_argument('handle')) is None:
logging.info("Updated user handle %s -> %s" %
(user.handle, self.get_argument('handle'),))
user.handle = unicode(self.get_argument('handle'))
else:
errors.append("Handle is already in use")
# Update hashing algoritm
if self.get_argument('hash_algorithm') in user.algorithms:
if user.algorithm != self.get_argument('hash_algorithm'):
if 0 < len(self.get_argument('password', '')):
logging.info("Updated %s's hashing algorithm %s -> %s" %
(user.handle, user.algorithm, self.get_argument('hash_algorithm'),)
)
user.algorithm = self.get_argument('hash_algorithm')
else:
errors.append("You must provide a password when updating the hashing algorithm")
else:
errors.append("Not a valid hash algorithm")
# Update password
if 0 < len(self.get_argument('password', '')):
user.password = self.get_argument('password')
# Update team
team = Team.by_uuid(self.get_argument('team_uuid'))
if team is not None:
if user.team_id != team.id:
logging.info("Updated %s's team %s -> %s" %
(user.handle, user.team_id, team.name))
user.team_id = team.id
else:
errors.append("Team does not exist in database")
dbsession.add(user)
dbsession.flush()
else:
errors.append("User does not exist")
self.render("admin/view/user_objects.html", errors=errors)
else:
self.render("admin/view/user_objects.html", errors=form.errors)
示例8: create_game_level
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def create_game_level(self):
''' Creates a game level '''
form = Form(
level_number="Please enter a level number",
buyout="Please enter a buyout value",
)
if form.validate(self.request.arguments):
try:
game_level = int(self.get_argument('level_number'))
buyout = int(self.get_argument('buyout'))
if game_level <= 0:
self.render('admin/create/game_level.html',
errors=["Level number must be greater than 0"]
)
elif GameLevel.by_number(game_level) is not None:
self.render('admin/create/game_level.html',
errors=["Game level number must be unique"]
)
elif buyout < 0:
self.render('admin/create/game_level.html',
errors=["Invalid buyout value"]
)
else:
self.__mklevel__(game_level, buyout)
self.redirect('/admin/view/game_levels')
except ValueError:
self.render('admin/create/game_level.html',
errors=["Invalid level number"]
)
else:
self.render('admin/create/game_level.html', errors=form.errors)
示例9: edit_corporations
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def edit_corporations(self):
''' Updates corporation object in the database '''
form = Form(
uuid="Object not selected",
name="Missing corporation name",
description="Missing description",
)
if form.validate(self.request.arguments):
corp = Corporation.by_uuid(self.get_argument('uuid'))
if corp is not None:
if self.get_argument('name') != corp.name:
logging.info("Updated corporation name %s -> %s" %
(corp.name, self.get_argument('name'),)
)
corp.name = unicode(self.get_argument('name'))
if self.get_argument('description') != corp.description:
logging.info("Updated corporation description %s -> %s" %
(corp.description, self.get_argument('description'),)
)
corp.description = unicode(self.get_argument('description'))
dbsession.add(corp)
dbsession.flush()
self.redirect('/admin/view/game_objects')
else:
self.render("admin/view/game_objects.html",
errors=["Corporation does not exist"]
)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
示例10: create_flag
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def create_flag(self):
''' Create a flag '''
form = Form(
box_uuid="Please select a box",
flag_name="Please enter a name",
token="Please enter a token value",
reward="Please enter a reward value",
is_file="Please select a file setting",
description="Please enter a flag description",
)
if form.validate(self.request.arguments):
try:
if Flag.by_name(self.get_argument('flag_name')) is not None:
self.render('admin/create/flag.html',
errors=["Name already exists"]
)
elif Flag.by_token(self.get_argument('token')) is not None:
self.render('admin/create/flag.html',
errors=["Token value is not unique"]
)
elif Box.by_uuid(self.get_argument('box_uuid')) is None:
self.render('admin/create/flag.html',
errors=["Box does not exist"]
)
else:
reward = int(self.get_argument('reward', 'NaN'))
self.__mkflag__(reward)
self.redirect('/admin/view/game_objects')
except ValueError:
self.render('admin/create/flag.html',
errors=["Invalid reward value"]
)
else:
self.render("admin/create/flag.html", errors=form.errors)
示例11: post
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def post(self, *args, **kwargs):
''' Creates a new weapon system, and yes the form validation is shit '''
form = Form(
name="Please enter a name",
ssh_user="Please enter an ssh user name",
ssh_key="Please enter an ssh key",
ip_address="Please enter a ip address",
ssh_port="Please enter an ssh port",
service_port="Please enter a service port",
)
if form.validate(self.request.arguments):
if WeaponSystem.by_name(self.get_argument('name')) is not None:
self.render("admin/weaponsystem/create.html",
errors=['That name already exists']
)
elif WeaponSystem.by_ip_address(self.get_argument('ip_address')) is not None:
self.render("admin/weaponsystem/create.html",
errors=['IP Address already in use']
)
else:
try:
if not 1 <= int(self.get_argument('ssh_port', -1)) < 65535:
raise ValueError("SSh port not in range")
if not 1 <= int(self.get_argument('service_port', -1)) < 65535:
raise ValueError("Service port not in range")
weapon_system = self.create_weapon()
self.render("admin/weaponsystem/created.html", errors=None)
except ValueError:
self.render("admin/weaponsystem/create.html",
errors=["Invalid port number; must be 1-65535"]
)
else:
self.render("admin/weaponsystem/create.html", errors=form.errors)
示例12: create_box
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def create_box(self):
''' Create a box object '''
form = Form(
box_name="Enter a box name",
description="Enter a description",
difficulty="Select a difficulty",
corporation_uuid="Please select a corporation",
game_level="Please select a game level",
)
if form.validate(self.request.arguments):
try:
game_level = int(self.get_argument('game_level'))
corp_uuid = self.get_argument('corporation_uuid')
if Box.by_name(self.get_argument('box_name')) is not None:
self.render("admin/create/box.html",
errors=["Box name already exists"]
)
elif Corporation.by_uuid(corp_uuid) is None:
self.render("admin/create/box.html",
errors=["Corporation does not exist"]
)
elif GameLevel.by_number(game_level) is None:
self.render("admin/create/box.html",
errors=["Game level does not exist"]
)
else:
self.__mkbox__()
self.redirect('/admin/view/game_objects')
except ValueError:
self.render('admin/view/create.html',
errors=["Invalid level number"]
)
else:
self.render("admin/create/box.html", errors=form.errors)
示例13: buyout
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def buyout(self):
''' Buyout and unlock a level '''
form = Form(uuid="Level parameter missing")
user = self.get_current_user()
if form.validate(self.request.arguments):
level = GameLevel.by_uuid(self.get_argument('uuid', ''))
if level is not None and user is not None:
if level.buyout < user.team.money:
user.team.game_levels.append(level)
user.team.money -= level.buyout
dbsession.add(user.team)
self.event_manager.unlocked_level(user, level)
self.redirect("/user/missions")
else:
self.render("missions/view.html",
team=user.team,
errors=[
"You do not have enough money to unlock this level"
]
)
else:
self.render("missions/view.html",
team=user.team,
errors=["Level does not exist"]
)
else:
self.render("missions/view.html",
team=user.team,
errors=form.errors
)
示例14: post
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def post(self, *args, **kwargs):
''' Attempt to upgrade hash algo '''
form = Form(
old_password="Enter your existing password",
new_password1="Enter a new password",
new_password2="Confirm your new password",
)
if form.validate(self.request.arguments):
user = self.get_current_user()
passwd = self.get_argument('new_password1')
old_passwd = self.get_argument('old_password')
if not user.validate_password(old_passwd):
self.render_page(["Invalid password"])
elif not passwd == self.get_argument('new_password2'):
self.render_page(["New passwords do not match"])
elif user.team.money < self.config.password_upgrade:
self.render_page(["You cannot afford to upgrade your hash"])
elif len(passwd) <= self.config.max_password_length:
user.team.money -= self.config.password_upgrade
dbsession.add(user.team)
dbsession.flush()
self.update_password(passwd)
self.render_page()
else:
self.render_page(["New password is too long"])
else:
self.render_page(form.errors)
示例15: post
# 需要導入模塊: from libs.Form import Form [as 別名]
# 或者: from libs.Form.Form import validate [as 別名]
def post(self, *args, **kwargs):
''' Attempts to create an account '''
form = Form(
username="Please enter a username",
pass1="Please enter a password",
pass2="Please confirm your password",
recaptcha_challenge_field="Invalid captcha",
recaptcha_response_field="Invalid captcha",
)
if not form.validate(self.request.arguments):
self.render("public/registration.html", errors=form.errors)
elif self.check_recaptcha():
user_name = self.get_argument('username')
if User.by_user_name(user_name) != None:
self.render('public/registration.html',
errors=['Account name already taken'])
elif len(user_name) < 3 or 15 < len(user_name):
self.render('public/registration.html',
errors=['Username must be 3-15 characters'])
elif not self.get_argument('pass1') == self.get_argument('pass2'):
self.render('public/registration.html',
errors=['Passwords do not match'])
elif not (12 <= len(self.get_argument('pass1')) <= 100):
self.render('public/registration.html',
errors=['Password must be 12-100 characters'])
else:
user = self.create_user(user_name, self.get_argument('pass1'))
self.render(
"public/account_created.html", user_name=user.user_name)
else:
self.render("public/registration.html",
errors=['Invalid captcha'])