Beispiel #1
0
class Favorite(base.ViewletBase):

    favorite = None
    is_manager = None
    can_favorite = None

    # Update methods are guaranteed to be called before rendering for
    # Viewlets and Portlets (Because they are IContentProvider objects)
    # and for z3c.forms and formlib forms. But *not* for normal Browser Pages
    def update(self):
        super(Favorite, self).update()

        if self.favorite is None:
            self.favorite = IFavoriting(self.context)

        if self.is_manager is None:
            self.pm = getToolByName(self.context, 'portal_membership')
            self.is_manager = self.pm.checkPermission(
                ViewManagementScreens, self.context)
            self.can_favorite = self.pm.checkPermission(
                DoFavorite, self.context)

    def favorited(self):
        "是否已被当前用户收藏,true:已被收藏"

        userid = self.pm.getAuthenticatedMember().getId()
        return not(self.favorite.favavailable(userid))

    def number(self):
        return self.favorite.number()

    def has_favorites(self):
        return (self.number() > 0)
Beispiel #2
0
class Favorite(base.ViewletBase):

    favorite = None
    is_manager = None
    can_favorite = None

    # Update methods are guaranteed to be called before rendering for
    # Viewlets and Portlets (Because they are IContentProvider objects)
    # and for z3c.forms and formlib forms. But *not* for normal Browser Pages
    def update(self):
        super(Favorite, self).update()

        if self.favorite is None:
            self.favorite = IFavoriting(self.context)

        if self.is_manager is None:
            self.pm = getToolByName(self.context, 'portal_membership')
            self.is_manager = self.pm.checkPermission(ViewManagementScreens,
                                                      self.context)
            self.can_favorite = self.pm.checkPermission(
                DoFavorite, self.context)

    def favorited(self):
        "是否已被当前用户收藏,true:已被收藏"

        userid = self.pm.getAuthenticatedMember().getId()
        return not (self.favorite.favavailable(userid))

    def number(self):
        return self.favorite.number()

    def has_favorites(self):
        return (self.number() > 0)
Beispiel #3
0
 def isfavorited(self,answer):
     """提供答案的brain,判断当前答案是否已被收藏,返回boolean"""
     obj = answer.getObject()
     aobj = IFavoriting(obj)
     
     userobject = self.pm().getAuthenticatedMember()
     userid = userobject.getId()
     return aobj.favavailable(userid)
Beispiel #4
0
 def isfavorited(self):
     """判断当前答案是否已被收藏,返回boolean"""
     obj = self.context
     aobj = IFavoriting(obj)
     
     userobject = self.pm().getAuthenticatedMember()
     userid = userobject.getId()          
     return aobj.favavailable(userid)
Beispiel #5
0
    def update(self):
        super(Favorite, self).update()

        if self.favorite is None:
            self.favorite = IFavoriting(self.context)

        if self.is_manager is None:
            self.pm = getToolByName(self.context, 'portal_membership')
            self.is_manager = self.pm.checkPermission(ViewManagementScreens,
                                                      self.context)
            self.can_favorite = self.pm.checkPermission(
                DoFavorite, self.context)
Beispiel #6
0
    def test_AddFavorite_event(self):
        from emc.memberArea.interfaces import IFavoriteEvent,IUnFavoriteEvent
        from emc.memberArea.events import FavoriteEvent,UnFavoriteEvent
#         from emc.kb.events import FavoriteAnswerEvent
#         from emc.kb.events import UnFavoriteAnswerEvent
        from emc.kb.contents.answer import Ianswer
        from emc.memberArea.interfaces import IFavoriting
#         from emc.kb.interfaces import IVoting
        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ('Manager',))
        portal.invokeFactory('emc.kb.questionfolder', 'questionfolder')
        portal['questionfolder'].invokeFactory('emc.kb.question', 'question',
                             discription=u"discription",
                             additional=u"additional",
                             isfollowed=True,
                             affiliatedtopics=u"affiliatedtopics",
                             relatedquestion=u"relatedquestion",
                             followernum=u"followernum",
                             pageview=u"pageview",
                             date=u"date"
                             )
        portal['questionfolder']['question'].invokeFactory('emc.kb.answer', 'answer',
                             answerer=u"answerer",
                             voteNum=u"voteNum",
                             voters=u"voters",
                             content=u"content of the answer",
                             date=u"date of the answer",
                             )
        file=portal['questionfolder']['question']['answer']  
        event.notify(FavoriteEvent(file))
        mp = getToolByName(portal,'portal_membership')
        userobject = mp.getAuthenticatedMember()
        username = userobject.getId()
        favoritelist = list(userobject.getProperty('myfavorite'))
        evlute = IFavoriting(file)
        uuid = IUUID(file,None)
        self.assertTrue(uuid in favoritelist)
