def card_info(request): user_or_team_id = request.get_form_var('user') team = Team.get_by_uid(user_or_team_id) user_existed = User.check_exist(user_or_team_id) if not team or user_existed: user = User(user_or_team_id) data = { 'user': {'name': user_or_team_id, 'avatar': user.avatar_url, 'url': user.url, 'badges': [{'img': item.badge.get_image_url(), 'name': item.badge.name, 'reason': item.reason or item.badge.summary} for item in user.get_badge_items()]} } else: members = team.user_ids[::-1] # 根据团队的时间排序 displayed_users = [User(uid) for uid in team.user_ids[:8]] data = { 'team': { 'id': team.uid, 'name': team.name, 'url': team.url, 'desc': team.short_description, 'profile_url': team.profile_url(), 'members': [{'uid': u.name, 'avatar_url': u.avatar_url} for u in displayed_users], 'member_count': len(members) } } return json.dumps(data)
def add_user(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1, error="team不存在") user_id = request.get_form_var("user_id", "") identity = int(request.get_form_var("identity", 0)) if not team.is_owner(user.name) or identity not in TEAM_IDENTITY_INFO.keys(): return dict(r=1, error="没有权限") rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id) if not rl: team.add_user(User(user_id), identity) elif identity == rl.identity: return dict(r=1, error="该用户已存在") elif rl.is_owner and team.n_owners == 1: return dict(r=1, error="只剩一个creator, 不能改变身份") else: rl.identity = identity rl.save() avatar_url = User(user_id).avatar_url team_add_member_signal.send( user.name, team_uid=team.uid, team_name=team.name, receiver=user_id, identity=TEAM_IDENTITY_INFO[identity]["name"], ) return dict(r=0, uid=user_id, avatar_url=avatar_url)
def settings(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError projects = team.projects input_uid = request.get_form_var("uid", "") input_name = request.get_form_var("name", "") input_description = request.get_form_var("description", "") error = "" if request.method == "POST": if not user: return request.redirect("/") if not team.is_owner(user.name): return request.redirect(team.url) teams = Team.gets() team_uid_pattern = re.compile(r"[a-zA-Z0-9\_]*") if not input_uid: error = "uid_not_exists" elif not input_name: error = "name_not_exists" elif input_uid != re.findall(team_uid_pattern, input_uid)[0]: error = "invilid_uid" elif input_uid in [t.uid for t in teams] and team.uid != input_uid: error = "uid_existed" elif input_name in [t.name for t in teams] and team.name != input_name: error = "name_existed" else: team.update(input_uid, input_name, input_description) return request.redirect("/hub/team/%s/settings" % input_uid) return st("/teams/team_settings.html", **locals())
def add_user(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1, error="team不存在") user_id = request.get_form_var('user_id', '') identity = int(request.get_form_var('identity', 0)) if not team.is_owner(user.name) \ or identity not in TEAM_IDENTITY_INFO.keys(): return dict(r=1, error="没有权限") rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id) if not rl: team.add_user(User(user_id), identity) elif identity == rl.identity: return dict(r=1, error="该用户已存在") elif rl.is_owner and team.n_owners == 1: return dict(r=1, error="只剩一个creator, 不能改变身份") else: rl.identity = identity rl.save() avatar_url = User(user_id).avatar_url team_add_member_signal.send( user.name, team_uid=team.uid, team_name=team.name, receiver=user_id, identity=TEAM_IDENTITY_INFO[identity]["name"]) return dict(r=0, uid=user_id, avatar_url=avatar_url)
def __init__(self, team_uid, issue_number): self.target = Team.get_by_uid(team_uid) self.issue_number = issue_number team_issue = TeamIssue.get(self.target.id, number=self.issue_number) self.issue_id = team_issue.issue_id self.issue = Issue.get_cached_issue(self.issue_id) self.issue_template = "issue/team_issue.html"
def __init__(self, team_uid, issue_number): self.target = Team.get_by_uid(team_uid) self.issue_number = issue_number team_issue = TeamIssue.get(self.target.id, number=self.issue_number) self.issue_id = team_issue.issue_id self.issue = Issue.get_cached_issue(self.issue_id) self.issue_template = 'issue/team_issue.html'
def leave(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) team.remove_user(user) return dict(r=0)
def _get_team_by_uid(uid): _team = Team.get_by_uid(uid) team = dict( id=_team.id, uid=_team.uid, name=_team.name, ) return team
def leave(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) team.remove_user(user) return dict(r=0)
def join(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) team.add_user(user, TEAM_MEMBER) team_joined_signal.send(user.name, team_id=team.id, team_uid=team.uid, team_name=team.name) return dict(r=0)
def judge_user(name): from vilya.models.team import Team if CodeUser.get(name=name): return "people" else: if Team.get_by_uid(name): return "team" else: return "people"
def judge_user(name): from vilya.models.team import Team if CodeUser.get(name=name): return "people" else: if Team.get_by_uid(name): return "team" else: return "people"
def _q_index(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError projects = team.projects is_admin = False if user and team.is_owner(user.name): is_admin = True return st("/teams/team.html", **locals())
def _q_index(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError projects = team.projects is_admin = False if user and team.is_owner(user.name): is_admin = True return st('/teams/team.html', **locals())
def _q_lookup(self, request, num): if not num.isdigit(): raise TraversalError num = int(num) team = Team.get_by_uid(self.team_uid) actions = get_team_feed(team.id).get_actions(start=num, stop=num+PAGE_ACTIONS_COUNT-1) length = len(actions) render_html = render_actions(actions, show_avatar=True) return {'result': render_html, 'length': length}
def remove(self, request): team = Team.get_by_uid(self.team_uid) if not team: return dict(r=1) user = request.user if not user or not team.is_owner(user.name): return dict(r=1) team.delete() return {"r": 0}
def remove(self, request): team = Team.get_by_uid(self.team_uid) if not team: return dict(r=1) user = request.user if not user or not team.is_owner(user.name): return dict(r=1) team.delete() return {'r': 0}
def _q_lookup(self, request, num): if not num.isdigit(): raise TraversalError num = int(num) team = Team.get_by_uid(self.team_uid) actions = get_team_feed(team.id).get_actions(start=num, stop=num + PAGE_ACTIONS_COUNT - 1) length = len(actions) render_html = render_actions(actions, show_avatar=True) return {'result': render_html, 'length': length}
def news(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError feed = get_team_feed(team.id) actions = feed.get_actions(stop=PAGE_ACTIONS_COUNT - 1) projects = team.projects is_admin = False if user and team.is_owner(user.name): is_admin = True return st("/teams/news.html", **locals())
def news(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError feed = get_team_feed(team.id) actions = feed.get_actions(stop=PAGE_ACTIONS_COUNT - 1) projects = team.projects is_admin = False if user and team.is_owner(user.name): is_admin = True return st('/teams/news.html', **locals())
def join(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) team.add_user(user, TEAM_MEMBER) team_joined_signal.send(user.name, team_id=team.id, team_uid=team.uid, team_name=team.name) return dict(r=0)
def destroy(self, request): project = self.project group_name = request.get_form_var('group', '') if not group_name: return request.redirect("%ssettings/" % project.url) team, _, group = group_name.rpartition('/') t = Team.get_by_uid(team) if not t: return request.redirect("%ssettings/" % project.url) g = TeamGroup.get(team_id=t.id, name=group) if not g: return request.redirect("%ssettings/" % project.url) g.remove_project(project_id=project.id) return request.redirect("%ssettings/" % project.url)
def destroy(self, request): project = self.project group_name = request.get_form_var('group', '') if not group_name: return request.redirect("%ssettings/" % project.url) team, _, group = group_name.rpartition('/') t = Team.get_by_uid(team) if not t: return request.redirect("%ssettings/" % project.url) g = TeamGroup.get(team_id=t.id, name=group) if not g: return request.redirect("%ssettings/" % project.url) g.remove_project(project_id=project.id) return request.redirect("%ssettings/" % project.url)
def remove_project(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) if not team.is_owner(user.name): return dict(r=1) project_name = request.get_form_var('project_name', '') project = CodeDoubanProject.get_by_name(project_name) if not project: return dict(r=1) team.remove_project(project) return dict(r=0)
def remove_project(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user or not team: return dict(r=1) if not team.is_owner(user.name): return dict(r=1) project_name = request.get_form_var("project_name", "") project = CodeDoubanProject.get_by_name(project_name) if not project: return dict(r=1) team.remove_project(project) return dict(r=0)
def card_info(request): user_or_team_id = request.get_form_var('user') team = Team.get_by_uid(user_or_team_id) user_existed = User.check_exist(user_or_team_id) if not team or user_existed: user = User(user_or_team_id) data = { 'user': { 'name': user_or_team_id, 'avatar': user.avatar_url, 'url': user.url, 'badges': [{ 'img': item.badge.get_image_url(), 'name': item.badge.name, 'reason': item.reason or item.badge.summary } for item in user.get_badge_items()] } } else: members = team.user_ids[::-1] # 根据团队的时间排序 displayed_users = [User(uid) for uid in team.user_ids[:8]] data = { 'team': { 'id': team.uid, 'name': team.name, 'url': team.url, 'desc': team.short_description, 'profile_url': team.profile_url(), 'members': [{ 'uid': u.name, 'avatar_url': u.avatar_url } for u in displayed_users], 'member_count': len(members) } } return json.dumps(data)
def upload_profile(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user and not team: return dict(r=1) if team and not team.is_owner(user.name): return dict(r=1) upload_url = request.get_form_var("url", "") hash_png = request.get_form_var("hash", "") profile = {"origin": upload_url} if upload_url and hash_png: rsize_url = "{0}/r/{1}?w=100&h=100".format(UPLOAD_URL, hash_png) r = requests.get(rsize_url) r.raise_for_status() profile.update({"icon": r.text}) team.profile = profile return dict(r=0)
def upload_profile(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user and not team: return dict(r=1) if team and not team.is_owner(user.name): return dict(r=1) upload_url = request.get_form_var('url', '') hash_png = request.get_form_var('hash', '') profile = {'origin': upload_url} if upload_url and hash_png: rsize_url = '{0}/r/{1}?w=100&h=100'.format(UPLOAD_URL, hash_png) r = requests.get(rsize_url) r.raise_for_status() profile.update({'icon': r.text}) team.profile = profile return dict(r=0)
def _q_index(request): sortby = request.get_form_var('sortby') if sortby in CodeDoubanProject.PROJECTS_SORT_BYS: project_list = CodeDoubanProject.get_projects(sortby=sortby) else: project_list = CodeDoubanProject.get_projects() team_uid = request.get_form_var('by_dept', '') team = Team.get_by_uid(team_uid) if team: project_ids = team.project_ids project_list = (CodeDoubanProject.gets(project_ids) if project_ids else []) without_commits = request.get_form_var('without_commits') or False data = {} data['projects'] = [project.get_info( without_commits=without_commits) for project in project_list] return json.dumps(data)
def add_project(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user and not team: return request.redirect('/') if team and not team.is_owner(user.name): return request.redirect(team.url) project_name = request.get_form_var('project_name') or '' project = CodeDoubanProject.get_by_name(project_name) error = '' if request.method == 'POST': if not project_name: error = 'project_name_not_exists' elif not project: error = 'project_not_exists' else: team.add_project(project) return request.redirect(team.url) return st('/teams/team_add_project.html', **locals())
def add_project(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not user and not team: return request.redirect("/") if team and not team.is_owner(user.name): return request.redirect(team.url) project_name = request.get_form_var("project_name") or "" project = CodeDoubanProject.get_by_name(project_name) error = "" if request.method == "POST": if not project_name: error = "project_name_not_exists" elif not project: error = "project_not_exists" else: team.add_project(project) return request.redirect(team.url) return st("/teams/team_add_project.html", **locals())
def remove_user(self, request): user = request.user if not user: return dict(r=1, error="用户未登录") team = Team.get_by_uid(self.team_uid) if not team: return dict(r=1, error="team不存在") user_id = request.get_form_var('user_id', '') if not team.is_owner(user.name): return dict(r=1, error="没有权限") rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id) if not rl: return dict(r=1, error="用户未加入team") elif rl.is_owner and team.n_owners == 1: return dict(r=1, error="只剩一个creator不能删除") else: rl.delete() return dict(r=0)
def remove_user(self, request): user = request.user if not user: return dict(r=1, error="用户未登录") team = Team.get_by_uid(self.team_uid) if not team: return dict(r=1, error="team不存在") user_id = request.get_form_var("user_id", "") if not team.is_owner(user.name): return dict(r=1, error="没有权限") rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id) if not rl: return dict(r=1, error="用户未加入team") elif rl.is_owner and team.n_owners == 1: return dict(r=1, error="只剩一个creator不能删除") else: rl.delete() return dict(r=0)
def settings(self, request): user = request.user team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError projects = team.projects input_uid = request.get_form_var('uid', '') input_name = request.get_form_var('name', '') input_description = request.get_form_var('description', '') error = '' if request.method == "POST": if not user: return request.redirect("/") if not team.is_owner(user.name): return request.redirect(team.url) teams = Team.gets() team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*') if not input_uid: error = 'uid_not_exists' elif not input_name: error = 'name_not_exists' elif input_uid != re.findall(team_uid_pattern, input_uid)[0]: error = 'invilid_uid' elif input_uid in [t.uid for t in teams] and team.uid != input_uid: error = 'uid_existed' elif input_name in [t.name for t in teams] \ and team.name != input_name: error = 'name_existed' else: team.update(input_uid, input_name, input_description) return request.redirect("/hub/team/%s/settings" % input_uid) return st('/teams/team_settings.html', **locals())
def pulls(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamPullsUI(self.team_uid)
def __init__(self, name): self.team = Team.get_by_uid(name)
def groups(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamGroupsUI(team)
def __init__(self, team_name): self.team_name = team_name self.team = Team.get_by_uid(team_name)
def groups(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamGroupsUI(team)
def __init__(self, team_uid): self.team_uid = team_uid self.team = Team.get_by_uid(self.team_uid)
def issue_comments(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamIssueCommentUI(self.team_uid)
def issue_comments(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamIssueCommentUI(self.team_uid)
def issues(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamIssueBoardUI(self.team_uid)
def __init__(self, team_uid): self.team_uid = team_uid self.team = Team.get_by_uid(self.team_uid) self.comment = None
def __init__(self, team_uid): self.team_uid = team_uid self.team = Team.get_by_uid(self.team_uid) self.comment = None
def __init__(self, team_uid): self.team_uid = team_uid self.team = Team.get_by_uid(self.team_uid)
def pulls(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamPullsUI(self.team_uid)
def issues(self): team = Team.get_by_uid(self.team_uid) if not team: raise TraversalError return TeamIssueBoardUI(self.team_uid)
def __init__(self, team_name): self.team_name = team_name self.team = Team.get_by_uid(team_name)