def add_watch(cls, proj_id, user_id): try: ProjectWatcher.create(project_id=proj_id, user_id=user_id) except IntegrityError: return None repo_watch_signal.send( cls.get(proj_id), project_id=proj_id, author=user_id)
def delete(self): from vilya.models.nteam import TeamProjectRelationship shutil.rmtree(self.git_real_path, ignore_errors=True) for hook in self.hooks: hook.destroy() ProjectWatcher.deletes(project_id=self.id) store.execute("delete from codedouban_projects " "where project_id=%s", (self.id,)) store.commit() self.clear_mc(self.id) CodeDoubanProject._flush_project_ids_by_owner(self.owner_id) rs = TeamProjectRelationship.gets(project_id=self.id) for r in rs: r.delete()
def get_watched_projects_by_user(cls, user, sortby=None): rs = ProjectWatcher.gets(user_id=user) ids = [r.project_id for r in rs] results = cls.gets(ids) if sortby: results.sort(key=lambda proj: proj.repo.get_last_update_timestamp(), reverse=True) return results
def get_watch_user_ids(cls, project_id): rs = ProjectWatcher.gets(project_id=project_id) return [r.user_id for r in rs]
def has_watched(cls, proj_id, user): w = ProjectWatcher.get(user_id=user.name, project_id=proj_id) return True if w else False
def del_watch(cls, proj_id, user_id): w = ProjectWatcher.get(user_id=user_id, project_id=proj_id) if w: w.delete()
def get_watched_count(cls, proj_id): return ProjectWatcher.count(project_id=proj_id)