Esempio n. 1
0
    def toggle_watching(self):
        """Add or remove the current authenticated member from the watchers.

        Taken from PoiIssue.

        If the current value is a tuple, we keep it that way.
        """
        memship = getToolByName(self.context, 'portal_membership', None)
        if memship is None:
            return
        if memship.isAnonymousUser():
            return
        member = memship.getAuthenticatedMember()
        member_id = member.getId()
        watchers = self.watchers
        if isinstance(watchers, tuple):
            watchers = list(watchers)
            as_tuple = True
        else:
            as_tuple = False
        if member_id in self.watchers:
            notify(event.ToggleWatchingEvent(self.context))
            notify(event.RemovedFromWatchingEvent(self.context))
            watchers.remove(member_id)
        else:
            notify(event.ToggleWatchingEvent(self.context))
            notify(event.AddedToWatchingEvent(self.context))
            watchers.append(member_id)
        if as_tuple:
            self.watchers = tuple(watchers)
        else:
            self.watchers = watchers
Esempio n. 2
0
 def remove(self, item):
     notify(event.ToggleWatchingEvent(self.context))
     notify(event.RemovedFromWatchingEvent(self.context))
     self.watchers.remove(item)
Esempio n. 3
0
 def append(self, item):
     notify(event.ToggleWatchingEvent(self.context))
     notify(event.AddedToWatchingEvent(self.context))
     self.watchers.append(item)