changeset 5089:196c46444d98

pullrequests: add PullRequest.nice_id method Currently, a pull request id is referenced as #5, and the '#' symbol is fixed and repeated in several places. This commit adds a class method make_nice_id, that returns a string reference to a pull request, currently in the form '#5'. This function could be overridden by an organization if they need references in another form, for example PR-5. The method nice_id uses this for the pullrequest's own id.
author Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
date Fri, 17 Apr 2015 12:14:19 +0200
parents d0d386e51d06
children 0c58b6dc5512
files kallithea/lib/helpers.py kallithea/model/comment.py kallithea/model/db.py kallithea/model/notification.py kallithea/model/pull_request.py kallithea/templates/changelog/changelog.html kallithea/templates/changelog/changelog_summary_data.html kallithea/templates/pullrequests/pullrequest_show.html
diffstat 8 files changed, 29 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/lib/helpers.py	Fri Apr 17 12:14:19 2015 +0200
@@ -423,7 +423,7 @@
 #==============================================================================
 from kallithea.lib.vcs.utils import author_name, author_email
 from kallithea.lib.utils2 import credentials_filter, age as _age
-from kallithea.model.db import User, ChangesetStatus
+from kallithea.model.db import User, ChangesetStatus, PullRequest
 
 age = lambda  x, y=False: _age(x, y)
 capitalize = lambda x: x.capitalize()
@@ -736,12 +736,15 @@
 
     def get_pull_request():
         pull_request_id = action_params
+        nice_id = PullRequest.make_nice_id(pull_request_id)
+
         deleted = user_log.repository is None
         if deleted:
             repo_name = user_log.repository_name
         else:
             repo_name = user_log.repository.repo_name
-        return link_to(_('Pull request #%s') % pull_request_id,
+
+        return link_to(_('Pull request %s') % nice_id,
                     url('pullrequest_show', repo_name=repo_name,
                     pull_request_id=pull_request_id))
 
--- a/kallithea/model/comment.py	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/model/comment.py	Fri Apr 17 12:14:19 2015 +0200
@@ -126,9 +126,9 @@
             comment_url = pull_request.url(canonical=True,
                 anchor='comment-%s' % comment.comment_id)
             subj = safe_unicode(
-                h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
+                h.link_to('Re pull request %(pr_nice_id)s: %(desc)s %(line)s' % \
                           {'desc': desc,
-                           'pr_id': comment.pull_request.pull_request_id,
+                           'pr_nice_id': comment.pull_request.nice_id(),
                            'line': line},
                           comment_url)
             )
@@ -144,7 +144,7 @@
             #set some variables for email notification
             email_kwargs = {
                 'pr_title': pull_request.title,
-                'pr_id': pull_request.pull_request_id,
+                'pr_nice_id': pull_request.nice_id(),
                 'status_change': status_change,
                 'closing_pr': closing_pr,
                 'pr_comment_url': comment_url,
--- a/kallithea/model/db.py	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/model/db.py	Fri Apr 17 12:14:19 2015 +0200
@@ -1384,12 +1384,13 @@
 
         grouped = {}
         for stat in statuses.all():
-            pr_id = pr_repo = None
+            pr_id = pr_nice_id = pr_repo = None
             if stat.pull_request:
                 pr_id = stat.pull_request.pull_request_id
+                pr_nice_id = PullRequest.make_nice_id(pr_id)
                 pr_repo = stat.pull_request.other_repo.repo_name
             grouped[stat.revision] = [str(stat.status), stat.status_lbl,
-                                      pr_id, pr_repo]
+                                      pr_id, pr_repo, pr_nice_id]
         return grouped
 
     def _repo_size(self):
@@ -2305,6 +2306,15 @@
             .first()
         return str(status.status) if status else ''
 
+    @classmethod
+    def make_nice_id(cls, pull_request_id):
+        '''Return pull request id nicely formatted for displaying'''
+        return '#%s' % pull_request_id
+
+    def nice_id(self):
+        '''Return the id of this pull request, nicely formatted for displaying'''
+        return self.make_nice_id(self.pull_request_id)
+
     def __json__(self):
         return dict(
             revisions=self.revisions
--- a/kallithea/model/notification.py	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/model/notification.py	Fri Apr 17 12:14:19 2015 +0200
@@ -298,8 +298,8 @@
             # self.TYPE_PASSWORD_RESET
             self.TYPE_REGISTRATION: _('New user %(new_username)s registered'),
             # self.TYPE_DEFAULT
-            self.TYPE_PULL_REQUEST: _('Review request on %(repo_name)s pull request #%(pr_id)s from %(ref)s by %(pr_username)s'),
-            self.TYPE_PULL_REQUEST_COMMENT: _('Comment on %(repo_name)s pull request #%(pr_id)s from %(ref)s by %(comment_username)s'),
+            self.TYPE_PULL_REQUEST: _('Review request on %(repo_name)s pull request %(pr_nice_id)s from %(ref)s by %(pr_username)s'),
+            self.TYPE_PULL_REQUEST_COMMENT: _('Comment on %(repo_name)s pull request %(pr_nice_id)s from %(ref)s by %(comment_username)s'),
         }
 
     def get_email_description(self, type_, **kwargs):
--- a/kallithea/model/pull_request.py	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/model/pull_request.py	Fri Apr 17 12:14:19 2015 +0200
@@ -129,10 +129,10 @@
                                      pull_request_id=pr.pull_request_id)]
         subject = safe_unicode(
             h.link_to(
-              _('%(user)s wants you to review pull request #%(pr_id)s: %(pr_title)s') % \
+              _('%(user)s wants you to review pull request %(pr_nice_id)s: %(pr_title)s') % \
                 {'user': pr.author.username,
                  'pr_title': pr.title,
-                 'pr_id': pr.pull_request_id},
+                 'pr_nice_id': pr.nice_id()},
                 pr_url)
             )
         body = pr.description
