예제 #1
0
 def get_slid(self):
     """slideshare slideshowid or redirect to upload"""
     annotations = IAnnotations(self.context)
     sl_id = annotations.get(KEY, None)
     if sl_id:
         return sl_id
     else:
         if IATFile.providedBy(self.context):
             if self.context.getContentType() in SLIDES_MIMETYPES:
                 self.request.response.redirect(
                     self.context.absolute_url() +
                             '/@@slideshare_post.html')
             else:
                 msg = _(u"This file does not seem to be a presentation")
                 IStatusMessage(self.request).addStatusMessage(msg,
                         type='error')
         elif IATLink.providedBy(self.context):
             urlob = urlparse(self.context.getRemoteUrl())
             if urlob.hostname == 'www.slideshare.net':
                  self.request.response.redirect(
                     self.context.absolute_url() +
                             '/@@slideshare_getid.html')
             else:
                 msg = _(u"This is not a valid slideshare URL")
                 IStatusMessage(self.request).addStatusMessage(msg,
                         type='error')
예제 #2
0
class RemoveSlideshareId(formbase.PageForm):
    form_fields = form.FormFields(IGetSlideshareIdSchema)
    label = _(u'Remove the Slideshare id from content')
    description = _(u'''If the slideshow was deleted from SlideShare you
    can remove the id. This does NOT delete the presentation from SlideShare.
    It is not recommended to remove the id if you do not delete the
    presentation from SlideShare, because if you change the view back to
    'SlideShare View' it will result in another upload of the presentation.
    ''')

    @property
    def next_url(self):
        url = self.context.absolute_url()
        url += '/view'
        return url

    @form.action('Remove')
    def actionSubmit(self, action, data):
        annotations = IAnnotations(self.context)
        if annotations.get(KEY):
            annotations[KEY] = None
            msg = _(u"Slideshare id removed")
            IStatusMessage(self.request).addStatusMessage(msg, type='info')
        else:
            msg = _(u"object does not have a slideshare id")
            IStatusMessage(self.request).addStatusMessage(msg, type='error')
        self.context.setLayout(self.context.getDefaultLayout())
        self.request.response.redirect(self.next_url)

    @form.action('Cancel')
    def actionCancel(self, action, data):
        self.request.response.redirect(self.next_url)
예제 #3
0
def _create_policy_vocab():
    items = [ ("fixed", _(u"always use credentials below")),
        ("user", _("always ask user for his credentials")),
        ("optional", _("allow user to supply his credentials"))]

    return  [ SimpleTerm(value=pair[0], token=pair[0], title=pair[1])
                for pair in items ]
예제 #4
0
 def actionSubmit(self, action, data):
     annotations = IAnnotations(self.context)
     if annotations.get(KEY):
         annotations[KEY] = None
         msg = _(u"Slideshare id removed")
         IStatusMessage(self.request).addStatusMessage(msg, type='info')
     else:
         msg = _(u"object does not have a slideshare id")
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
     self.context.setLayout(self.context.getDefaultLayout())
     self.request.response.redirect(self.next_url)
예제 #5
0
class IPostToSlideshareSchema(Interface):
    """ get username/password to post to slideshare """

    username = schema.TextLine(title=_(u"Username"),
        description = _(u"Your slideshare username"),
        required = False,
        )

    password = schema.TextLine(title=_(u"Password"),
        description = _(u"Your slideshare password"),
        required = False,
        )
예제 #6
0
class GetSlideshareId(formbase.PageForm):
    form_fields = form.FormFields(IGetSlideshareIdSchema)
    label = _(u'Get embed information from Slideshare')
    description = _(u'Get the code to embed the slideshow from slideshare')

    def __init__(self, *args, **kwargs):
        registry = getUtility(IRegistry)
        self.settings = registry.forInterface(ISlideshareSettings)
        super(GetSlideshareId, self).__init__(*args, **kwargs)

    @property
    def next_url(self):
        url = self.context.absolute_url()
        url += '/view'
        return url

    @form.action('Submit')
    def actionSubmit(self, action, data):
        if self.settings.api_key and self.settings.shared_secret:
            api = slideshare.SlideshareAPI(self.settings.api_key,
                self.settings.shared_secret)
        else:
            msg = _(u"Slideshare API_KEY or SHARED_SECRET missing")
            IStatusMessage(self.request).addStatusMessage(msg, type='error')
            self.request.response.redirect(self.next_url)
            return
        msg = collective.slideshare.utils.get_slideshare_id(
            self.settings.api_key, self.settings.shared_secret,
            self.context)
        self.request.response.redirect(self.next_url)
        msgtype = 'info'
        if 'SlideShareServiceError' in msg:
            msgtype = 'error'
        IStatusMessage(self.request).addStatusMessage(msg, type=msgtype)

    @form.action('Cancel')
    def actionCancel(self, action, data):
        if self.context.getLayout() == 'slideshare_view.html':
            self.context.setLayout(self.context.getDefaultLayout())
        self.request.response.redirect(self.next_url)
