473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

validationform

hi,
i am doing a validation for joining form .
when i write the code in python script
Expand|Select|Wrap|Line Numbers
  1. ## Script (Python) "join_form_validate"
  2. ##bind container=container
  3. ##bind context=context
  4. ##bind namespace=
  5. ##bind script=script
  6. ##bind state=state
  7. ##bind subpath=traverse_subpath
  8. ##parameters=username='',email='',password='',password_confirm=''
  9. ##title=validates the Registration of a User
  10. ##
  11. from Products.CMFPlone import PloneMessageFactory as _
  12.  
  13. reg_tool=context.portal_registration
  14. def missing(field):
  15.     state.setError(field, _(u'This field is required, please provide some information.'), 'input_required')
  16. def nomatch(field):
  17.     state.setError(field, _(u'Passwords do not match.'), 'nomatch_password')
  18. def minlimit(field):
  19.     state.setError(field, _(u'Passwords must contain at least 5 letters.'), 'min_password')
  20. def notallowed(field):
  21.     state.setError(field, _(u'This username is reserved. Please choose a different name.'), 'not_allowed')
  22.  
  23. if not username:
  24.     missing('username')
  25. if not email:
  26.     missing('email')
  27. if username and username == context.portal_url.getPortalObject().getId():
  28.     notallowed('username')
  29.  
  30. properties = context.portal_properties.site_properties
  31. if not properties.validate_email:
  32.      if password!=password_confirm:
  33.          nomatch('password')
  34.          nomatch('password_confirm')
  35.  
  36.      if not password:
  37.          missing('password')
  38.      if not password_confirm:
  39.          missing('password_confirm')
  40.  
  41.      if not state.getError('password') and len(password) < 5:
  42.          minlimit('password')
  43.          minlimit('password_confirm')
  44.  
  45. if not state.getError('username') and not reg_tool.isMemberIdAllowed(username):
  46.     state.setError('username',
  47.                    _(u'The login name you selected is already in use or is not valid. Please choose another.'),
  48.                    'username_invalid' )
  49.  
  50. if state.getErrors():
  51.     context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
  52.     return state.set(status='failure')
  53. else:
  54.     context.plone_utils.addPortalMessage(_(u'You have been registered.'))
  55.     return state
  56.  
the error is
Error Type:
KeyError

Error Value:
'bind state
Feb 23 '07 #1
1 1114
bartonc
6,596 Expert 4TB
I don't see the import for context.. What module is that name coming from?
Feb 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: raj | last post by:
hi, i have one textbox and one save button, i have added attribute at page load event btnSave.Attributes.Add("onclick","return ValidateForm();"); in validationform() ,I have written like this...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.