@@ -144,7 +144,7 @@
             'pr_url': pr_url,
             'pr_revisions': revision_data,
             'repo_name': pr.other_repo.repo_name,
-            'pr_id': pr.pull_request_id,
+            'pr_nice_id': pr.nice_id(),
             'ref': org_ref_name,
             'pr_username': pr.author.username,
             'threading': threading,
--- a/kallithea/templates/changelog/changelog.html	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/templates/changelog/changelog.html	Fri Apr 17 12:14:19 2015 +0200
@@ -89,7 +89,7 @@
                           %if c.statuses.get(cs.raw_id):
                             <div class="changeset-status-ico">
                             %if c.statuses.get(cs.raw_id)[2]:
-                              <a class="tooltip" title="${_('Changeset status: %s\nClick to open associated pull request #%s') % (c.statuses.get(cs.raw_id)[1], c.statuses.get(cs.raw_id)[2])}" href="${h.url('pullrequest_show',repo_name=c.statuses.get(cs.raw_id)[3],pull_request_id=c.statuses.get(cs.raw_id)[2])}">
+                              <a class="tooltip" title="${_('Changeset status: %s\nClick to open associated pull request %s') % (c.statuses.get(cs.raw_id)[1], c.statuses.get(cs.raw_id)[4])}" href="${h.url('pullrequest_show',repo_name=c.statuses.get(cs.raw_id)[3],pull_request_id=c.statuses.get(cs.raw_id)[2])}">
                                 <i class="icon-circle changeset-status-${c.statuses.get(cs.raw_id)[0]}"></i>
                               </a>
                             %else:
--- a/kallithea/templates/changelog/changelog_summary_data.html	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/templates/changelog/changelog_summary_data.html	Fri Apr 17 12:14:19 2015 +0200
@@ -17,7 +17,7 @@
               %if c.statuses.get(cs.raw_id):
                 <div class="changeset-status-ico shortlog">
                 %if c.statuses.get(cs.raw_id)[2]:
-                  <a class="tooltip" title="${_('Changeset status: %s\nClick to open associated pull request #%s') % (c.statuses.get(cs.raw_id)[1], c.statuses.get(cs.raw_id)[2])}" href="${h.url('pullrequest_show',repo_name=c.statuses.get(cs.raw_id)[3],pull_request_id=c.statuses.get(cs.raw_id)[2])}">
+                  <a class="tooltip" title="${_('Changeset status: %s\nClick to open associated pull request %s') % (c.statuses.get(cs.raw_id)[1], c.statuses.get(cs.raw_id)[4])}" href="${h.url('pullrequest_show',repo_name=c.statuses.get(cs.raw_id)[3],pull_request_id=c.statuses.get(cs.raw_id)[2])}">
                     <i class="icon-circle changeset-status-${c.statuses.get(cs.raw_id)[0]}"></i>
                   </a>
                 %else:
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Sun May 03 22:08:22 2015 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Fri Apr 17 12:14:19 2015 +0200
@@ -3,11 +3,11 @@
 <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
 <%block name="title">
-    ${_('%s Pull Request #%s') % (c.repo_name, c.pull_request.pull_request_id)}
+    ${_('%s Pull Request %s') % (c.repo_name, c.pull_request.nice_id())}
 </%block>
 
 <%def name="breadcrumbs_links()">
-    ${_('Pull request #%s from %s#%s') % (c.pull_request.pull_request_id, c.pull_request.org_repo.repo_name, c.cs_branch_name)}
+    ${_('Pull request %s from %s#%s') % (c.pull_request.nice_id(), c.pull_request.org_repo.repo_name, c.cs_branch_name)}
 </%def>
 
 <%block name="header_menu">