def initialize(self):
     if IMegaphone.providedBy(self.context):
         # in use with a pre-existing PFG
         self.loadSteps(self.context)
     else:
         # initialize with site defaults
         self.session.update(get_megaphone_defaults())
         
         # give each step a chance to translate defaults
         for step in self.activeSteps:
             if hasattr(step, 'initialize'):
                 step.initialize()
    def test_petition_wizard(self):
        # log in
        browser = Browser()
        browser.handleErrors = False
        self.app.acl_users.userFolderAddUser('root', 'secret', ['Manager'], [])
        browser.addHeader('Authorization', 'Basic root:secret')
        browser.open('http://nohost/plone')

        # make sure we get the right steps for configuring a petition
        browser.getLink('Megaphone Action').click()
        browser.getControl(name='intro.widgets.megaphone_type:list').value = ['petition']
        browser.getControl('Continue').click()
        
        self.failUnless('General Settings' in browser.contents)
        browser.getControl('Title').value = 'Petition'
        browser.getControl('Continue').click()
        
        self.failUnless('Form Fields' in browser.contents)
        # remove captcha field
        browser.getControl(name='crud-edit.captcha.widgets.select:list').value = ['true']
        browser.getControl('Delete').click()
        browser.getControl('Continue').click()
        
        self.failUnless('Thank You to Activist' in browser.contents)
        if HAS_SALESFORCE:
            browser.getControl('Continue').click()
            self.failUnless('Save to Salesforce' in browser.contents)
        browser.getControl('Continue').click()
        self.failUnless('List of Signatures' in browser.contents)
        browser.getControl('Finish').click()
        self.failUnless('Megaphone Action Wizard Summary' in browser.contents)

        browser.getLink('View').click()
        self.assertEqual('http://nohost/plone/petition/view', browser.url)
        self.failUnless(IMegaphone.providedBy(self.portal.petition))
        
        # petitions don't get a 'Preview' button
        self.failIf('Preview' in browser.contents)
        
        # check the default fields
        expected_subitems = ['thank-you', 'body', 'first', 'last', 'email', 'street', 'city', 'state', 'zip', 'thank-you-email', 'saved-letters', 'rendered-letter']
        self.assertEqual(expected_subitems, self.portal.petition.objectIds())
        self.assertEqual('Additional Comment', self.portal.petition.body.Title())
        
        # return to edit and make sure we still get the petition steps
        browser.getLink('Edit').click()
        self.failUnless('List of Signatures' in browser.contents)
    def steps(self):
        # XXX this should probably get adapterized in some fashion

        steps = []
        if not IMegaphone.providedBy(self.context):
            # initial creation or editing site defaults; show intro
            steps = [IntroStep]
            megaphone_type = self.session.get('intro', {}).get('megaphone_type', 'letter')
        else:
            megaphone_type = IAnnotations(self.context).get(ANNOTATION_KEY, {}).get('megaphone_type', 'letter')
        if 'intro.widgets.megaphone_type' in self.request.form:
            megaphone_type = self.request.form['intro.widgets.megaphone_type'][0]
        if megaphone_type == 'letter':
            steps.extend([GeneralSettingsStep, FormFieldsStep, RecipientsStep, TemplateStep, ThankYouStep])
        else:
            steps.extend([GeneralSettingsStep, FormFieldsStep, ThankYouStep])
        if salesforce_is_configured():
            steps.append(SalesforceStep)
        if megaphone_type == 'petition':
            steps.append(SignersStep)
        
        return steps