예제 #7
0
 def actionSubmit(self, action, data):
     url = self.context.absolute_url()
     if self.settings.api_key and self.settings.shared_secret:
         api = slideshare.SlideshareAPI(self.settings.api_key,
             self.settings.shared_secret)
     else:
         msg = _(u"Slideshare API_KEY or SHARED_SECRET missing")
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
         self.request.response.redirect(self.next_url)
         return
     if self.settings.user_policy == "fixed":
         username = self.settings.username
         password = self.settings.password
     elif self.settings.user_policy == "user":
         username = data.get('username')
         password = data.get('password')
     elif self.settings.user_policy == "optional":
         username = data.get('username')
         password = data.get('password')
         if not(username and password):
             username = self.settings.username
             password = self.settings.password
     else:
         username = None
         password = None
     if not(username and password):
         msg = _(u"Slideshare USERNAME or PASSWORD missing")
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
         return
     msg = collective.slideshare.utils.post_to_slideshare(
             self.settings.api_key, self.settings.shared_secret,
             username, password, self.context)
     self.request.response.redirect(self.next_url)
     msgtype = 'info'
     if 'SlideShareServiceError' in msg:
         msgtype = 'error'
     IStatusMessage(self.request).addStatusMessage(msg, type=msgtype)
예제 #8
0
 def actionSubmit(self, action, data):
     if self.settings.api_key and self.settings.shared_secret:
         api = slideshare.SlideshareAPI(self.settings.api_key,
             self.settings.shared_secret)
     else:
         msg = _(u"Slideshare API_KEY or SHARED_SECRET missing")
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
         self.request.response.redirect(self.next_url)
         return
     msg = collective.slideshare.utils.get_slideshare_id(
         self.settings.api_key, self.settings.shared_secret,
         self.context)
     self.request.response.redirect(self.next_url)
     msgtype = 'info'
     if 'SlideShareServiceError' in msg:
         msgtype = 'error'
     IStatusMessage(self.request).addStatusMessage(msg, type=msgtype)
예제 #9
0
 def __init__(self, *args, **kwargs):
     registry = getUtility(IRegistry)
     self.settings = registry.forInterface(ISlideshareSettings)
     if self.settings.user_policy == "fixed":
         self.description = ""
         self.form_fields = self.form_fields.omit('username', 'password')
     elif self.settings.user_policy == "user":
         un = self.form_fields.get('username')
         un.field.required = True
         pw = self.form_fields.get('password')
         pw.field.required = True
     elif self.settings.user_policy == "optional":
         self.description = _(u"""Supply your Slideshare credentials
         if you want to upload the presentation to your own account.
         Your credentials will not be stored""")
         un = self.form_fields.get('username')
         un.field.required = False
         pw = self.form_fields.get('password')
         pw.field.required = False
     super(PostToSlideshare, self).__init__(*args, **kwargs)
예제 #10
0
        filename=context.getFilename(),
        mimetype=context.getContentType()
        )
    try:
        sls = api.upload_slideshow(username, password,
            slideshow_title = context.Title(),
            slideshow_srcfile = srcfile,
            slideshow_description = context.Description(),
            slideshow_tags = ','.join(context.Subject()))
    except slideshare.SlideShareServiceError, exc:
        context.setLayout(context.getDefaultLayout())
        return str(exc)
    sl_id = sls['SlideShowUploaded']['SlideShowID']
    annotations = IAnnotations(context)
    annotations[KEY] = sl_id
    msg = _(u"Slideshow uploaded")
    if 'slideshare_view.html' in [l[0] for l in context.getAvailableLayouts()]:
        context.setLayout('slideshare_view.html')
    return msg

