def DownloadVocabulary(context):
    types = [
        ('true', _('true', default=u'Enabled')),
        ('false', _('false', default=u'Disabled')),
    ]
    terms = [SimpleTerm(term, term, title=label) for term, label in types]
    return SimpleVocabulary(terms)
def SharingVocabulary(context):
    types = [
        ('public',
            _(
                'public',
                default=u'Public - Makes this track  available to everyone'
            )
         ),
        ('private',
            _('private', default=u'Private - Only you have access')
         ),
    ]
    terms = [SimpleTerm(term, term, title=label) for term, label in types]
    return SimpleVocabulary(terms)
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # something changed?
        settings = get_soundcloud_settings()
        if (data.get('client_id') == settings.client_id) and settings.token:
            IStatusMessage(self.request).addStatusMessage(
                _(u'All values unchanged.'),
                "info"
            )
            self.request.response.redirect(self.request.getURL())
            return

        # store data
        settings.client_id = data.get('client_id')
        settings.client_secret = data.get('client_secret')

        # handle soundcloud
        client = soundcloud.Client(
            client_id=data.get('client_id'),
            client_secret=data.get('client_secret'),
            redirect_uri='{0}/soundcloud_redirect_handler'.format(
                self.context.absolute_url()
            )
        )
        self.request.RESPONSE.redirect(client.authorize_url())
 def __call__(self):
     alsoProvides(self.request, IDisableCSRFProtection)
     self.request.RESPONSE.redirect(
         '{0}/soundcloud-settings'.format(self.context.absolute_url())
     )
     code = self.request.form.get('code')
     if not code:
         IStatusMessage(self.request).addStatusMessage(
             _(u'Soundcloud code not fetched.'),
             "error"
         )
         return
     settings = get_soundcloud_settings()
     client = soundcloud.Client(
         client_id=settings.client_id,
         client_secret=settings.client_secret,
         redirect_uri='{0}/soundcloud_redirect_handler'.format(
             self.context.absolute_url()
         )
     )
     try:
         result = client.exchange_token(
             code=code
         )
     except requests.HTTPError as e:
         # no idea at the moment what this exception may be
         IStatusMessage(self.request).addStatusMessage(
             _(
                 u'Soundcloud can not transform code to token.: ' +
                 e.message
             ),
             "error"
         )
         return
     settings.token = result.obj['access_token']
     settings.client_secret = u'a token was stored'
     IStatusMessage(self.request).addStatusMessage(
         _(u'Soundcloud settings completed and saved.'),
         "info"
     )