Changeset 3168 in products for quintagroup.pfg.captcha
- Timestamp:
- Apr 21, 2011 1:43:09 PM (13 years ago)
- Location:
- quintagroup.pfg.captcha/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/__init__.py
r2095 r3168 2 2 from Products.Archetypes.atapi import process_types, listTypes 3 3 4 from config import PROJECTNAME5 from config import ADD_PERMISSION4 from quintagroup.pfg.captcha.config import PROJECTNAME 5 from quintagroup.pfg.captcha.config import ADD_PERMISSION 6 6 7 from field import CaptchaField 8 from widget import CaptchaWidget 9 from validator import CaptchaValidator 7 from quintagroup.pfg.captcha.field import CaptchaField 8 from quintagroup.pfg.captcha.widget import CaptchaWidget 9 from quintagroup.pfg.captcha.validator import CaptchaValidator 10 #for pyflakes test 11 CaptchaField 12 CaptchaWidget 13 CaptchaValidator 14 10 15 11 16 def initialize(context): 12 17 13 content_types, constructors, ftis = process_types(listTypes(PROJECTNAME), PROJECTNAME) 18 content_types, constructors, ftis = process_types(listTypes(PROJECTNAME), 19 PROJECTNAME) 14 20 15 21 utils.ContentInit( 16 22 PROJECTNAME + ' Content', 17 content_types =content_types,18 permission =ADD_PERMISSION,19 extra_constructors =constructors,20 fti =ftis,23 content_types=content_types, 24 permission=ADD_PERMISSION, 25 extra_constructors=constructors, 26 fti=ftis, 21 27 ).initialize(context) -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/config.py
r2852 r3168 5 5 ADD_PERMISSION = cmfcore_permissions.AddPortalContent 6 6 7 try: 8 # Plone 4 and higher 9 import plone.app.upgrade 10 PLONE_VERSION = 4 11 except ImportError: 7 try: 8 # Plone 4 and higher 9 import plone.app.upgrade 10 PLONE_VERSION = 4 11 # for pyflakes test 12 plone 13 except ImportError: 12 14 PLONE_VERSION = 3 13 -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/field.py
r2098 r3168 3 3 from Products.CMFCore.permissions import View 4 4 5 from Products.Archetypes.atapi import *5 from Products.Archetypes.atapi import StringField 6 6 from Products.ATContentTypes.content.base import registerATCT 7 7 8 8 from Products.PloneFormGen.content.fields import FGStringField 9 from Products.PloneFormGen.content.fieldsBase import BareFieldSchema10 9 from Products.PloneFormGen.content.fieldsBase import BaseFormField 11 from Products.PloneFormGen.content.fieldsBase import BaseFieldSchemaStringDefault 10 from Products.PloneFormGen.content.fieldsBase \ 11 import BaseFieldSchemaStringDefault 12 12 13 13 from quintagroup.pfg.captcha.config import PROJECTNAME … … 16 16 CAPTCHA_ID = 'key' 17 17 HIDDEN_FIELDS = [ 18 'title', 18 'title', 19 19 'description', 20 'required', 21 'hidden', 22 'fgTDefault', 23 'fgTEnabled', 20 'required', 21 'hidden', 22 'fgTDefault', 23 'fgTEnabled', 24 24 'fgDefault', 25 25 'fgTValidator'] 26 26 27 def finalizeCaptchaFieldSchema( schema ): 28 schema['title'].default= 'key' 27 28 def finalizeCaptchaFieldSchema(schema): 29 schema['title'].default = 'key' 29 30 for field in HIDDEN_FIELDS: 30 schema[field].widget.visible = {'view':'invisible','edit':'invisible'} 31 schema[field].widget.visible = {'view': 'invisible', 32 'edit': 'invisible'} 31 33 32 34 CaptchaFieldSchema = BaseFieldSchemaStringDefault.copy() 33 finalizeCaptchaFieldSchema( CaptchaFieldSchema ) 35 finalizeCaptchaFieldSchema(CaptchaFieldSchema) 36 34 37 35 38 def addCaptchaField(self, id, **kwargs): 36 id = CAPTCHA_ID 39 id = CAPTCHA_ID 37 40 obj = CaptchaField(id) 38 41 notify(ObjectCreatedEvent(obj)) … … 42 45 notify(ObjectModifiedEvent(obj)) 43 46 return obj.getId() 47 44 48 45 49 class CaptchaField(FGStringField): … … 56 60 searchable=0, 57 61 required=1, 58 write_permission =View,62 write_permission=View, 59 63 validators=('isCaptchaCorrect',), 60 64 widget=CaptchaWidget(), -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/setuphandlers.py
r2737 r3168 6 6 captcha_fields = [] 7 7 8 8 9 def migrateToPackage(context): 9 """Collect old Products.qPloneCaptchaFields fields (before types tool setup). 10 """ 11 Collect old Products.qPloneCaptchaFields fields (before types tool setup). 10 12 """ 11 13 global captcha_fields … … 20 22 catalog = plone_tools.catalog() 21 23 captcha_fields = [(cf.id, cf.getObject().aq_parent) \ 22 for cf in catalog.search({'portal_type':'CaptchaField'})] 24 for cf in catalog.search( 25 {'portal_type': 'CaptchaField'})] 23 26 logger.info("Old Products.qPloneCaptchaField fields collected.") 24 27 -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/tests/base.py
r2853 r3168 1 import re2 import string3 import unittest4 1 import transaction 5 2 … … 16 13 'quintagroup.pfg.captcha', 17 14 ] 18 REQUIREMENTS = ['PloneFormGen', ] + PACKAGES15 REQUIREMENTS = ['PloneFormGen', ] + PACKAGES 19 16 20 17 ptc.setupPloneSite() … … 24 21 # !!! method of the layer class. 25 22 ztc.installProduct('PloneFormGen') 23 26 24 27 25 class NotInstalled(PloneSite): … … 60 58 def tearDown(cls): 61 59 ptc_setup._placefulTearDown() 62 60 63 61 64 62 class TestCase(ptc.PloneTestCase): -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/tests/testInstalled.py
r2737 r3168 1 from base import * 1 import string 2 import unittest 2 3 3 4 from Products.CMFCore.permissions import View … … 11 12 from quintagroup.pfg.captcha.widget import CAPTCHA_MACRO 12 13 from quintagroup.pfg.captcha.field import CAPTCHA_ID, HIDDEN_FIELDS 14 from quintagroup.pfg.captcha.tests.base import TestCase, REQUIREMENTS 13 15 14 16 _marker = object() 17 15 18 16 19 class TestInstallations(TestCase): … … 37 40 default_chain = pw.getDefaultChain() 38 41 cf_chain = pw.getChainForPortalType('CaptchaField') 39 self.assertNotEqual(cf_chain == default_chain 42 self.assertNotEqual(cf_chain == default_chain, True) 40 43 41 44 def testNotToList(self): … … 70 73 for field in HIDDEN_FIELDS: 71 74 visibility = schema[field].widget.visible 72 self.assertEqual(visibility, {'view':'invisible','edit':'invisible'}, 75 self.assertEqual(visibility, {'view': 'invisible', 76 'edit': 'invisible'}, 73 77 '"%s" field is not hidden, but %s:' % (field, visibility)) 74 78 … … 79 83 # Test fgField properties 80 84 self.assertEqual(type(fgField), StringField) 81 self.assertEqual(bool(fgField.searchable), False 85 self.assertEqual(bool(fgField.searchable), False) 82 86 self.assertEqual(fgField.write_permission, View) 83 87 self.assertEqual(type(fgField.widget), CaptchaWidget) … … 111 115 112 116 def getValidator(self): 113 return validation.validatorFor('isCaptchaCorrect') 117 return validation.validatorFor('isCaptchaCorrect') 114 118 115 119 def testRegistration(self): … … 121 125 def __init__(self, status, error=""): 122 126 self.status = status 123 self.errors = {'key': [error,]}127 self.errors = {'key': [error, ]} 124 128 125 patch_validator = lambda 129 patch_validator = lambda: MockState(status, error) 126 130 self.portal.captcha_validator = patch_validator 127 131 … … 133 137 result = validator('test', instance=self.portal) 134 138 self.assertEqual(result, 1) 135 139 136 140 def testValidationFailure(self): 137 141 # PFG validator must call patched quintagroup.captcha.core' -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/tests/testMigration.py
r2737 r3168 1 from base import * 2 from Products.PloneTestCase.setup import cleanupPloneSite 3 from Products.PloneTestCase.setup import portal_name 4 from Products.PloneTestCase.setup import SiteCleanup 1 import unittest 2 from quintagroup.pfg.captcha.tests.base import TestCaseNotInstalled 3 5 4 6 5 class TestMigration(TestCaseNotInstalled): … … 32 31 33 32 def beforeTearDown(self): 34 self.qi.uninstallProducts(["quintagroup.pfg.captcha", ])33 self.qi.uninstallProducts(["quintagroup.pfg.captcha", ]) 35 34 36 35 def prepareToMigration(self): … … 42 41 test_form.invokeFactory("CaptchaField", 'test_captcha_field') 43 42 self.cf_path = "test_form/key" 44 self.old_cf = self.portal.unrestrictedTraverse(self.cf_path) 43 self.old_cf = self.portal.unrestrictedTraverse(self.cf_path) 45 44 self.assert_(self.old_cf) 46 self.pt['CaptchaField'].manage_changeProperties(product="qPloneCaptchaField") 45 self.pt['CaptchaField'].manage_changeProperties( 46 product="qPloneCaptchaField") 47 47 self.qi.manage_delObjects('quintagroup.pfg.captcha') 48 48 49 49 def testMigration(self): 50 50 self.addProduct("quintagroup.pfg.captcha") 51 new_cf = self.portal.unrestrictedTraverse(self.cf_path) 51 new_cf = self.portal.unrestrictedTraverse(self.cf_path) 52 52 self.assert_(self.old_cf != new_cf) 53 53 -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/validator.py
r2852 r3168 2 2 from Products.validation import validation 3 3 from Products.validation.interfaces.IValidator import IValidator 4 from Products.CMFPlone.utils import safe_hasattr5 4 6 from config import PLONE_VERSION 5 from quintagroup.pfg.captcha.config import PLONE_VERSION 6 7 7 8 8 class CaptchaValidator: … … 19 19 def __call__(self, value, *args, **kwargs): 20 20 21 form 21 form = kwargs.get('instance') 22 22 portal = getToolByName(form, 'portal_url').getPortalObject() 23 23 result = portal.captcha_validator() 24 24 if result.status == 'failure': 25 return ("%(problem)s" % {'problem' 25 return ("%(problem)s" % {'problem': result.errors['key'][0]}) 26 26 else: 27 27 return 1 -
quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/widget.py
r2099 r3168 4 4 CAPTCHA_MACRO = "captchaField_widget" 5 5 6 6 7 class CaptchaWidget(StringWidget): 7 8 _properties = StringWidget._properties.copy() 8 _properties.update( {'macro' : CAPTCHA_MACRO})9 _properties.update({'macro': CAPTCHA_MACRO}) 9 10 10 11 11 12 registerWidget(CaptchaWidget, 12 title ='Captcha widget',13 description= 14 used_for =('quintagroup.pfg.captcha.field.CaptchaField',)13 title='Captcha widget', 14 description=('Renders captcha image and string input',), 15 used_for=('quintagroup.pfg.captcha.field.CaptchaField',) 15 16 ) -
quintagroup.pfg.captcha/trunk/setup.py
r2854 r3168 6 6 setup(name='quintagroup.pfg.captcha', 7 7 version=version, 8 description="quintagroup.pfg.captcha is a package that allows to add captcha field to PloneFormGen forms.", 8 description="quintagroup.pfg.captcha is a package that allows " 9 "to add captcha field to PloneFormGen forms.", 9 10 long_description=open("README.txt").read() + "\n" + 10 11 open(os.path.join("docs", "HISTORY.txt")).read(), 11 # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers12 12 classifiers=[ 13 13 "Framework :: Plone", … … 18 18 author='Quintagroup', 19 19 author_email='support@quintagroup.com', 20 url='http://projects.quintagroup.com/products/wiki/quintagroup.pfg.captcha', 20 url='http://projects.quintagroup.com/products/wiki/'\ 21 'quintagroup.pfg.captcha', 21 22 license='GPL', 22 23 packages=find_packages(exclude=['ez_setup']),
Note: See TracChangeset
for help on using the changeset viewer.