コード例 #1
0
def check_watch(entity):
    if not c.user:
        return None
    watch = Watch.find_by_entity(c.user, entity)
    if request.params.get('watch') and not watch:
        Watch.create(c.user, entity)
    elif watch:
        watch.delete()
    meta.Session.commit()
コード例 #2
0
ファイル: watchlist.py プロジェクト: veryrandomname/adhocracy
def set_watch(entity, set_watch=True):
    """
    Make sure that the current user watches entity, if set_watch is True. Make
    sure that the current user doesn't watch entity, if set_watch is False.
    """
    has_watch = Watch.find_by_entity(c.user, entity)
    if set_watch and has_watch is None:
        Watch.create(c.user, entity)
        meta.Session.commit()
    elif not set_watch and has_watch is not None:
        has_watch.delete()
        meta.Session.commit()
コード例 #3
0
def set_watch(entity, set_watch=True):
    """
    Make sure that the current user watches entity, if set_watch is True. Make
    sure that the current user doesn't watch entity, if set_watch is False.
    """
    has_watch = Watch.find_by_entity(c.user, entity)
    if set_watch and has_watch is None:
        Watch.create(c.user, entity)
        meta.Session.commit()
    elif not set_watch and has_watch is not None:
        has_watch.delete()
        meta.Session.commit()
コード例 #4
0
ファイル: watchlist.py プロジェクト: veryrandomname/adhocracy
def traverse_watchlist(entity):
    """
    Traverse the watchlist for all affected topics. Returns only
    the most closely matching watchlist entries.
    """

    def merge(outer, inner):
        return inner + [w for w in outer if
                        not w.user in [w.user for w in inner]]

    watches = Watch.all_by_entity(entity)

    if isinstance(entity, Comment):
        if entity.reply is not None:
            watches = merge(watches,
                            traverse_watchlist(entity.reply))
        else:
            watches = merge(watches,
                            traverse_watchlist(entity.topic))
    elif isinstance(entity, Delegateable):
        if entity.milestone is not None and not entity.milestone.is_deleted():
            watches = merge(watches, traverse_watchlist(entity.milestone))
        if len(entity.parents):
            for parent in entity.parents:
                watches = merge(watches,
                                traverse_watchlist(parent))
        else:
            watches = merge(watches,
                            traverse_watchlist(entity.instance))
    return watches
コード例 #5
0
def traverse_watchlist(entity):
    """
    Traverse the watchlist for all affected topics. Returns only
    the most closely matching watchlist entries.
    """
    def merge(outer, inner):
        return inner + [w for w in outer if \
            not w.user in [w.user for w in inner]]

    watches = Watch.all_by_entity(entity)

    if isinstance(entity, Comment):
        if entity.reply is not None:
            watches = merge(watches, traverse_watchlist(entity.reply))
        else:
            watches = merge(watches, traverse_watchlist(entity.topic))
    elif isinstance(entity, Delegateable):
        if entity.milestone is not None and not entity.milestone.is_deleted():
            watches = merge(watches, traverse_watchlist(entity.milestone))
        if len(entity.parents):
            for parent in entity.parents:
                watches = merge(watches, traverse_watchlist(parent))
        else:
            watches = merge(watches, traverse_watchlist(entity.instance))
    return watches
コード例 #6
0
 def _to_python(self, value, state):
     from adhocracy.model import Watch
     watch = Watch.by_id(value)
     if not watch:
         raise formencode.Invalid(
             _("No watchlist entry with ID '%s' exists") % value, value,
             state)
     return watch
コード例 #7
0
ファイル: common.py プロジェクト: whausen/part
 def _to_python(self, value, state):
     from adhocracy.model import Watch
     watch = Watch.by_id(value)
     if not watch:
         raise formencode.Invalid(
             _("No watchlist entry with ID '%s' exists") % value,
             value, state)
     return watch
コード例 #8
0
ファイル: test_user.py プロジェクト: alkadis/vcv
 def test_delete_user_deletes_watches(self):
     from adhocracy.model import Watch
     voter_group = Group.by_code(Group.CODE_VOTER)
     user = tt_make_user(instance_group=voter_group)
     instance = tt_get_instance()
     watch = Watch.create(user, instance)
     self.assertFalse(watch.is_deleted())
     user.delete()
     self.assertTrue(watch.is_deleted())
コード例 #9
0
ファイル: test_user.py プロジェクト: JonnyWalker/adhocracy
 def test_delete_user_deletes_watches(self):
     from adhocracy.model import Watch
     voter_group = Group.by_code(Group.CODE_VOTER)
     user = tt_make_user(instance_group=voter_group)
     instance = tt_get_instance()
     watch = Watch.create(user, instance)
     self.assertFalse(watch.is_deleted())
     user.delete()
     self.assertTrue(watch.is_deleted())
コード例 #10
0
ファイル: watchlist.py プロジェクト: alkadis/vcv
def clean_stale_watches():
    log.debug("Beginning to clean up watchlist entries...")
    count = 0
    for watch in Watch.all():
        if hasattr(watch.entity, "is_deleted") and watch.entity.is_deleted():
            count += 1
            watch.delete()
    meta.Session.commit()
    if count > 0:
        log.debug("Removed %d stale watchlist entries." % count)
コード例 #11
0
def clean_stale_watches():
    log.debug("Beginning to clean up watchlist entries...")
    count = 0
    for watch in Watch.all():
        if hasattr(watch.entity, 'is_deleted') and \
                watch.entity.is_deleted():
            count += 1
            watch.delete()
    meta.Session.commit()
    if count > 0:
        log.debug("Removed %d stale watchlist entries." % count)
コード例 #12
0
ファイル: watchlist.py プロジェクト: veryrandomname/adhocracy
def find_watch(entity):
    return Watch.find_by_entity(c.user, entity)
コード例 #13
0
def find_watch(entity):
    return Watch.find_by_entity(c.user, entity)