def handle_add_action(self, action, data):
        logger.info("Adding account to the registry")
        consumer = data['consumer']
        consumer_key = data['consumer_key']
        consumer_secret = data['consumer_secret']
        oauth_token = data['oauth_token']
        oauth_token_secret = data['oauth_token_secret']
        pincode = data['pincode']

        if consumer == "Plone default":
            consumer_key = PLONE_CONSUMER_KEY
            consumer_secret = PLONE_CONSUMER_SECRET

        if (consumer_key and
            consumer_secret and
            oauth_token and
            oauth_token_secret and
            pincode):

            validate_token = getMultiAdapter((self.context, self.request),
                                             name='validate-token')

            access_token = validate_token(consumer, consumer_key, consumer_secret,
                                          oauth_token, oauth_token_secret, pincode)

            if access_token:

                registry = getUtility(IRegistry)
                accounts = registry['collective.twitter.accounts']
                if not accounts:
                    accounts = {}

                username = access_token['screen_name']
                oauth_token = access_token['oauth_token']
                oauth_token_secret = access_token['oauth_token_secret']

                accounts[username] = \
                                     {'consumer_key': consumer_key,
                                      'consumer_secret': consumer_secret,
                                      'oauth_token': oauth_token,
                                      'oauth_token_secret': oauth_token_secret}

                registry['collective.twitter.accounts'] = accounts

                logger.info("Account added succesfully to the registry")

                logger.info("Token: %s" % access_token)
                self.status = _("Twitter account succesfully authorized.")

            else:
                logger.info("Account was not added to the registry")
                self.status = _("Could not authorize. Perhaps wrong token provided.")
        else:
            self.status = _("Missing data.")
def TwitterApplications(context):

    app_list = [("Plone default", _(u"Plone default")),
                ("Custom", _(u"Custom"))]

    return SimpleVocabulary(make_terms(app_list))
from plone.registry.interfaces import IRegistry

from collective.twitter.accounts.config import PLONE_CONSUMER_KEY
from collective.twitter.accounts.config import PLONE_CONSUMER_SECRET

from collective.twitter.accounts.config import PROJECTNAME

from zope.component import getMultiAdapter

from zope.schema.interfaces import IContextSourceBinder

import logging

logger = logging.getLogger(PROJECTNAME)

consumer_vocabulary = SimpleVocabulary.fromValues([_(u"Plone default"), _(u"Custom")])


def make_terms(items):
    """ Create zope.schema terms for vocab from tuples """
    terms = [SimpleTerm(value=pair[0], token=pair[0], title=pair[1])
             for pair in items]
    return terms


def TwitterApplications(context):

    app_list = [("Plone default", _(u"Plone default")),
                ("Custom", _(u"Custom"))]

    return SimpleVocabulary(make_terms(app_list))