def get_slideshare_id(api_key, shared_secret, context):
    """From a link to a slideshare slideshow get the slideshareId
    and  annotate the object"""
    api = slideshare.SlideshareAPI(api_key, shared_secret)
    try:
        sls = api.get_slideshow(slideshow_url=context.getRemoteUrl())
    except slideshare.SlideShareServiceError, exc:
        context.setLayout(context.getDefaultLayout())
        return str(exc)
    title = sls['Slideshow'].get('Title')
    description = sls['Slideshow'].get('Description')
예제 #11
0
 def validateUserPwdRequired(data):
     if data.push_on_publish:
         if data.user_policy == 'user':
             raise RequiredUserPwd(
                 _(u"""If you require the user to supply his credentials,
                 you cannot activate the upload on publish"""))
예제 #12
0
 def validateUserPwdMissing(data):
     if data.push_on_publish:
         if not(data.username and data.password):
             raise MissingUserPwd(
                 _(u"""You must provide a username and password
                 if you want activate the upload on publish."""))
예제 #13
0
class ISlideshareSettings(Interface):
    """Global settings. This describes records stored in the
    configuration registry and obtainable via plone.registry.
    """

    api_key = schema.TextLine(title=_(u"API Key"),
        description = _(u"Apply for an Key at http://www.slideshare.net/developers/applyforapi"),
        required = True,
        )

    shared_secret = schema.TextLine(title=_(u"Shared Secret"),
        description = _(u""),
        required = True,
        )

    user_policy = schema.Choice(title=_(u'Post as user policy'),
         description=_(u"Select if a user has to supply his credentials"),
         vocabulary=vocabularies.user_policy_vocabulary,
         default=u'fixed',
         required=True,
         )

    username = schema.TextLine(title=_(u"User"),
        description = _(u"Username of the user you post to slideshare as"),
        required = False,
        )

    password = schema.TextLine(title=_(u"Password"),
        description = _(u"Password of the user you post to slideshare as"),
        required = False,
        )

    push_on_publish = schema.Bool(title=_(u"Post to Slideshare on publish"),
        description=_(u"For this to work the User and Password above must be filled in"),
        required=False,
        default=False,
        )


    width = schema.TextLine(
        title=_(u"Width"),
        description=_(
            u"Choose the width of the slides, "
            u"specified as an absolute value (e.g. '450px' or '15em'), "
            u"or relative (e.g. '100%') size."
        ),
        default=u"427px",
        required=False)

    height = schema.TextLine(
        title=_(u"Height"),
        description=_(
            u"Choose the height of the slides, "
            u"specified as an absolute value (e.g. '450px' or '15em'), "
            u"or relative (e.g. '100%') size."
        ),
        default=u"356px",
        required=False)


    @invariant
    def validateUserPwdMissing(data):
        if data.push_on_publish:
            if not(data.username and data.password):
                raise MissingUserPwd(
                    _(u"""You must provide a username and password
                    if you want activate the upload on publish."""))

    @invariant
    def validateUserPwdRequired(data):
        if data.push_on_publish:
            if data.user_policy == 'user':
                raise RequiredUserPwd(
                    _(u"""If you require the user to supply his credentials,
                    you cannot activate the upload on publish"""))

    @invariant
    def validateUserPwdfixed(data):
        if data.user_policy == 'fixed':
            if not(data.username and data.password):
                raise FixedUserPwd(
                    _(u"""If you always want to use the system credentials,
                    you must provide a username and password"""))
예제 #14
0
class FixedUserPwd(Invalid):
    __doc__ = _(u"If you always use the system credentials, you must provide a username and password")
예제 #15
0
class RequiredUserPwd(Invalid):
    __doc__ = _(u"If you require the user to supply his credentials, you cannot activate the upload on publish")
예제 #16
0
class MissingUserPwd(Invalid):
    __doc__ = _(u"You must provide a username and password for this to work")
