def __call__(self):
     self.messages = IStatusMessage(self.request)
     
     link_id = self.context.id
     link_title = self.context.title
     link_url = self.context.absolute_url()
     link_uid = self.getUID()
     
     typestool = getToolByName(self, 'portal_types')
     home_folder = getToolByName(self, 'portal_membership').getHomeFolder()
     
     if home_folder == None:
         msgid = _(u"no_home_folder_msg", default=u"User did not have a Home Folder, could not create Favorite Link for ${path}" , mapping={ u"path" : link_url})
         translated = self.context.translate(msgid)
         self.messages.add(translated, type=u"warn")
         #self.messages.add(_(u"User did not have a Home Folder, could not create Favorite Link for %s") % link_url, type=u"warn")
     else:
         if not home_folder.has_key('favorites'):
             fav = typestool.constructContent(type_name="Favorites Folder", container=home_folder, id='favorites')
             home_folder[fav].setTitle(_(u"Favorites"))
             home_folder['favorites'].setExcludeFromNav(True)
         fav = home_folder['favorites']
         if not fav.has_key('fav'+link_uid):
             link = createContentInContainer(fav, "Favorite", checkConstrains=False, id='fav' + link_uid, title='fav'+link_uid, target_uid = link_uid)
             
             msgid = _(u"fav_created_msg", default=u"Favorites Link created for ${path}" , mapping={ u"path" : link_url})
             translated = self.context.translate(msgid)
             self.messages.add(translated, type=u"info")
             #self.messages.add(_(u"Favorites Link created for %s") % link_url, type=u"info")
         else:           
             msgid = _(u"fav_doubled_msg", default=u"Favorites Link already exists for ${path}" , mapping={ u"path" : link_url})
             translated = self.context.translate(msgid)
             self.messages.add(translated, type=u"warn")
             #self.messages.add(_(u"Favorites Link already exists for %s") % link_url, type=u"warn")
     return self.request.RESPONSE.redirect(self.context.absolute_url())
示例#2
0
class AddForm(base.NullAddForm):
    form_fields = form.Fields(IFavoritesPortlet)
    label = _(u"Add Favorites Portlet")
    description = _(
        u"This portlet displays the documents you have selected as your favorites."
    )

    def create(self):
        return Assignment()
示例#3
0
    def remove(self):
        super(AjaxFavoriteActions, self).remove()

        if IFolderish.providedBy(self.context):
            msg = _("The folder has been removed from your favorites")
        else:
            msg = _("The document has been removed from your favorites")

        return {'status': 'favorite-off',
                'msg': translate(msg, context=self.request)}
示例#4
0
    def add(self):
        request = self.request
        view = request.get('view', '')
        super(FavoriteActions, self).add()

        statusmsg = IStatusMessage(request)
        if IFolderish.providedBy(self.context):
            statusmsg.add(_("The folder has been added to your favorites"))
        else:
            statusmsg.add(_("The document has been added to your favorites"))

        request.response.redirect(self.context.absolute_url() + '/' + view)
示例#5
0
    def remove(self):
        super(FavoriteActions, self).remove()

        statusmsg = IStatusMessage(self.request)
        if IFolderish.providedBy(self.context):
            statusmsg.add(_("The folder has been removed from your favorites"))
        else:
            statusmsg.add(_("The document has been removed from your favorites"))

        site_properties = getToolByName(self.context, 'portal_properties').site_properties
        useView = self.context.portal_type in site_properties.typesUseViewActionInListings
        url = self.context.absolute_url() + (useView and "/view" or "")
        self.request.response.redirect(url)
 def __call__(self):
     self.messages = IStatusMessage(self.request)
     
     link_uid = self.getUID()
     
     typestool = getToolByName(self, 'portal_types')
     home_folder = getToolByName(self, 'portal_membership').getHomeFolder()
     fav_folder = home_folder['favorites']
     try: 
         fav_folder.manage_delObjects(['fav'+link_uid])
         
         self.messages.add(_(u"Favorite deleted") , type=u"info")
     except:
         self.messages.add(_(u"Could not delete Favorite") , type=u"error")
     return self.request.RESPONSE.redirect(self.context.absolute_url())
