def test_unwatch(self):
        w = CQDEWatchlistStore()
        w.watch_project(32, 23, "immediate")
        w.watch_project(34, 23, "daily")

        w.unwatch_project(32, 23)

        watchlist = w.get_projects_by_user(32)
        self.assertTrue(len(watchlist) == 0)
        watchlist = w.get_projects_by_user(34)
        self.assertTrue(len(watchlist) == 1)

        watchlist = w.get_watchers_by_project(23)
        self.assertTrue(len(watchlist) == 1)
        self.assertFalse(w.is_watching(32, 23))
    def test_unwatch(self):
        w = CQDEWatchlistStore()
        w.watch_project(32, 23, "immediate")
        w.watch_project(34, 23, "daily")

        w.unwatch_project(32, 23)

        watchlist = w.get_projects_by_user(32)
        self.assertTrue(len(watchlist) == 0)
        watchlist = w.get_projects_by_user(34)
        self.assertTrue(len(watchlist) == 1)

        watchlist = w.get_watchers_by_project(23)
        self.assertTrue(len(watchlist) == 1)
        self.assertFalse(w.is_watching(32, 23))
Пример #3
0
    def save_watchlist(self, req):
        user = get_userstore().getUser(req.authname)
        if not user:
            return

        w = CQDEWatchlistStore()
        if req.args.get('notification'):
            notifylist = self.__to_list(req.args.get('notification'))
            for item in notifylist:
                project_id, notification = item.split('_')
                w.watch_project(user.id, project_id, notification)

        if req.args.get('remove'):
            removelist = self.__to_list(req.args.get('remove'))
            for project_id in removelist:
                w.unwatch_project(user.id, project_id)
Пример #4
0
    def process_request(self, req):
        """
        Handles the request

        :param req: Request
        :return: json
        """
        if req.method != 'POST':
            raise TracError('Invalid request')

        req.perm.require('TIMELINE_VIEW')

        userstore = get_userstore()
        watchstore = CQDEWatchlistStore()
        action = req.args.get('action')
        project_id = 0

        # Determine project id from URL
        match = REQ_REGEXP.match(req.path_info)
        if match:
            project_id = int(match.group('pid'))

        # Load userinfo
        user = userstore.getUser(req.authname)
        uid = user.id if user else None

        #load project
        project = Project.get(id=project_id)

        # Start following
        if action == 'watch':
            watchstore.watch_project(uid, project_id)

            # Notify listeners.
            for listener in self.project_change_listeners:
                try:
                    listener.project_watchers(project)
                except:
                    pass

        # Stop following
        elif action == 'unwatch':
            watchstore.unwatch_project(uid, project_id)

        goto = req.args.get('goto', req.href(''))
        return req.redirect(goto)
    def save_watchlist(self, req):
        user = get_userstore().getUser(req.authname)
        if not user:
            return

        w = CQDEWatchlistStore()
        if req.args.get('notification'):
            notifylist = self.__to_list(req.args.get('notification'))
            for item in notifylist:
                project_id, notification = item.split('_')
                w.watch_project(user.id, project_id, notification)
                
                # Notify listeners.
                project = Project.get(id=project_id)
                for listener in self.project_change_listeners:
                    listener.project_watchers(project)

        if req.args.get('remove'):
            removelist = self.__to_list(req.args.get('remove'))
            for project_id in removelist:
                w.unwatch_project(user.id, project_id)