#         self.assertTrue(file.id in favoritelist)
        self.assertFalse(evlute.favavailable(username)) 

        event.notify(UnFavoriteEvent(file))
        mp = getToolByName(portal,'portal_membership')
        userobject= mp.getAuthenticatedMember()
        username = userobject.getId()
        favoritelist = list(userobject.getProperty('myfavorite'))
        evlute = IFavoriting(file) 
        uuid = IUUID(file,None)
        self.assertFalse(uuid in favoritelist)
#         self.assertFalse(file.id in favoritelist)
        self.assertTrue(evlute.favavailable(username))                    
Beispiel #7
0
def UnFavoriteAnswer(obj,event):
    """del the answer from the favorite"""
    mp = getToolByName(obj,'portal_membership')
    userobject = mp.getAuthenticatedMember()
    userid = userobject.getId()
    favoritelist = list(userobject.getProperty('myfavorite'))    
#     fav = mp.getHomeFolder(userid)['workspace']['favorite']
#     favoritelist = list(getattr(fav,'myfavorite',[]))
    uuid = IUUID(obj,None)
    if uuid == None:return    
    if  uuid in favoritelist:
        favoritelist.remove(uuid)
        userobject.setProperties(myfavorite=favoritelist)
#         setattr(fav,'myfavorite',favoritelist)
        
    ada = IFavoriting(obj)
    if not ada.favavailable(userid):
        ada.delfavorite(userid)
Beispiel #8
0
    def update(self):
        super(Favorite, self).update()

        if self.favorite is None:
            self.favorite = IFavoriting(self.context)

        if self.is_manager is None:
            self.pm = getToolByName(self.context, 'portal_membership')
            self.is_manager = self.pm.checkPermission(
                ViewManagementScreens, self.context)
            self.can_favorite = self.pm.checkPermission(
                DoFavorite, self.context)
Beispiel #9
0
def DoFavorite(obj,event):
    """add the obj to my favorite"""
    
    mp = getToolByName(obj,'portal_membership')
    userobject = mp.getAuthenticatedMember()
    userid = userobject.getId()
    favoritelist = list(userobject.getProperty('myfavorite'))   

#     import pdb
#     pdb.set_trace()
#     fav = mp.getHomeFolder(userid)['workspace']['favorite']
#     favoritelist = list(getattr(fav,'myfavorite',[]))
    
    uuid = IUUID(obj,None)
    if uuid == None:return
    if not uuid in favoritelist:
        favoritelist.append(uuid)
        userobject.setProperties(myfavorite=favoritelist)
#         setattr(fav,'myfavorite',favoritelist)
#         fav.reindexObject()
        
    ada = IFavoriting(obj)
    if ada.favavailable(userid):
        ada.addfavorite(userid)
Beispiel #10
0
    def test_project_LocalRoles(self):
        portal = self.layer['portal']
        app = self.layer['app']
        setRoles(portal, TEST_USER_ID, ('Manager', ))
        membership = getToolByName(portal, 'portal_membership')
        provideAdapter(AssignRoles)

        portal.invokeFactory('emc.memberArea.workspace', 'work1')
        portal['work1'].invokeFactory('emc.memberArea.messagebox', 'folder1')
        portal['work1']['folder1'].invokeFactory('emc.memberArea.outputbox',
                                                 'ou1')
        portal['work1']['folder1']['ou1'].invokeFactory(
            'emc.memberArea.message', 'me1')
        message = portal['work1']['folder1']['ou1']['me1']
        import transaction
        transaction.commit()
        #         alsoProvides(self.request,IFavoriteAdapter)
        self.assertEqual(IFavoriting(message).number(), 0)
        self.assertFalse(IFavoritable.providedBy(message))
        applyMarkers(message, ObjectCreatedEvent(message))
        #         event.notify(ObjectCreatedEvent(message))
        self.assertTrue(IFavoritable.providedBy(message))
        event.notify(FavoriteEvent(message))
        self.assertEqual(IFavoriting(message).number(), 1)
Beispiel #11
0
def delFavorite(obj,event):
        
    """判断当前答案是否被收藏,当对象被删除时,收藏也应删除"""    
    
    try:
        ada = IFavoriting(obj)
    except:
        return

    useridlist = ada.favorite
    if len(useridlist) == 0:
        return
    
    mp = getToolByName(obj, 'portal_membership')
    for userid in useridlist:
        fav = mp.getHomeFolder(userid)['workspace']['favorite']
        favoritelist = list(getattr(fav,'myfavorite',[]))
        uuid = IUUID(obj)
#         """删除用户收藏到答案"""        
        if uuid in favoritelist:
            favoritelist.remove(uuid)
            setattr(fav,'myfavorite',favoritelist)