changeset 6234:e99a33d7d7f5

cleanup: use obj.foo_id instead of obj.foo.foo_id Don't use constructs like obj.user.user_id when obj.user_id works equally well (and potentially saves a database load).
author Søren Løvborg <sorenl@unity3d.com>
date Thu, 15 Sep 2016 17:22:56 +0200
parents dd6e3441b4f4
children 1903d3813ac4
files kallithea/controllers/admin/notifications.py kallithea/controllers/admin/repos.py kallithea/controllers/changeset.py kallithea/controllers/journal.py kallithea/controllers/pullrequests.py kallithea/model/user_group.py kallithea/templates/changeset/changeset_file_comment.html kallithea/templates/pullrequests/pullrequest_data.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/tests/models/test_notifications.py
diffstat 10 files changed, 18 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/notifications.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/controllers/admin/notifications.py	Thu Sep 15 17:22:56 2016 +0200
@@ -93,7 +93,7 @@
     def update(self, notification_id):
         try:
             no = Notification.get(notification_id)
-            owner = all(un.user.user_id == c.authuser.user_id
+            owner = all(un.user_id == c.authuser.user_id
                         for un in no.notifications_to_users)
             if h.HasPermissionAny('hg.admin')() or owner:
                 # deletes only notification2user
@@ -108,7 +108,7 @@
     def delete(self, notification_id):
         try:
             no = Notification.get(notification_id)
-            owner = any(un.user.user_id == c.authuser.user_id
+            owner = any(un.user_id == c.authuser.user_id
                         for un in no.notifications_to_users)
             if h.HasPermissionAny('hg.admin')() or owner:
                 # deletes only notification2user
--- a/kallithea/controllers/admin/repos.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/controllers/admin/repos.py	Thu Sep 15 17:22:56 2016 +0200
@@ -423,7 +423,7 @@
                          if x.repo_id != c.repo_info.repo_id]
 
         defaults = {
-            'id_fork_of': c.repo_info.fork.repo_id if c.repo_info.fork else ''
+            'id_fork_of': c.repo_info.fork_id if c.repo_info.fork_id else ''
         }
 
         c.active = 'advanced'
--- a/kallithea/controllers/changeset.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/controllers/changeset.py	Thu Sep 15 17:22:56 2016 +0200
@@ -422,7 +422,7 @@
         co = ChangesetComment.get_or_404(comment_id)
         if co.repo.repo_name != repo_name:
             raise HTTPNotFound()
-        owner = co.author.user_id == c.authuser.user_id
+        owner = co.author_id == c.authuser.user_id
         repo_admin = h.HasRepoPermissionAny('repository.admin')(repo_name)
         if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
             ChangesetCommentsModel().delete(comment=co)
--- a/kallithea/controllers/journal.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/controllers/journal.py	Thu Sep 15 17:22:56 2016 +0200
@@ -78,10 +78,10 @@
         return groups
 
     def _get_journal_data(self, following_repos):
-        repo_ids = [x.follows_repository.repo_id for x in following_repos
-                    if x.follows_repository is not None]
-        user_ids = [x.follows_user.user_id for x in following_repos
-                    if x.follows_user is not None]
+        repo_ids = [x.follows_repo_id for x in following_repos
+                    if x.follows_repo_id is not None]
+        user_ids = [x.follows_user_id for x in following_repos
+                    if x.follows_user_id is not None]
 
         filtering_criterion = None
 
--- a/kallithea/controllers/pullrequests.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/controllers/pullrequests.py	Thu Sep 15 17:22:56 2016 +0200
@@ -473,7 +473,7 @@
 
         ChangesetCommentsModel().create(
             text=_('Closed, next iteration: %s .') % pull_request.url(canonical=True),
-            repo=old_pull_request.other_repo.repo_id,
+            repo=old_pull_request.other_repo_id,
             author=c.authuser.user_id,
             pull_request=old_pull_request.pull_request_id,
             closing_pr=True)
@@ -536,7 +536,7 @@
     def delete(self, repo_name, pull_request_id):
         pull_request = PullRequest.get_or_404(pull_request_id)
         #only owner can delete it !
-        if pull_request.owner.user_id == c.authuser.user_id:
+        if pull_request.owner_id == c.authuser.user_id:
             PullRequestModel().delete(pull_request)
             Session().commit()
             h.flash(_('Successfully deleted pull request'),
@@ -758,7 +758,7 @@
                 raise HTTPForbidden()
 
         if delete == "delete":
-            if (pull_request.owner.user_id == c.authuser.user_id or
+            if (pull_request.owner_id == c.authuser.user_id or
                 h.HasPermissionAny('hg.admin')() or
                 h.HasRepoPermissionAny('repository.admin')(pull_request.org_repo.repo_name) or
                 h.HasRepoPermissionAny('repository.admin')(pull_request.other_repo.repo_name)
@@ -830,7 +830,7 @@
             #don't allow deleting comments on closed pull request
             raise HTTPForbidden()
 
-        owner = co.author.user_id == c.authuser.user_id
+        owner = co.author_id == c.authuser.user_id
         repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
         if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
             ChangesetCommentsModel().delete(comment=co)
--- a/kallithea/model/user_group.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/model/user_group.py	Thu Sep 15 17:22:56 2016 +0200
@@ -202,7 +202,7 @@
 
         user_group_member = None
         for m in user_group.members:
-            if m.user.user_id == user.user_id:
+            if m.user_id == user.user_id:
                 # Found this user's membership row
                 user_group_member = m
                 break
--- a/kallithea/templates/changeset/changeset_file_comment.html	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/templates/changeset/changeset_file_comment.html	Thu Sep 15 17:22:56 2016 +0200
@@ -24,7 +24,7 @@
               <a class="permalink" href="${co.url()}">&para;</a>
           </span>
 
-          %if co.author.user_id == c.authuser.user_id or h.HasRepoPermissionAny('repository.admin')(c.repo_name):
+          %if co.author_id == c.authuser.user_id or h.HasRepoPermissionAny('repository.admin')(c.repo_name):
             %if co.deletable():
               <div onClick="confirm('${_("Delete comment?")}') && deleteComment(${co.comment_id})" class="buttons delete-comment btn btn-mini" style="margin:0 5px">${_('Delete')}</div>
             %endif
@@ -81,7 +81,7 @@
 
                 %if c.pull_request is not None and ( \
                     h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) \
-                    or c.pull_request.owner.user_id == c.authuser.user_id):
+                    or c.pull_request.owner_id == c.authuser.user_id):
                 <div>
                   ${_('Finish pull request')}:
                   <label>
--- a/kallithea/templates/pullrequests/pullrequest_data.html	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_data.html	Thu Sep 15 17:22:56 2016 +0200
@@ -59,7 +59,7 @@
         </a>
       </td>
       <td style="text-align:right">
-        %if pr.owner.user_id == c.authuser.user_id:
+        %if pr.owner_id == c.authuser.user_id:
           ${h.form(url('pullrequest_delete', repo_name=pr.other_repo.repo_name, pull_request_id=pr.pull_request_id), style="display:inline-block")}
           <button class="action_button"
                   id="remove_${pr.pull_request_id}"
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Thu Sep 15 17:22:56 2016 +0200
@@ -15,7 +15,7 @@
 </%block>
 
 <%def name="main()">
-<% editable = not c.pull_request.is_closed() and (h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or c.pull_request.owner.user_id == c.authuser.user_id) %>
+<% editable = not c.pull_request.is_closed() and (h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or c.pull_request.owner_id == c.authuser.user_id) %>
 ${self.repo_context_bar('showpullrequest')}
 <div class="box">
   <!-- box / title -->
--- a/kallithea/tests/models/test_notifications.py	Thu Sep 15 17:40:29 2016 +0200
+++ b/kallithea/tests/models/test_notifications.py	Thu Sep 15 17:22:56 2016 +0200
@@ -70,7 +70,7 @@
             .filter(UserNotification.notification == notification).all()
 
         assert len(unotification) == len(usrs)
-        assert set([x.user.user_id for x in unotification]) == set(usrs)
+        assert set([x.user_id for x in unotification]) == set(usrs)
 
     def test_user_notifications(self):
         notification1 = NotificationModel().create(created_by=self.u1,