示例#7
0
 def add(self):
     request = self.request
     view = request.get('view', '')
     super(FavoriteActions, self).add()
     statusmsg = IStatusMessage(request)
     statusmsg.add(_("The item has been added to your favorites"))
     request.response.redirect(self.context.absolute_url() + '/' + view)
 def add(self):
     request = self.request
     view = request.get('view', '')
     super(FavoriteActions, self).add()
     statusmsg = IStatusMessage(request)
     statusmsg.add(_("The item has been added to your favorites"))
     request.response.redirect(self.context.absolute_url() + '/' + view)
示例#9
0
    def remove(self):
        request = self.request
        user = request.AUTHENTICATED_USER
        view = request.get('view', '')
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        site = getNavigationRootObject(self.context, portal)
        IFavoriteStorage(site).remove_favorite(user.getId(),
                                               id=IUUID(self.context))

        statusmsg = IStatusMessage(request)
        if IFolderish.providedBy(self.context):
            statusmsg.add(_("The folder has been removed from your favorites"))
        else:
            statusmsg.add(
                _("The document has been removed from your favorites"))

        request.response.redirect(self.context.absolute_url() + '/' + view)
示例#10
0
    def remove(self):
        request = self.request
        user = request.AUTHENTICATED_USER
        view = request.get('view', '')
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        site = getNavigationRootObject(self.context, portal)
        IFavoriteStorage(site).remove_favorite(user.getId(),
                                                 id=IUUID(self.context))


        statusmsg = IStatusMessage(request)
        if IFolderish.providedBy(self.context):
            statusmsg.add(_("The folder has been removed from your favorites"))
        else:
            statusmsg.add(_("The document has been removed from your favorites"))

        request.response.redirect(self.context.absolute_url() + '/' + view)
示例#11
0
class Renderer(base.Renderer):

    render = ViewPageTemplateFile('favorites.pt')

    title = _("Favorites")

    @property
    def anonymous(self):
        context = aq_inner(self.context)
        portal_state = getMultiAdapter((context, self.request),
                                       name=u'plone_portal_state')
        return portal_state.anonymous()

    @property
    def available(self):
        return not self.anonymous and len(self._data())

    def favorites_items(self):
        return self._data()

    @memoize
    def _data(self):
        policies = getUtilitiesFor(IFavoritesPolicy)
        mtool = getToolByName(self.context, 'portal_membership')
        user_id = mtool.getAuthenticatedMember().getId()
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        site = getNavigationRootObject(self.context, portal)
        favorites_list = IFavoriteStorage(site).list_favorites(user_id)

        favorites_infos = []
        for policy_name, policy in policies:
            favorites_infos.extend(
                policy.get_favorites_infos(self.context, [
                    fav for fav in favorites_list if fav['type'] == policy_name
                ]))

        favorites_infos.sort(key=lambda x: x['index'])
        return favorites_infos
示例#12
0
 def add(self):
     super(AjaxFavoriteActions, self).add()
     msg = _("The item has been added to your favorites")
     return {'status': 'favorite-on',
             'msg': translate(msg, context=self.request)}
示例#13
0
 def title(self):
     return _(u"Favorites List")
示例#14
0
 def title(self):
     return _(u"Favorites List")
示例#15
0
 def remove(self):
     super(AjaxFavoriteActions, self).remove()
     msg = _("The item has been removed from your favorites")
     return {'status': 'favorite-off',
             'msg': translate(msg, context=self.request)}
示例#16
0
 def remove(self):
     super(AjaxFavoriteActions, self).remove()
     msg = _("The item has been removed from your favorites")
     return {'status': 'favorite-off',
             'msg': translate(msg, context=self.request)}
示例#17
0
 def add(self):
     super(AjaxFavoriteActions, self).add()
     msg = _("The item has been added to your favorites")
     return {'status': 'favorite-on',
             'msg': translate(msg, context=self.request)}