def _q_index(request): context = {} current_user = request.user if current_user and request.method == "POST": name = request.get_form_var('name') description = request.get_form_var('description') p = Project.add(name=name, description=description, owner_id=current_user.id, creator_id=current_user.id) if p: return request.redirect('%s' % p.repo_name) has_proj = Project.get_by_name_and_owner(name, current_user.id) default_error = 'Create Failure. Please contact the administrator!' if has_proj is not None: context['error'] = 'Project has exists, Please confirm!' else: context['error'] = default_error context['current_user'] = current_user return st('/errors/common.html', **context) projects = Project.gets_by() context['projects'] = projects context['current_user'] = current_user return st('projects/index.html', **context)
def _q_index(request): context = {} if request.method == "POST": name = request.get_form_var('name') password = request.get_form_var('password') email = request.get_form_var('email') description = request.get_form_var('description') # Forced mail format must be correct if not _validate_email(email): context['name'] = name context['not_validate_email'] = True context['password'] = password context['email'] = email context['description'] = description return st('users/new.html', **context) user = User.add(name=name, password=password, description=description, email=email) if user: context['user'] = user user.set_session(request) request.user = user return request.redirect('/') users = User.gets_by() context['users'] = users return st('users/index.html', **context)
def comment(self, request): target = self.target issue = self.issue issue_id = self.issue_id current_user = request.user if request.method == 'POST': content = request.get_form_var('content', '').decode('utf-8') user = request.user user = user.name if user else None if user: author = user if content.strip(): comment = issue.add_comment(content, user) issue.add_participant(user) html = st('/widgets/issue/issue_comment.html', **locals()) else: return {'error': 'Content is empty'} if request.get_form_var('comment_and_close'): issue.close(author) # TODO: 重构feed后取消信号发送 issue_signal.send(author=author, content=content, issue_id=issue_id) dispatch('issue', data={ 'sender': author, 'content': content, 'issue': issue, }) return dict(r=0, reload=1, redirect_to=issue.url) elif request.get_form_var('comment_and_open'): issue.open() # TODO: 重构feed后取消信号发送 issue_signal.send(author=author, content=content, issue_id=issue_id) dispatch('issue', data={ 'sender': author, 'content': content, 'issue': issue, }) return dict(r=0, reload=1, redirect_to=issue.url) elif content: issue_comment_signal.send(author=author, content=comment.content, issue_id=comment.issue_id, comment_id=comment.id) dispatch('issue_comment', data={ 'sender': author, 'content': comment.content, 'issue': issue, 'comment': comment}) participants = issue.participants teams = Team.get_all_team_uids() participants_html = st('/widgets/participation.html', **locals()) # FIXME: locals()? return dict( r=0, html=html, participants_html=participants_html) return request.redirect(issue.url)
def _q_index(request): context = {} if request.method == "POST": name = request.get_form_var("name") password = request.get_form_var("password") email = request.get_form_var("email") description = request.get_form_var("description") # Forced mail format must be correct if not _validate_email(email): context["name"] = name context["not_validate_email"] = True context["password"] = password context["email"] = email context["description"] = description return st("users/new.html", **context) user = User.add(name=name, password=password, description=description, email=email) if user: context["user"] = user user.set_session(request) request.user = user return request.redirect("/") users = User.gets_by() context["users"] = users return st("users/index.html", **context)
def _q_exception_handler(request, exception): if isinstance(exception, TraversalError): error = exception return st('/errors/404.html', **locals()) if isinstance(exception, AccessError): error = exception return st('/errors/401.html', **locals()) else: raise exception
def pledge(self, request): if request.method == 'POST': amount = request.get_form_var('amount') if not amount.isdigit(): error = '请输入承诺贡献的PR数量' return st('/fair/pledge.html', request=request, issue=self.issue, error=error) amount = int(amount) self.issue.update_pledge(request.user, amount) return request.redirect(self.issue.url) return st('/fair/pledge.html', request=request, issue=self.issue)
def edit(self, request): gist = self.gist user = request.user if not user or user.username != gist.owner_id: raise AccessError() if request.method == 'POST': desc, is_public, names, contents, oids = _get_req_gist_data( request) gist.update(desc, names, contents, oids) return request.redirect(gist.url) tdt = dict(request=request, gist=gist, user=user) if is_mobile_device(request): return st('/m/gist/edit.html', **tdt) return st('/gist/edit.html', **tdt)
def _get_tmpl_tree(tmpl_target, ref, path, project_name, request): project = CodeDoubanProject.get_by_name(project_name) if not project: raise TraversalError("Wrong path for tree %s" % path) if project.is_mirror_project: mirror = CodeDoubanMirror.get_by_project_id(project.id) if not mirror.is_clone_completed: return st("/projects/mirror_cloning.html", **locals()) if not project.repo: raise TraversalError("Wrong path for tree %s" % path) if not ref: ref = project.default_branch tree_path = path.decode("utf-8") last_commit = project.repo.get_last_commit(ref, path=path) if ref else "" tdt = _tmpl_common_data(ref, path, project_name, request) user = tdt["user"] if user is not None: username = user.username cur_user_project = project.get_forked_project(username) if cur_user_project is not None: latest_branch = _latest_update_branch(cur_user_project, ref, user) if latest_branch: cur_user_latest_branch_name = "{0}:{1}".format(username, latest_branch) tdt["latest_update_branch"].append((cur_user_project, cur_user_latest_branch_name, latest_branch)) tdt.update({"lastcommit": last_commit}) tree = [] is_empty = True if last_commit: tree = project.repo.get_tree(ref, path) is_empty = False if tree else True if is_empty and not project.repo.is_empty: raise TraversalError("Wrong path for tree %s" % path) if isinstance(tree, basestring): raise TraversalError("Got a blob instead of a tree") # Add README code to tree if any for item in tree: if item["type"] == "blob" and (item["name"] == "README" or item["name"].startswith("README.")): readme_content = project.repo.get_file_by_ref("%s:%s" % (ref, item["path"])) tdt.update({"readme_content": format_md_or_rst(item["path"], readme_content, project.name)}) break tdt.update({"tree": tree, "tree_path": tree_path, "is_empty": is_empty}) return st(tmpl_target, **tdt)
def files_tab(self, request): # call by ajax user = request.user current_user = request.user ticket = self.ticket pullreq = self.pullreq project = self.project has_proj_perm = project.has_push_perm(user.name) if user else False show_merge_guide = ( has_proj_perm or user.username == ticket.author) \ if user and not ticket.closed else False # get line comments # commits = self.all_commits # last_commit_ref = commits[0].sha if commits else '' # linecomments = PullLineComment.gets_by_target_and_ref( # self.ticket.id, last_commit_ref) linecomments = PullLineComment.gets_by_target(self.ticket.id) # get diff(patches) # FIXME: ignore_space,这是被ajax请求的,js那边没这逻辑。应该在前端加一个按钮 whitespace = request.get_form_var('w', '0') if whitespace.isdigit() and int(whitespace) == 1: ignore = True else: ignore = False try: diff = pullreq.get_diff(ignore_space=ignore, rename_detection=True, linecomments=linecomments) except: # FIXME: diff 的默认值不该为 [],其他很多地方也是 diff = [] return st('/pull/diffs_pane.html', **locals())
def comment(self, request): if request.method == 'POST': content = request.get_form_var('content').decode('utf-8') if not content.strip(): return {'error': 'Content is empty!'} user = request.user current_user = request.user author = user.name comment = self.ticket.add_comment(content, author) ticket = self.ticket pullreq = self.pullreq project = self.project html = st('/pull/ticket_comment.html', **locals()) if request.get_form_var('comment_and_close'): close_pull(ticket, pullreq, user, content, comment, request) return dict(r=0, reload=1, redirect_to=self.url) elif request.get_form_var('comment_and_reopen'): if not pullreq.is_temp_pull(): ticket.open(author) return dict(r=0, reload=1, redirect_to=self.url) else: at_users = get_mentions_from_text(content) for u in at_users: User(u).add_invited_pull_request(ticket.id) return dict(r=0, html=html) return request.redirect(self.url)
def _q_index(request): user = request.user if not user: return request.redirect("/") all_rooms = Room.get_all_rooms() messages = get_room_message('lobby').get_messages() return st("chat.html", **locals())
def add_team(request): user = request.user if not user: return request.redirect("/") uid = request.get_form_var('uid') or '' name = request.get_form_var('name') or '' description = request.get_form_var('description') or '' errors = "" if request.method == "POST": teams = Team.gets() team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*') if not uid: error = 'uid_not_exists' elif not name: error = 'name_not_exists' elif uid != re.findall(team_uid_pattern, uid)[0]: error = 'invilid_uid' elif uid in [team.uid for team in teams]: error = 'uid_existed' elif User.check_exist(uid): error = 'user_id_existed' elif name in [team.name for team in teams]: error = 'name_existed' else: team = Team.add(uid, name, description) if team: team_created_signal.send(user.name, team_name=team.name, team_uid=team.uid) team.add_user(user, TEAM_OWNER) return request.redirect(team.url) return st('/teams/add_team.html', **locals())
def _q_index(request): user = request.user my_issues = [] if user: username = user.username your_projects = CodeDoubanProject.get_projects(owner=username, sortby='lru') watched_projects = CodeDoubanProject.get_watched_others_projects_by_user( # noqa user=username, sortby='lru') teams = Team.get_by_user_id(user.name) actions = get_user_inbox(username).get_actions( stop=PAGE_ACTIONS_COUNT - 1) badge_items = user.get_badge_items() # pull request # your_tickets = user.get_user_pull_requests_rank(limit=5) your_tickets = user.get_user_submit_pull_requests(limit=5) # issue project_ids = CodeDoubanProject.get_ids(user.name) dt = { 'state': "open", 'limit': 5, 'start': 0, } my_issues = ProjectIssue.gets_by_project_ids(project_ids, **dt) return st('newsfeed.html', **locals()) return request.redirect("/teams/")
def _q_index(request): user = request.user if user: list_type = request.get_form_var("list_type", "invited") n_invited = user.n_open_invited n_participated = user.n_open_participated n_yours = user.n_user_open_submit_pull_requests counts = [n_invited, n_participated, n_yours, None] tab_info = [] for tab, count in zip(MY_PULL_REQUESTS_TAB_INFO, counts): tab.update(count=count) tab_info.append(tab) if list_type == "participated": tickets = user.get_participated_pull_requests() elif list_type == "yours": tickets = user.get_user_submit_pull_requests() elif list_type == "explore": from vilya.models.ticket import Ticket tickets = Ticket.gets_all_opened() ticket_total_len = len(tickets) shuffle(tickets) else: tickets = user.get_invited_pull_requests() is_closed_tab = False ticket_total_len = len(tickets) return st('my_pull_requests.html', **locals())
def search(self, request): key_word = request.get_form_var('q') if not key_word: return self._index(request) status = request.get_form_var('status') user = request.user page = request.get_form_var('page', 1) project = self.project tickets = [] ticket_len = Ticket.get_count_by_proj_id(project.id) search_result = PullRequestSearch.search_a_phrase( key_word, project.id, size=ticket_len) if search_result and not search_result.get('error'): ticket_ids = [id for id, in SearchEngine.decode( search_result, ['ticket_id'])] tickets = Ticket.gets_by_projectid_and_ticketnumbers( project.id, ticket_ids) if status == "closed": tickets = [t for t in tickets if t.closed] else: tickets = [t for t in tickets if not t.closed] ticket_total_len = len(tickets) limit = TICKETS_COUNT_PER_PAGE start = TICKETS_COUNT_PER_PAGE * (int(page) - 1) tickets = tickets[start:start + limit] n_pages = (ticket_total_len - 1) / TICKETS_COUNT_PER_PAGE + 1 if status == "closed": is_closed_tab = True else: is_closed_tab = False open_tab_link = self.open_tab_link close_tab_link = self.close_tab_link return st('/pull/pulls.html', **locals())
def revisions(self, request): user = request.user gist = self.gist page = int(request.get_form_var('page', 1)) skip = 3 * (page - 1) revlist = gist.get_revlist_with_renames(max_count=3, skip=skip) link_prev = _make_links(self.id, int(page) - 1, ext="revisions") if revlist: link_next = _make_links(self.id, int(page) + 1, ext="revisions") else: link_next = '' content = [] for r in revlist: # FIXME: try-except ? content.append(gist.repo.get_diff(r.sha, rename_detection=True)) tdt = { 'request': request, 'gist': gist, 'content': content, 'revlist': revlist, 'link_prev': link_prev, 'link_next': link_next, 'user': user, 'current_user': user, } return st('/gist/gist_revisions.html', **tdt)
def _q_index(self, request): user = request.user team = self.team page = request.get_form_var('page', 1) state = request.get_form_var("state", "open") order = get_order_type(request, 'team_issues_order') team_issues = [] selected_tag_names = request.get_form_var('tags', '') if selected_tag_names: selected_tag_names = selected_tag_names.split(',') issue_ids = Tag.get_type_ids_by_names_and_target_id( TAG_TYPE_TEAM_ISSUE, selected_tag_names, team.id) team_issues = self.cls.gets_by_issue_ids(issue_ids, state) else: team_issues = self.cls.gets_by_target(team.id, state, order=order) n_team_issue = len(team_issues) show_tags = team.get_group_tags(selected_tag_names) is_closed_tab = None if state == "open" else True n_pages = 1 # TODO: 分页 return st('issue/team_issues.html', **locals())
def _q_index(request): user = request.user if user: all = request.get_form_var('all') scope = request.get_form_var('scope') unread = not all or all != '1' scope = ActionScope.getScope(scope) or '' # 不带scope则默认所有 actions = Notification.get_data(user.name) # 迁移数据 all_actions = [migrate_notif_data(action, user.name) for action in actions] if scope: actions = [action for action in all_actions if action.get('scope') == scope] else: actions = all_actions if unread: actions = [action for action in actions if not action.get('read')] count_dict = {s: len([a for a in all_actions if a.get('scope') == s and not a.get('read')]) for s in ActionScope.all_scopes} else: count_dict = {s: len([a for a in all_actions if a.get('scope') == s]) for s in ActionScope.all_scopes} count_dict['all'] = sum(count_dict.values()) return st('notifications.html', **locals()) else: return request.redirect("/hub/teams")
def _q_index(request): """recommendations timeline""" start = request.get_form_var('start') start = start and start.isdigit() and int(start) or 0 limit = 20 recs = Recommendation.gets(start=start, limit=limit) return st('recommendations.html', **locals())
def _q_lookup(self, request, revrange): current_user = request.user try: sha1, sha2 = revrange.split('...') except ValueError: raise TraversalError( 'please provide valid start & end revisions: /compare/sha1...sha2' ) # noqa project = self.project commits = project.repo.get_commits(sha2, sha1) if commits is False: raise TraversalError() lasttime = commits and commits[0].author_time.strftime( "%Y-%m-%d %H:%M:%S") or 'UNKNOWN' grouped_commits = groupby(commits, lambda c: c.author_time.date()) n_commits = len(commits) n_authors = len(set(c.author.username for c in commits)) diff = project.repo.get_diff(sha2, from_ref=sha1, rename_detection=True) #diffs = project.git.get_3dot_diff(sha1, sha2) n_files = diff.length if diff else 0 comments = [] for ci in commits: comments.extend(Comment.gets_by_proj_and_ref(project.id, ci.sha)) branches = project.repo.branches tags = project.repo.tags ref = project.default_branch n_comments = len(comments) ref_type = 'branch' if ref in branches else 'tag' \ if ref in tags else 'tree' return st('compare.html', **locals())
def _q_index(self, request): if self.name == 'issues': return request.redirect(self.team.url) user = request.user team = self.team page = request.get_form_var('page', 1) state = request.get_form_var('state', 'open') order = get_order_type(request, 'fair_issues_order') all_issues = [] selected_tag_names = request.get_form_var('tags', '') if selected_tag_names: selected_tag_names = selected_tag_names.split(',') issue_ids = Tag.get_type_ids_by_names_and_target_id( TAG_TYPE_FAIR_ISSUE, selected_tag_names, team.id) all_issues = self.cls.gets_by_issue_ids(issue_ids, state) else: all_issues = self.cls.gets_by_target(team.id, state, order=order) n_team_issue = len(all_issues) show_tags = team.get_group_tags(selected_tag_names) is_closed_tab = None if state == 'open' else True n_pages = 1 return st('/fair.html', **locals())
def _q_index(request): errors = [] key_lines = '' user = request.user sshkeys = user.sshkeys if request.method == "POST": key_lines = request.get_form_var('ssh') newsshkeys = [] errorkeys = [] for index, line in enumerate(key_lines.splitlines()): valid = SSHKey.validate(user.name, line) if not valid: errorkeys.append((index, line)) continue duplicated = SSHKey.is_duplicated(user.name, line) if duplicated: errorkeys.append((index, line)) continue newsshkeys.append(line) if not errorkeys: for key in newsshkeys: SSHKey.add(user.name, key) return request.redirect('/settings/ssh') error_prefix = 'Please check your SSH Key, Line: ' for no, key in errorkeys: error = error_prefix + '%s ' % no errors.append(error) return st('/settings/ssh.html', **locals())
def check_merge(self, request): """ return merge guide widget """ ticket = self.ticket project = self.project pullreq = self.pullreq auto_mergable = self.pullreq.is_auto_mergable() can_fastforward = self.pullreq.can_fastforward() user = request.user # FIXME menghan: 如果latest_commit_status不是针对最后一个commit,那么结果有误导性 latest_commit_status = None commits = pullreq.commits for commit in commits: cs = CommitStatuses(pullreq.from_proj.id, commit.sha) latest_commit_status = cs.latest() if latest_commit_status: break has_perm = project.has_push_perm(user.name) if user else False show_merge_btn = has_perm and not pullreq.is_up_to_date() return st('/pull/merge_guide.html', auto_mergable=auto_mergable, can_fastforward=can_fastforward, latest_commit_status=latest_commit_status, show_merge_btn=show_merge_btn, project=project, pullreq=pullreq, user=user, ticket=ticket, )
def _q_index(request): user = request.user if user: list_type = request.get_form_var("list_type", "invited") n_invited = user.n_open_invited n_participated = user.n_open_participated n_yours = user.n_user_open_submit_pull_requests counts = [n_invited, n_participated, n_yours, None] tab_info = [] for tab, count in zip(MY_PULL_REQUESTS_TAB_INFO, counts): tab.update(count=count) tab_info.append(tab) if list_type == "participated": tickets = user.get_participated_pull_requests() elif list_type == "yours": tickets = user.get_user_submit_pull_requests() elif list_type == "explore": from models.ticket import Ticket tickets = Ticket.gets_all_opened() ticket_total_len = len(tickets) shuffle(tickets) else: tickets = user.get_invited_pull_requests() is_closed_tab = False ticket_total_len = len(tickets) return st("my_pull_requests.html", **locals())
def _render(self, request, view='', error=None): current_user = request.user # TODO: user flash message ticket = self.ticket pullreq = self.pullreq project = self.project commits = self.all_commits try: diff_length = pullreq.get_diff_length() except: # FIXME: more exception detail diff_length = 0 user = request.user has_proj_perm = project.has_push_perm(user.name) if user else False show_merge_guide = (has_proj_perm or user.username == ticket.author) \ if user and not ticket.closed else False if not pullreq.merged and not ticket.closed: # FIXME: 这使得发邮件的时机有点奇怪?没人请求页面就不发吗? delta_commits = self.pullreq.get_delta_commits() if delta_commits: value = ','.join(c.sha for c in delta_commits) author = self.pullreq.from_proj.owner_name if self.ticket.add_commits(value, author): # 补充commits则发送通知邮件给pr参与者 dispatch('new_commits', data={ 'pullreq': self.pullreq, 'ticket': self.ticket, 'deltacommits': delta_commits, }) return st('/pull/ticket.html', **locals())
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 _q_lookup(self, request, revrange): current_user = request.user try: sha1, sha2 = revrange.split('...') except ValueError: raise TraversalError( 'please provide valid start & end revisions: /compare/sha1...sha2') # noqa project = self.project commits = project.repo.get_commits(sha2, sha1) if commits is False: raise TraversalError() lasttime = commits and commits[0].author_time.strftime( "%Y-%m-%d %H:%M:%S") or 'UNKNOWN' grouped_commits = groupby(commits, lambda c: c.author_time.date()) n_commits = len(commits) n_authors = len(set(c.author.username for c in commits)) diff = project.repo.get_diff(sha2, from_ref=sha1, rename_detection=True) #diffs = project.git.get_3dot_diff(sha1, sha2) n_files = diff.length if diff else 0 comments = [] for ci in commits: comments.extend(Comment.gets_by_proj_and_ref(project.id, ci.sha)) branches = project.repo.branches tags = project.repo.tags ref = project.default_branch n_comments = len(comments) ref_type = 'branch' if ref in branches else 'tag' \ if ref in tags else 'tree' return st('compare.html', **locals())
def check_merge(self, request): """ return merge guide widget """ ticket = self.ticket project = self.project pullreq = self.pullreq auto_mergable = self.pullreq.is_auto_mergable() can_fastforward = self.pullreq.can_fastforward() user = request.user # FIXME menghan: 如果latest_commit_status不是针对最后一个commit,那么结果有误导性 latest_commit_status = None commits = pullreq.commits for commit in commits: cs = CommitStatuses(pullreq.from_proj.id, commit.sha) latest_commit_status = cs.latest() if latest_commit_status: break has_perm = project.has_push_perm(user.name) if user else False show_merge_btn = has_perm and not pullreq.is_up_to_date() return st( '/pull/merge_guide.html', auto_mergable=auto_mergable, can_fastforward=can_fastforward, latest_commit_status=latest_commit_status, show_merge_btn=show_merge_btn, project=project, pullreq=pullreq, user=user, ticket=ticket, )
def _q_index(self, request): user = request.user path = '/'.join(self.parts) doc = self.doc(self.project, self.id, path) if not doc.exists: raise TraversalError if doc.is_template: tdt = { 'errors': '', 'user': user, 'request': request, 'project': self.project, } # FIXME tdt['doc'] = { # 'with_comment': self.builder.with_comment(), # 'docsdir': self.builder.dir, # 'base_path': self.base_path, 'docsdir': '', 'base_path': '', } tdt['doc'].update(doc.content) return st(doc.template, **tdt) request.response.set_content_type(doc.content_type) return doc.content
def search(self, request): key_word = request.get_form_var('q') if not key_word: return self._index(request) status = request.get_form_var('status') user = request.user page = request.get_form_var('page', 1) project = self.project tickets = [] ticket_len = Ticket.get_count_by_proj_id(project.id) search_result = PullRequestSearch.search_a_phrase(key_word, project.id, size=ticket_len) if search_result and not search_result.get('error'): ticket_ids = [ id for id, in SearchEngine.decode(search_result, ['ticket_id']) ] tickets = Ticket.gets_by_projectid_and_ticketnumbers( project.id, ticket_ids) if status == "closed": tickets = [t for t in tickets if t.closed] else: tickets = [t for t in tickets if not t.closed] ticket_total_len = len(tickets) limit = TICKETS_COUNT_PER_PAGE start = TICKETS_COUNT_PER_PAGE * (int(page) - 1) tickets = tickets[start:start + limit] n_pages = (ticket_total_len - 1) / TICKETS_COUNT_PER_PAGE + 1 if status == "closed": is_closed_tab = True else: is_closed_tab = False open_tab_link = self.open_tab_link close_tab_link = self.close_tab_link return st('/pull/pulls.html', **locals())
def mentioned(self, request): list_type = 'mentioned' state = request.get_form_var('state', 'open') page = request.get_form_var('page', 1) project_name = self.proj_name user = request.user project = self.project n_open_issues = project.n_open_issues n_closed_issues = project.n_closed_issues n_everyone_issues = 0 n_assigned_issues = 0 n_created_issues = 0 n_mentioned_issues = 0 n_pages = 0 issue_list = [] total_issues = 0 is_closed_tab = None if state == "open" else True if user: n_assigned_issues = user.get_n_assigned_issues_by_project( project.id, state) # noqa n_created_issues = user.get_n_created_issues_by_project( project.id, state) # noqa n_everyone_issues = n_open_issues \ if state == "open" else n_closed_issues return st('issue/issues.html', **locals())
def review_comment(self, request): ''' pull linecomment ''' user = request.user current_user = request.user if request.method == 'POST' and user: project = CodeDoubanProject.get_by_name(self.proj_name) project_id = project.id from_sha = request.get_form_var('from_sha') assert from_sha, "comment from_sha cannot be empty" old_path = request.get_form_var('old_path') assert old_path, "comment old_path cannot be empty" new_path = request.get_form_var('new_path') # position = request.get_form_var('position') # assert position, "comment position cannot be empty" from_oid = request.get_form_var('from_oid') assert from_oid, "comment from_oid cannot be empty" to_oid = request.get_form_var('to_oid') assert to_oid, "comment to_oid cannot be empty" old = request.get_form_var('old_no') old = int(old) if old.isdigit() else LINECOMMENT_INDEX_EMPTY new = request.get_form_var('new_no') new = int(new) if new.isdigit() else LINECOMMENT_INDEX_EMPTY content = request.get_form_var('content', '').decode('utf-8') # commit_author = request.get_form_var('commit_author') if not content.strip(): return {'error': 'Content is empty!'} author = user.name ticket = self.ticket linecomment = ticket.add_codereview(from_sha, '', old_path, new_path, from_oid, to_oid, old, new, author, content) pullreq = self.pullreq codereviews = [linecomment] at_users = get_mentions_from_text(content) for u in at_users: User(u).add_invited_pull_request(ticket.id) # TODO: 把dispatch 从model移到这里 # r.html_with_diff used by codelive return dict( r=0, html=st('/pull/ticket_linecomment.html', **locals()), html_with_diff=st('/pull/render_ticket_codereview.html', **locals()))
def _q_index(request): t_shirts = [ ['1994842254', 'normal系'], ['1994842218', '黑色系'], ['1994842153', '粉色系'], ['1994842093', '低调系'], ] return st('shop.html', **locals())
def _q_index(self, request): user = request.user tdt = { 'user': user, 'project': CodeDoubanProject.get_by_name(self.proj_name), 'request': request, } return st('settings/config.html', **tdt)
def _q_index(request): user = request.user if request.method == 'POST': desc, is_public, names, contents, oids = _get_req_gist_data(request) user = request.user owner_id = user and user.username or Gist.ANONYMOUS gist = Gist.add(desc, owner_id, is_public, names, contents) return request.redirect(gist.url) tdt = dict(request=request, gists=[], user=user) if user: gists = Gist.gets_by_owner(user.username, limit=4) tdt.update(dict(gists=gists)) if is_mobile_device(request): return st('/m/gist/index.html', **tdt) return st('/gist/index.html', **tdt)
def new(self, request): user = request.user current_user = request.user team = self.team tags = team.tags error = request.get_form_var('error') teams = Team.get_all_team_uids() return st('issue/new_team_issue.html', **locals())
def new(self, request): project_name = self.proj_name project = self.project user = request.user tags = project.tags error = request.get_form_var('error') teams = Team.get_all_team_uids() return st('issue/new.html', **locals())
def _q_index(request): context = {} if request.method == "POST": name = request.get_form_var('name') description = request.get_form_var('description') creator_id = int(request.get_form_var('creator_id', 1)) o = Organization.add(name=name, description=description, owner_id=creator_id, creator_id=creator_id) if o: return request.redirect('organizations/%s' % o.name) context['organization'] = o return st('organizations/index.html', **context) organizations = Organization.gets_by() context['organizations'] = organizations return st('organizations/index.html', **context)
def review_comment(self, request): ''' pull linecomment ''' user = request.user current_user = request.user if request.method == 'POST' and user: project = CodeDoubanProject.get_by_name(self.proj_name) project_id = project.id from_sha = request.get_form_var('from_sha') assert from_sha, "comment from_sha cannot be empty" old_path = request.get_form_var('old_path') assert old_path, "comment old_path cannot be empty" new_path = request.get_form_var('new_path') # position = request.get_form_var('position') # assert position, "comment position cannot be empty" from_oid = request.get_form_var('from_oid') assert from_oid, "comment from_oid cannot be empty" to_oid = request.get_form_var('to_oid') assert to_oid, "comment to_oid cannot be empty" old = request.get_form_var('old_no') old = int(old) if old.isdigit() else LINECOMMENT_INDEX_EMPTY new = request.get_form_var('new_no') new = int(new) if new.isdigit() else LINECOMMENT_INDEX_EMPTY content = request.get_form_var('content', '').decode('utf-8') # commit_author = request.get_form_var('commit_author') if not content.strip(): return {'error': 'Content is empty!'} author = user.name ticket = self.ticket linecomment = ticket.add_codereview(from_sha, '', old_path, new_path, from_oid, to_oid, old, new, author, content) pullreq = self.pullreq codereviews = [linecomment] at_users = get_mentions_from_text(content) for u in at_users: User(u).add_invited_pull_request(ticket.id) # TODO: 把dispatch 从model移到这里 # r.html_with_diff used by codelive return dict(r=0, html=st('/pull/ticket_linecomment.html', **locals()), html_with_diff=st( '/pull/render_ticket_codereview.html', **locals()))
def _get_tmpl_commits(tmpl_target, rev, path, project_name, request): project = CodeDoubanProject.get_by_name(project_name) show_merges = request.get_form_var('show_merges', None) if show_merges and show_merges.isdigit(): show_merges = int(show_merges) else: show_merges = 0 if path else 1 # Keep start_rev for older links start_rev = request.get_form_var('start_rev', None) if start_rev and not rev: rev = start_rev if not rev: rev = project.default_branch page = int(request.get_form_var('page', 1)) author = request.get_form_var('author', None) query = request.get_form_var('query', None) skip = NB_COMMITS_PER_PAGE * (page - 1) tdt = _tmpl_common_data(rev, path, project_name, request) revlist = project.repo.get_commits(rev, max_count=NB_COMMITS_PER_PAGE, skip=skip, path=path, author=author, query=query, no_merges=(not show_merges)) comment_counts = _get_comment_counts(revlist, project.id) # handle renamed file renames = dict() if revlist: # and not next: oldcommit = revlist[-1] renames = project.repo.get_renamed_files(oldcommit.sha) rename_from = renames.get(path, '') graph_data = generate_graph_data(revlist) older_revlist = project.repo.get_commits(rev, max_count=NB_COMMITS_PER_PAGE, skip=(NB_COMMITS_PER_PAGE * page), path=path, author=author, query=query) release = get_release(project.repository) tdt.update({ 'comment_counts': comment_counts, 'rename_from': rename_from, 'author': author, 'query': query, 'revlist': revlist, 'renames': renames, 'page': page, 'link_prev': _make_links(project, rev, author, path, page - 1, query), 'link_next': _make_links(project, rev, author, path, page + 1, query) if older_revlist else False, 'release': release, 'graph_data': graph_data, }) return st(tmpl_target, **tdt)