Changeset 3168 in products for quintagroup.pfg.captcha


Ignore:
Timestamp:
Apr 21, 2011 1:43:09 PM (13 years ago)
Author:
vmaksymiv
Message:

pep8, pyflakes fixes

Location:
quintagroup.pfg.captcha/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/__init__.py

    r2095 r3168  
    22from Products.Archetypes.atapi import process_types, listTypes 
    33 
    4 from config import PROJECTNAME 
    5 from config import ADD_PERMISSION 
     4from quintagroup.pfg.captcha.config import PROJECTNAME 
     5from quintagroup.pfg.captcha.config import ADD_PERMISSION 
    66 
    7 from field import CaptchaField 
    8 from widget import CaptchaWidget 
    9 from validator import CaptchaValidator 
     7from quintagroup.pfg.captcha.field import CaptchaField 
     8from quintagroup.pfg.captcha.widget import CaptchaWidget 
     9from quintagroup.pfg.captcha.validator import CaptchaValidator 
     10#for pyflakes test 
     11CaptchaField 
     12CaptchaWidget 
     13CaptchaValidator 
     14 
    1015 
    1116def initialize(context): 
    1217 
    13     content_types, constructors, ftis = process_types(listTypes(PROJECTNAME), PROJECTNAME) 
     18    content_types, constructors, ftis = process_types(listTypes(PROJECTNAME), 
     19                                                      PROJECTNAME) 
    1420 
    1521    utils.ContentInit( 
    1622        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, 
    2127        ).initialize(context) 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/config.py

    r2852 r3168  
    55ADD_PERMISSION = cmfcore_permissions.AddPortalContent 
    66 
    7 try:  
    8     # Plone 4 and higher  
    9     import plone.app.upgrade  
    10     PLONE_VERSION = 4  
    11 except ImportError:  
     7try: 
     8    # Plone 4 and higher 
     9    import plone.app.upgrade 
     10    PLONE_VERSION = 4 
     11    # for pyflakes test 
     12    plone 
     13except ImportError: 
    1214    PLONE_VERSION = 3 
    13  
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/field.py

    r2098 r3168  
    33from Products.CMFCore.permissions import View 
    44 
    5 from Products.Archetypes.atapi import * 
     5from Products.Archetypes.atapi import StringField 
    66from Products.ATContentTypes.content.base import registerATCT 
    77 
    88from Products.PloneFormGen.content.fields import FGStringField 
    9 from Products.PloneFormGen.content.fieldsBase import BareFieldSchema 
    109from Products.PloneFormGen.content.fieldsBase import BaseFormField 
    11 from Products.PloneFormGen.content.fieldsBase import BaseFieldSchemaStringDefault 
     10from Products.PloneFormGen.content.fieldsBase \ 
     11        import BaseFieldSchemaStringDefault 
    1212 
    1313from quintagroup.pfg.captcha.config import PROJECTNAME 
     
    1616CAPTCHA_ID = 'key' 
    1717HIDDEN_FIELDS = [ 
    18     'title',  
     18    'title', 
    1919    'description', 
    20     'required',  
    21     'hidden',  
    22     'fgTDefault',  
    23     'fgTEnabled',  
     20    'required', 
     21    'hidden', 
     22    'fgTDefault', 
     23    'fgTEnabled', 
    2424    'fgDefault', 
    2525    'fgTValidator'] 
    2626 
    27 def finalizeCaptchaFieldSchema( schema ): 
    28     schema['title'].default= 'key' 
     27 
     28def finalizeCaptchaFieldSchema(schema): 
     29    schema['title'].default = 'key' 
    2930    for field in HIDDEN_FIELDS: 
    30         schema[field].widget.visible = {'view':'invisible','edit':'invisible'} 
     31        schema[field].widget.visible = {'view': 'invisible', 
     32                                        'edit': 'invisible'} 
    3133 
    3234CaptchaFieldSchema = BaseFieldSchemaStringDefault.copy() 
    33 finalizeCaptchaFieldSchema( CaptchaFieldSchema ) 
     35finalizeCaptchaFieldSchema(CaptchaFieldSchema) 
     36 
    3437 
    3538def addCaptchaField(self, id, **kwargs): 
    36     id = CAPTCHA_ID  
     39    id = CAPTCHA_ID 
    3740    obj = CaptchaField(id) 
    3841    notify(ObjectCreatedEvent(obj)) 
     
    4245    notify(ObjectModifiedEvent(obj)) 
    4346    return obj.getId() 
     47 
    4448 
    4549class CaptchaField(FGStringField): 
     
    5660            searchable=0, 
    5761            required=1, 
    58             write_permission = View, 
     62            write_permission=View, 
    5963            validators=('isCaptchaCorrect',), 
    6064            widget=CaptchaWidget(), 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/setuphandlers.py

    r2737 r3168  
    66captcha_fields = [] 
    77 
     8 
    89def migrateToPackage(context): 
    9     """Collect old Products.qPloneCaptchaFields fields (before types tool setup). 
     10    """ 
     11    Collect old Products.qPloneCaptchaFields fields (before types tool setup). 
    1012    """ 
    1113    global captcha_fields 
     
    2022        catalog = plone_tools.catalog() 
    2123        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'})] 
    2326        logger.info("Old Products.qPloneCaptchaField fields collected.") 
    2427 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/tests/base.py

    r2853 r3168  
    1 import re 
    2 import string 
    3 import unittest 
    41import transaction 
    52 
     
    1613    'quintagroup.pfg.captcha', 
    1714] 
    18 REQUIREMENTS = ['PloneFormGen',] + PACKAGES 
     15REQUIREMENTS = ['PloneFormGen', ] + PACKAGES 
    1916 
    2017ptc.setupPloneSite() 
     
    2421# !!! method of the layer class. 
    2522ztc.installProduct('PloneFormGen') 
     23 
    2624 
    2725class NotInstalled(PloneSite): 
     
    6058    def tearDown(cls): 
    6159        ptc_setup._placefulTearDown() 
    62          
     60 
    6361 
    6462class TestCase(ptc.PloneTestCase): 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/tests/testInstalled.py

    r2737 r3168  
    1 from base import * 
     1import string 
     2import unittest 
    23 
    34from Products.CMFCore.permissions import View 
     
    1112from quintagroup.pfg.captcha.widget import CAPTCHA_MACRO 
    1213from quintagroup.pfg.captcha.field import CAPTCHA_ID, HIDDEN_FIELDS 
     14from quintagroup.pfg.captcha.tests.base import TestCase, REQUIREMENTS 
    1315 
    1416_marker = object() 
     17 
    1518 
    1619class TestInstallations(TestCase): 
     
    3740        default_chain = pw.getDefaultChain() 
    3841        cf_chain = pw.getChainForPortalType('CaptchaField') 
    39         self.assertNotEqual(cf_chain == default_chain , True) 
     42        self.assertNotEqual(cf_chain == default_chain, True) 
    4043 
    4144    def testNotToList(self): 
     
    7073        for field in HIDDEN_FIELDS: 
    7174            visibility = schema[field].widget.visible 
    72             self.assertEqual(visibility, {'view':'invisible','edit':'invisible'}, 
     75            self.assertEqual(visibility, {'view': 'invisible', 
     76                                          'edit': 'invisible'}, 
    7377                '"%s" field is not hidden, but %s:' % (field, visibility)) 
    7478 
     
    7983        # Test fgField properties 
    8084        self.assertEqual(type(fgField), StringField) 
    81         self.assertEqual(bool(fgField.searchable), False ) 
     85        self.assertEqual(bool(fgField.searchable), False) 
    8286        self.assertEqual(fgField.write_permission, View) 
    8387        self.assertEqual(type(fgField.widget), CaptchaWidget) 
     
    111115 
    112116    def getValidator(self): 
    113         return validation.validatorFor('isCaptchaCorrect')         
     117        return validation.validatorFor('isCaptchaCorrect') 
    114118 
    115119    def testRegistration(self): 
     
    121125            def __init__(self, status, error=""): 
    122126                self.status = status 
    123                 self.errors = {'key':[error,]} 
     127                self.errors = {'key': [error, ]} 
    124128 
    125         patch_validator = lambda : MockState(status, error) 
     129        patch_validator = lambda: MockState(status, error) 
    126130        self.portal.captcha_validator = patch_validator 
    127131 
     
    133137        result = validator('test', instance=self.portal) 
    134138        self.assertEqual(result, 1) 
    135          
     139 
    136140    def testValidationFailure(self): 
    137141        # 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 
     1import unittest 
     2from quintagroup.pfg.captcha.tests.base import TestCaseNotInstalled 
     3 
    54 
    65class TestMigration(TestCaseNotInstalled): 
     
    3231 
    3332    def beforeTearDown(self): 
    34         self.qi.uninstallProducts(["quintagroup.pfg.captcha",]) 
     33        self.qi.uninstallProducts(["quintagroup.pfg.captcha", ]) 
    3534 
    3635    def prepareToMigration(self): 
     
    4241        test_form.invokeFactory("CaptchaField", 'test_captcha_field') 
    4342        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) 
    4544        self.assert_(self.old_cf) 
    46         self.pt['CaptchaField'].manage_changeProperties(product="qPloneCaptchaField") 
     45        self.pt['CaptchaField'].manage_changeProperties( 
     46            product="qPloneCaptchaField") 
    4747        self.qi.manage_delObjects('quintagroup.pfg.captcha') 
    4848 
    4949    def testMigration(self): 
    5050        self.addProduct("quintagroup.pfg.captcha") 
    51         new_cf = self.portal.unrestrictedTraverse(self.cf_path)  
     51        new_cf = self.portal.unrestrictedTraverse(self.cf_path) 
    5252        self.assert_(self.old_cf != new_cf) 
    5353 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/validator.py

    r2852 r3168  
    22from Products.validation import validation 
    33from Products.validation.interfaces.IValidator import IValidator 
    4 from Products.CMFPlone.utils import safe_hasattr 
    54 
    6 from config import PLONE_VERSION 
     5from quintagroup.pfg.captcha.config import PLONE_VERSION 
     6 
    77 
    88class CaptchaValidator: 
     
    1919    def __call__(self, value, *args, **kwargs): 
    2020 
    21         form  = kwargs.get('instance') 
     21        form = kwargs.get('instance') 
    2222        portal = getToolByName(form, 'portal_url').getPortalObject() 
    2323        result = portal.captcha_validator() 
    2424        if result.status == 'failure': 
    25             return ("%(problem)s" % {'problem' : result.errors['key'][0]}) 
     25            return ("%(problem)s" % {'problem': result.errors['key'][0]}) 
    2626        else: 
    2727            return 1 
  • quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/widget.py

    r2099 r3168  
    44CAPTCHA_MACRO = "captchaField_widget" 
    55 
     6 
    67class CaptchaWidget(StringWidget): 
    78    _properties = StringWidget._properties.copy() 
    8     _properties.update( {'macro' : CAPTCHA_MACRO} ) 
     9    _properties.update({'macro': CAPTCHA_MACRO}) 
    910 
    1011 
    1112registerWidget(CaptchaWidget, 
    12                title = 'Captcha widget', 
    13                description= ('Renders captcha image and string input',), 
    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',) 
    1516              ) 
  • quintagroup.pfg.captcha/trunk/setup.py

    r2854 r3168  
    66setup(name='quintagroup.pfg.captcha', 
    77      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.", 
    910      long_description=open("README.txt").read() + "\n" + 
    1011                       open(os.path.join("docs", "HISTORY.txt")).read(), 
    11       # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers 
    1212      classifiers=[ 
    1313        "Framework :: Plone", 
     
    1818      author='Quintagroup', 
    1919      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', 
    2122      license='GPL', 
    2223      packages=find_packages(exclude=['ez_setup']), 
Note: See TracChangeset for help on using the changeset viewer.