예제 #17
0
class PostToSlideshare(formbase.PageForm):
    form_fields = form.FormFields(IPostToSlideshareSchema)
    form_fields['password'].custom_widget = PasswordWidget
    label = _(u'Post to Slideshare')
    description = _(u'Supply your Slideshare credentials to upload')

    def __init__(self, *args, **kwargs):
        registry = getUtility(IRegistry)
        self.settings = registry.forInterface(ISlideshareSettings)
        if self.settings.user_policy == "fixed":
            self.description = ""
            self.form_fields = self.form_fields.omit('username', 'password')
        elif self.settings.user_policy == "user":
            un = self.form_fields.get('username')
            un.field.required = True
            pw = self.form_fields.get('password')
            pw.field.required = True
        elif self.settings.user_policy == "optional":
            self.description = _(u"""Supply your Slideshare credentials
            if you want to upload the presentation to your own account.
            Your credentials will not be stored""")
            un = self.form_fields.get('username')
            un.field.required = False
            pw = self.form_fields.get('password')
            pw.field.required = False
        super(PostToSlideshare, self).__init__(*args, **kwargs)

    @property
    def next_url(self):
        url = self.context.absolute_url()
        url += '/view'
        return url

    @form.action('Submit')
    def actionSubmit(self, action, data):
        url = self.context.absolute_url()
        if self.settings.api_key and self.settings.shared_secret:
            api = slideshare.SlideshareAPI(self.settings.api_key,
                self.settings.shared_secret)
        else:
            msg = _(u"Slideshare API_KEY or SHARED_SECRET missing")
            IStatusMessage(self.request).addStatusMessage(msg, type='error')
            self.request.response.redirect(self.next_url)
            return
        if self.settings.user_policy == "fixed":
            username = self.settings.username
            password = self.settings.password
        elif self.settings.user_policy == "user":
            username = data.get('username')
            password = data.get('password')
        elif self.settings.user_policy == "optional":
            username = data.get('username')
            password = data.get('password')
            if not(username and password):
                username = self.settings.username
                password = self.settings.password
        else:
            username = None
            password = None
        if not(username and password):
            msg = _(u"Slideshare USERNAME or PASSWORD missing")
            IStatusMessage(self.request).addStatusMessage(msg, type='error')
            return
        msg = collective.slideshare.utils.post_to_slideshare(
                self.settings.api_key, self.settings.shared_secret,
                username, password, self.context)
        self.request.response.redirect(self.next_url)
        msgtype = 'info'
        if 'SlideShareServiceError' in msg:
            msgtype = 'error'
        IStatusMessage(self.request).addStatusMessage(msg, type=msgtype)

    @form.action('Cancel')
    def actionCancel(self, action, data):
        if self.context.getLayout() == 'slideshare_view.html':
            self.context.setLayout(self.context.getDefaultLayout())
        self.request.response.redirect(self.next_url)
예제 #18
0
 def validateUserPwdfixed(data):
     if data.user_policy == 'fixed':
         if not(data.username and data.password):
             raise FixedUserPwd(
                 _(u"""If you always want to use the system credentials,
                 you must provide a username and password"""))
예제 #19
0
 def link_text(self):
     if IATFile.providedBy(self.context):
         return _("Download")
     elif IATLink.providedBy(self.context):
         return _("View it on SlideShare")
예제 #20
0
                   filename=context.getFilename(),
                   mimetype=context.getContentType())
    try:
        sls = api.upload_slideshow(username,
                                   password,
                                   slideshow_title=context.Title(),
                                   slideshow_srcfile=srcfile,
                                   slideshow_description=context.Description(),
                                   slideshow_tags=','.join(context.Subject()))
    except slideshare.SlideShareServiceError, exc:
        context.setLayout(context.getDefaultLayout())
        return str(exc)
    sl_id = sls['SlideShowUploaded']['SlideShowID']
    annotations = IAnnotations(context)
    annotations[KEY] = sl_id
    msg = _(u"Slideshow uploaded")
    if 'slideshare_view.html' in [l[0] for l in context.getAvailableLayouts()]:
        context.setLayout('slideshare_view.html')
    return msg


def get_slideshare_id(api_key, shared_secret, context):
    """From a link to a slideshare slideshow get the slideshareId
    and  annotate the object"""
    api = slideshare.SlideshareAPI(api_key, shared_secret)
    try:
        sls = api.get_slideshow(slideshow_url=context.getRemoteUrl())
    except slideshare.SlideShareServiceError, exc:
        context.setLayout(context.getDefaultLayout())
        return str(exc)
    title = sls['Slideshow'].get('Title')