Пример #1
0
class ITwitterPublishAction(Interface):
    """ Twitter Config """

    tw_account = schema.Choice(title=_(u'Twitter account'),
                               description=_(u"Which twitter account to use."),
                               required=True,
                               source=TwitterAccounts)
    def __call__(self):
        context = aq_inner(self.event.object)
        ploneutils = getToolByName(self.context, 'plone_utils')
        registry = getUtility(IRegistry)
        accounts = registry['collective.twitter.accounts']
        
        account = accounts.get(self.element.tw_account, {})

        if account:
            tw =  twitter.Api(consumer_key = account.get('consumer_key'),
                              consumer_secret = account.get('consumer_secret'),
                              access_token_key = account.get('oauth_token'), 
                              access_token_secret = account.get('oauth_token_secret'),)
                              
            obj = self.event.object
            title = obj.Title()
            url = getTinyURL(obj.absolute_url())
            if url is None:
                return False
            twittertext = "%s\n%s" % ( title[0:140-(len(url)+2)], url )
    
            try:
                status = tw.PostUpdate(twittertext)
                msg = _("Item published to twitter")
            except HTTPError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
            except twitter.TwitterError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
Пример #3
0
class TwitterPublishActionEditForm(EditForm):
    """An edit form for portal type conditions
    """
    form_fields = form.FormFields(ITwitterPublishAction)
    label = _(u"Edit publish to Twitter action.")
    description = _(u"Publish a title and short URL to Twitter")
    form_name = _(u"Select account")
Пример #4
0
    def __call__(self):
        context = aq_inner(self.event.object)
        ploneutils = getToolByName(self.context, 'plone_utils')
        registry = getUtility(IRegistry)
        accounts = registry['collective.twitter.accounts']

        account = accounts.get(self.element.tw_account, {})

        if account:
            tw = twitter.Api(
                consumer_key=account.get('consumer_key'),
                consumer_secret=account.get('consumer_secret'),
                access_token_key=account.get('oauth_token'),
                access_token_secret=account.get('oauth_token_secret'),
            )

            obj = self.event.object
            title = obj.Title()
            url = getTinyURL(obj.absolute_url())
            if url is None:
                return False
            twittertext = "%s\n%s" % (title[0:140 - (len(url) + 2)], url)

            try:
                status = tw.PostUpdate(twittertext)
                msg = _("Item published to twitter")
            except HTTPError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
            except twitter.TwitterError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
Пример #5
0
class TwitterPublishActionAddForm(AddForm):
    """An add form for portal type conditions.
    """
    form_fields = form.FormFields(ITwitterPublishAction)
    label = _(u"Publish to Twitter action.")
    description = _(u"Publish a title and short URL to Twitter")
    form_name = _(u"Select account")

    def create(self, data):
        c = TwitterPublishAction()
        form.applyChanges(c, self.form_fields, data)
        return c
 def summary(self):
     return _(u"Twitter account: ${user}", mapping=dict(user=self.tw_account))
            twittertext = "%s\n%s" % ( title[0:140-(len(url)+2)], url )
    
            try:
                status = tw.PostUpdate(twittertext)
                msg = _("Item published to twitter")
            except HTTPError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
            except twitter.TwitterError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
                
            ploneutils.addPortalMessage( msg )
            self.context.REQUEST.response.redirect(obj.absolute_url())
            
        else:
            msg = _("Could not publish to twitter, seems the account %s "
                    "was removed from the list of authorized accounts for this "
                    "site." % self.element.tw_account)
            ploneutils.addPortalMessage( msg )
            self.context.REQUEST.response.redirect(obj.absolute_url())
 
            
        return True

class TwitterPublishActionAddForm(AddForm):
    """An add form for portal type conditions.
    """
    form_fields = form.FormFields(ITwitterPublishAction)
    label = _(u"Publish to Twitter action.")
    description = _(u"Publish a title and short URL to Twitter")
    form_name = _(u"Select account")
Пример #8
0
 def summary(self):
     return _(u"Twitter account: ${user}",
              mapping=dict(user=self.tw_account))
Пример #9
0
            twittertext = "%s\n%s" % (title[0:140 - (len(url) + 2)], url)

            try:
                status = tw.PostUpdate(twittertext)
                msg = _("Item published to twitter")
            except HTTPError, e:
                msg = _("Error while publishing to twitter %s" % str(e))
            except twitter.TwitterError, e:
                msg = _("Error while publishing to twitter %s" % str(e))

            ploneutils.addPortalMessage(msg)
            self.context.REQUEST.response.redirect(obj.absolute_url())

        else:
            msg = _(
                "Could not publish to twitter, seems the account %s "
                "was removed from the list of authorized accounts for this "
                "site." % self.element.tw_account)
            ploneutils.addPortalMessage(msg)
            self.context.REQUEST.response.redirect(obj.absolute_url())

        return True


class TwitterPublishActionAddForm(AddForm):
    """An add form for portal type conditions.
    """
    form_fields = form.FormFields(ITwitterPublishAction)
    label = _(u"Publish to Twitter action.")
    description = _(u"Publish a title and short URL to Twitter")
    form_name = _(u"Select account")