Ejemplo n.º 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()
Ejemplo n.º 2
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()
Ejemplo n.º 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()
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
 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())