예제 #1
0
파일: issue.py 프로젝트: 000fan000/code
    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)
예제 #2
0
파일: issue.py 프로젝트: 000fan000/code
 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())
예제 #3
0
파일: team.py 프로젝트: leeccong/code
 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())
예제 #4
0
파일: issue.py 프로젝트: jackfrued/code-1
 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())
예제 #5
0
 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())
예제 #6
0
파일: pull.py 프로젝트: jackfrued/code-1
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(
            commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(from_proj.id, from_ref,
                                             to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
예제 #7
0
파일: pull.py 프로젝트: 000fan000/code
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(
            from_proj.id, from_ref, to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
예제 #8
0
파일: issue.py 프로젝트: 000fan000/code
 def join(self, request):
     issue = self.issue
     user = request.user
     if user:
         issue.add_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants, teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
예제 #9
0
파일: issue.py 프로젝트: jackfrued/code-1
 def join(self, request):
     issue = self.issue
     user = request.user
     if user:
         issue.add_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants,
                                teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
예제 #10
0
파일: issue.py 프로젝트: 000fan000/code
 def leave(self, request):
     issue = self.issue
     user = request.user
     if user:
         if user.name == issue.creator_id:
             return dict(r=1, msg="Can't leave the issue created by you.")
         issue.delete_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants, teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
예제 #11
0
파일: issue.py 프로젝트: 000fan000/code
 def _q_index(self, request):
     show_close = True
     target = self.target
     issue = self.issue
     user = request.user
     current_user = request.user
     author = issue.creator
     i_am_author = user and issue.creator_id == user.username
     i_am_admin = user and target.is_admin(user.name)
     has_user_voted = issue.has_user_voted(user.name) if user else False
     vote_count = issue.vote_count
     teams = Team.get_all_team_uids()
     return st(self.issue_template, **locals())
예제 #12
0
파일: issue.py 프로젝트: jackfrued/code-1
 def _q_index(self, request):
     show_close = True
     target = self.target
     issue = self.issue
     user = request.user
     current_user = request.user
     author = issue.creator
     i_am_author = user and issue.creator_id == user.username
     i_am_admin = user and target.is_admin(user.name)
     has_user_voted = issue.has_user_voted(user.name) if user else False
     vote_count = issue.vote_count
     teams = Team.get_all_team_uids()
     return st(self.issue_template, **locals())
예제 #13
0
파일: issue.py 프로젝트: jackfrued/code-1
 def leave(self, request):
     issue = self.issue
     user = request.user
     if user:
         if user.name == issue.creator_id:
             return dict(r=1, msg="Can't leave the issue created by you.")
         issue.delete_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants,
                                teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
예제 #14
0
파일: pull.py 프로젝트: jackfrued/code-1
    def discussion_tab(self, request):
        # TODO: 把 get_diff 提到这里做
        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
        show_close = has_proj_perm or user.name == ticket.author \
            if user and not ticket.closed else False
        show_reopen = has_proj_perm or user.name == ticket.author \
            if user and ticket.closed and not pullreq.merged \
            and not pullreq.is_temp_pull() else False

        # 可以@到team_id
        teams = Team.get_all_team_uids()

        codereviews_group = ticket.get_codereviews_group()
        # 根据 patch(paths, from_sha) 缓存 raw_diff
        raw_diff_by_patch = {}
        key_func = lambda x: x.old_path + x.from_sha
        diff_by_linecomment_id = {}
        for id, linecomments in codereviews_group.iteritems():
            _default = linecomments[0]
            if key_func(_default) in raw_diff_by_patch:
                _diff = pullreq.get_diff(
                    raw_diff=raw_diff_by_patch[key_func(_default)],
                    linecomments=linecomments)
            else:
                _diff = pullreq.get_diff(ref=_default.from_sha,
                                         paths=_default.paths,
                                         rename_detection=True,
                                         linecomments=linecomments)
                if _diff:
                    raw_diff_by_patch[key_func(_default)] = _diff.raw_diff
            diff_by_linecomment_id[_default.id] = _diff

        return st('/pull/ticket_thread.html', **locals())
예제 #15
0
파일: pull.py 프로젝트: 000fan000/code
    def discussion_tab(self, request):
        # TODO: 把 get_diff 提到这里做
        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
        show_close = has_proj_perm or user.name == ticket.author \
            if user and not ticket.closed else False
        show_reopen = has_proj_perm or user.name == ticket.author \
            if user and ticket.closed and not pullreq.merged \
            and not pullreq.is_temp_pull() else False

        # 可以@到team_id
        teams = Team.get_all_team_uids()

        codereviews_group = ticket.get_codereviews_group()
        # 根据 patch(paths, from_sha) 缓存 raw_diff
        raw_diff_by_patch = {}
        key_func = lambda x: x.old_path + x.from_sha
        diff_by_linecomment_id = {}
        for id, linecomments in codereviews_group.iteritems():
            _default = linecomments[0]
            if key_func(_default) in raw_diff_by_patch:
                _diff = pullreq.get_diff(
                    raw_diff=raw_diff_by_patch[key_func(_default)],
                    linecomments=linecomments)
            else:
                _diff = pullreq.get_diff(
                    ref=_default.from_sha, paths=_default.paths,
                    rename_detection=True, linecomments=linecomments)
                if _diff:
                    raw_diff_by_patch[key_func(_default)] = _diff.raw_diff
            diff_by_linecomment_id[_default.id] = _diff

        return st('/pull/ticket_thread.html', **locals())
예제 #16
0
파일: issue.py 프로젝트: jackfrued/code-1
    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)