def UnFavoriteAnswer(obj,event):
    """del the answer from the favorite"""
    mp = getToolByName(obj,'portal_membership')
    userobject = mp.getAuthenticatedMember()
    username = userobject.getId()
    favoritelist = list(userobject.getProperty('myfavorite'))
    
    if  obj.id in favoritelist:
        favoritelist.remove(obj.id)
        userobject.setProperties(myfavorite=favoritelist)
        
    evlute = IEvaluate(obj)
    if evlute.favavailable(username):
        evlute.delfavorite(username)
def FavoriteAnswer(obj,event):
    """add the answer to favorite"""
    
    mp = getToolByName(obj,'portal_membership')
    userobject = mp.getAuthenticatedMember()
    username = userobject.getId()
    favoritelist = list(userobject.getProperty('myfavorite'))
    
    if not obj.id in favoritelist:
        favoritelist.append(obj.id)
        userobject.setProperties(myfavorite=favoritelist)
        
    evlute = IEvaluate(obj)
    if not evlute.favavailable(username):
        evlute.addfavorite(username)
    def test_followed_event(self):
        from collective.conference.conference import IConference
        from collective.conference.interfaces import IEvaluate

        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ('Manager',))
        portal.invokeFactory('collective.conference.conference', 'conference1',
                             title=u'conference1',
                             participants=['member1'])
        portal['conference1'].invokeFactory('collective.conference.session', 'session1',
                             description=u"description",
                             additional=u"additional"

                             )
        
        file=portal['conference1']['session1']
        file=portal['conference1']        
        event.notify(FollowedEvent(file))
        
        mp = getToolByName(portal,'portal_membership')
        userobject = mp.getAuthenticatedMember()
        username = userobject.getUserName()
#        import pdb
#        pdb.set_trace()
        questionlist = userobject.getProperty('myquestions')
        evlute = IEvaluate(file)
        
        self.assertTrue(file.id in questionlist)
        
        self.assertTrue(evlute.favavailable(username))
        self.assertEqual(1, evlute.followerNum)
        
        event.notify(UnfollowedEvent(file))
        
        mp = getToolByName(portal,'portal_membership')
        userobject = mp.getAuthenticatedMember()
        username = userobject.getUserName()
        questionlist = userobject.getProperty('myquestions')
        evlute = IEvaluate(file)
        
        self.assertFalse(file.id in questionlist)
        self.assertFalse(evlute.available(username))
        self.assertEqual(0, evlute.followerNum)
# fire register conf event        
        event.notify(RegisteredConfEvent(file))
        clists = userobject.getProperty('conferences')
        plists = file.participants
        self.assertTrue(file.id in clists)
#        username = '******'
        self.assertTrue(username in plists)
                        
        recorders = userobject.getProperty('bonusrecorder')
        useremail = userobject.getUserName()
     
        self.assertTrue(useremail in recorders[-1])
        self.assertTrue(file.title in recorders[-1])        
# fire unregister conf event        
        event.notify(UnRegisteredConfEvent(file))
        clists = userobject.getProperty('conferences')
        plists = file.participants
        self.assertFalse(file.id in clists)
#        username = '******'
        self.assertFalse(username in plists)
                        
        recorders = userobject.getProperty('bonusrecorder')
        useremail = userobject.getUserName()
     
        self.assertTrue(useremail in recorders[-1])
        self.assertTrue(file.title in recorders[-1])
        
          
# fire register session event        
        event.notify(RegisteredSessionEvent(file))
        slists = userobject.getProperty('speeches')
        plists = file.participants
        speaklists = file.speakers        
        
        self.assertTrue(file.id in slists)
        self.assertTrue(username in plists)
        self.assertTrue(username in speaklists)