[PATCH 4 of 5 v2] my pullrequests: line up controller/template handling with repo pullrequests

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Feb 24 16:36:06 EST 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at alcatel-lucent.com>
# Date 1424554186 -3600
#      Sat Feb 21 22:29:46 2015 +0100
# Node ID 2490789dd26d56d501793516ce32e0df30efa236
# Parent  35d2e797a6884547065c88d5b671f29aff2c5773
my pullrequests: line up controller/template handling with repo pullrequests

Currently, the data for 'my pullrequests' is loaded dynamically through
ajax, unlike the way 'repository pullrequests' are loaded (statically).

As there is no good reason to have both treated differently, and as dynamic
loading of 'my pullrequests' is not really needed, rework the handling of
the 'my pullrequests' page with the 'repository pullrequests' page.

This includes lining up the 'show closed pull requests' checkbox/link.

This also fixes issue #102 ('my pull requests' when not logged in:
incorrect handling of login).

diff --git a/kallithea/config/routing.py b/kallithea/config/routing.py
--- a/kallithea/config/routing.py
+++ b/kallithea/config/routing.py
@@ -729,10 +729,6 @@
                  '/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}',
diff --git a/kallithea/controllers/pullrequests.py b/kallithea/controllers/pullrequests.py
--- a/kallithea/controllers/pullrequests.py
+++ b/kallithea/controllers/pullrequests.py
@@ -210,17 +210,13 @@
         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 show_my(self):
+        c.closed = request.GET.get('closed') or ''
 
         def _filter(pr):
             s = sorted(pr, key=lambda o: o.created_on, reverse=True)
-            if not c.show_closed:
+            if not c.closed:
                 s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s)
             return s
 
@@ -235,7 +231,7 @@
                                         self.authuser.user_id)\
                                                  )
 
-        return render('/pullrequests/pullrequest_show_my_data.html')
+        return render('/pullrequests/pullrequest_show_my.html')
 
     @LoginRequired()
     @NotAnonymous()
diff --git a/kallithea/templates/pullrequests/pullrequest_show_my.html b/kallithea/templates/pullrequests/pullrequest_show_my.html
--- a/kallithea/templates/pullrequests/pullrequest_show_my.html
+++ b/kallithea/templates/pullrequests/pullrequest_show_my.html
@@ -20,31 +20,19 @@
         ${self.breadcrumbs()}
     </div>
 
-    <div id="pullrequests_container" class="table">
-        ## loaded via AJAX
-        ${_('Loading...')}
+    <div style="margin: 0 20px">
+        <div>
+        %if c.closed:
+            ${h.link_to(_('Hide closed pull requests (only show open pull requests)'), h.url('my_pullrequests'))}
+        %else:
+            ${h.link_to(_('Show closed pull requests (in addition to open pull requests)'), h.url('my_pullrequests',closed=1))}
+        %endif
+        </div>
     </div>
 
-<script type="text/javascript">
-pyroutes.register('my_pullrequests_data', "${url('my_pullrequests_data')}", []);
-
-var show_pullrequests = function(e){
-
-    var url = pyroutes.url('my_pullrequests_data');
-    if ($('#show_closed').prop('checked')) {
-        var url = pyroutes.url('my_pullrequests_data', {'pr_show_closed': '1'});
-    }
-    asynchtml(url, $('#pullrequests_container'), function(){
-        // new #show_closed has just been loaded
-        $('#show_closed').change(function (e) {
-            show_pullrequests(e);
-        });
-    });
-}
-show_pullrequests()
-
-</script>
+    <div id="pullrequests_container" class="table">
+        <%include file='pullrequest_show_my_data.html'/>
+    </div>
 
 </div>
-
 </%def>
diff --git a/kallithea/templates/pullrequests/pullrequest_show_my_data.html b/kallithea/templates/pullrequests/pullrequest_show_my_data.html
--- a/kallithea/templates/pullrequests/pullrequest_show_my_data.html
+++ b/kallithea/templates/pullrequests/pullrequest_show_my_data.html
@@ -1,4 +1,3 @@
-${h.checkbox('show_closed',checked="checked" if c.show_closed else "", label=_('Show closed pull requests (in addition to open pull requests)'))}
 <div class="pullrequests_section_head">${_('Pull Requests Created by Me')}</div>
 <ul>
   %if c.my_pull_requests:


More information about the kallithea-general mailing list