diff --git a/kallithea/config/routing.py b/kallithea/config/routing.py --- a/kallithea/config/routing.py +++ b/kallithea/config/routing.py @@ -718,6 +718,15 @@ def make_map(config): action='show_all', conditions=dict(function=check_repo, method=["GET"])) + rmap.connect('my_pullrequests', + '/my_pullrequests', + controller='pullrequests', + action='show_my', conditions=dict(method=["GET"])) + rmap.connect('my_pullrequests_data', + '/my_pullrequests_data', + controller='pullrequests', + action='show_my_data', conditions=dict(method=["GET"])) + rmap.connect('pullrequest_comment', '/{repo_name:.*?}/pull-request-comment/{pull_request_id}', controller='pullrequests', diff --git a/kallithea/controllers/pullrequests.py b/kallithea/controllers/pullrequests.py --- a/kallithea/controllers/pullrequests.py +++ b/kallithea/controllers/pullrequests.py @@ -48,7 +48,8 @@ from kallithea.lib.utils import action_l from kallithea.lib.vcs.utils import safe_str from kallithea.lib.vcs.exceptions import EmptyRepositoryError from kallithea.lib.diffs import LimitedDiffContainer -from kallithea.model.db import PullRequest, ChangesetStatus, ChangesetComment +from kallithea.model.db import PullRequest, ChangesetStatus, ChangesetComment,\ + PullRequestReviewers from kallithea.model.pull_request import PullRequestModel from kallithea.model.meta import Session from kallithea.model.repo import RepoModel @@ -257,6 +258,34 @@ class PullrequestsController(BaseRepoCon return render('/pullrequests/pullrequest_show_all.html') @LoginRequired() + def show_my(self): # my_account_my_pullrequests + c.show_closed = request.GET.get('pr_show_closed') + return render('/pullrequests/pullrequest_show_my.html') + + @NotAnonymous() + def show_my_data(self): + c.show_closed = request.GET.get('pr_show_closed') + + def _filter(pr): + s = sorted(pr, key=lambda o: o.created_on, reverse=True) + if not c.show_closed: + s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s) + return s + + c.my_pull_requests = _filter(PullRequest.query()\ + .filter(PullRequest.user_id == + self.authuser.user_id)\ + .all()) + + c.participate_in_pull_requests = _filter(PullRequest.query()\ + .join(PullRequestReviewers)\ + .filter(PullRequestReviewers.user_id == + self.authuser.user_id)\ + ) + + return render('/pullrequests/pullrequest_show_my_data.html') + + @LoginRequired() @NotAnonymous() @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py --- a/kallithea/lib/base.py +++ b/kallithea/lib/base.py @@ -55,6 +55,7 @@ from kallithea.model.db import Repositor from kallithea.model.notification import NotificationModel from kallithea.model.scm import ScmModel from kallithea.model.meta import Session +from kallithea.model.pull_request import PullRequestModel log = logging.getLogger(__name__) @@ -319,6 +320,9 @@ class BaseController(WSGIController): .get_unread_cnt_for_user(c.authuser.user_id) self.cut_off_limit = safe_int(config.get('cut_off_limit')) + + c.my_pr_count = PullRequestModel().get_pullrequest_cnt_for_user(c.authuser.user_id) + self.sa = meta.Session self.scm_model = ScmModel(self.sa) diff --git a/kallithea/model/pull_request.py b/kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py +++ b/kallithea/model/pull_request.py @@ -49,6 +49,13 @@ class PullRequestModel(BaseModel): def __get_pull_request(self, pull_request): return self._get_instance(PullRequest, pull_request) + def get_pullrequest_cnt_for_user(self, user): + return PullRequest.query()\ + .join(PullRequestReviewers)\ + .filter(PullRequestReviewers.user_id == user)\ + .filter(PullRequest.status != PullRequest.STATUS_CLOSED)\ + .count() + def get_all(self, repo_name, from_=False, closed=False): """Get all PRs for repo. Default is all PRs to the repo, PRs from the repo if from_. diff --git a/kallithea/templates/base/base.html b/kallithea/templates/base/base.html --- a/kallithea/templates/base/base.html +++ b/kallithea/templates/base/base.html @@ -222,7 +222,78 @@ %def> -<%def name="usermenu()"> +<%def name="menu(current=None)"> + <% + def is_current(selected): + if selected == current: + return h.literal('class="current"') + %> + +