changeset 4850:a40824531f68

controllers: don't pass rendered templates in context variables Some controllers used the followifng pattern: - render a data template into a context variable - for partial (ajax) requests, return the contents of this variable - for full-page requests, render the full page, which expands the value of the context variable Instead, avoid context variables let the controller simply render the full or partial page, and let the full page template include the partial page. Remove this context variable for templating and use render exclusively. From templates, use %include instead of context variables. This in line with the suggestions in the Pylons documentation: http://pylons-webframework.readthedocs.org/en/latest/helpers.html#partial-updates-with-ajax
author Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
date Sat, 21 Feb 2015 22:04:54 +0100
parents 5e94c0f9720c
children 508a49a1a02f
files kallithea/controllers/admin/admin.py kallithea/controllers/followers.py kallithea/controllers/forks.py kallithea/controllers/journal.py kallithea/controllers/pullrequests.py kallithea/templates/admin/admin.html kallithea/templates/followers/followers.html kallithea/templates/forks/forks.html kallithea/templates/journal/journal.html kallithea/templates/journal/public_journal.html kallithea/templates/pullrequests/pullrequest_show_all.html
diffstat 11 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/admin.py	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/controllers/admin/admin.py	Sat Feb 21 22:04:54 2015 +0100
@@ -141,8 +141,8 @@
             return url.current(filter=c.search_term, **kw)
 
         c.users_log = Page(users_log, page=p, items_per_page=10, url=url_generator)
-        c.log_data = render('admin/admin_log.html')
 
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.log_data
+            return render('admin/admin_log.html')
+
         return render('admin/admin.html')
--- a/kallithea/controllers/followers.py	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/controllers/followers.py	Sat Feb 21 22:04:54 2015 +0100
@@ -53,9 +53,7 @@
             .order_by(UserFollowing.follows_from)
         c.followers_pager = Page(d, page=p, items_per_page=20)
 
-        c.followers_data = render('/followers/followers_data.html')
-
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.followers_data
+            return render('/followers/followers_data.html')
 
         return render('/followers/followers.html')
--- a/kallithea/controllers/forks.py	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/controllers/forks.py	Sat Feb 21 22:04:54 2015 +0100
@@ -123,10 +123,8 @@
             d.append(r)
         c.forks_pager = Page(d, page=p, items_per_page=20)
 
-        c.forks_data = render('/forks/forks_data.html')
-
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.forks_data
+            return render('/forks/forks_data.html')
 
         return render('/forks/forks.html')
 
--- a/kallithea/controllers/journal.py	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/controllers/journal.py	Sat Feb 21 22:04:54 2015 +0100
@@ -207,9 +207,8 @@
         c.journal_pager = Page(journal, page=p, items_per_page=20, url=url_generator)
         c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
 
-        c.journal_data = render('journal/journal_data.html')
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.journal_data
+            return render('journal/journal_data.html')
 
         repos_list = Session().query(Repository)\
                      .filter(Repository.user_id ==
@@ -350,9 +349,9 @@
 
         c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
 
-        c.journal_data = render('journal/journal_data.html')
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.journal_data
+            return render('journal/journal_data.html')
+
         return render('journal/public_journal.html')
 
     @LoginRequired(api_access=True)
--- a/kallithea/controllers/pullrequests.py	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/controllers/pullrequests.py	Sat Feb 21 22:04:54 2015 +0100
@@ -204,10 +204,8 @@
 
         c.pullrequests_pager = Page(c.pull_requests, page=p, items_per_page=10)
 
-        c.pullrequest_data = render('/pullrequests/pullrequest_data.html')
-
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
-            return c.pullrequest_data
+            return render('/pullrequests/pullrequest_data.html')
 
         return render('/pullrequests/pullrequest_show_all.html')
 
--- a/kallithea/templates/admin/admin.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/admin/admin.html	Sat Feb 21 22:04:54 2015 +0100
@@ -27,7 +27,7 @@
     <!-- end box / title -->
     <div class="table">
         <div id="user_log">
-            ${c.log_data}
+            <%include file='admin_log.html'/>
         </div>
     </div>
 </div>
--- a/kallithea/templates/followers/followers.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/followers/followers.html	Sat Feb 21 22:04:54 2015 +0100
@@ -22,7 +22,7 @@
     <!-- end box / title -->
     <div class="table">
         <div id="followers">
-            ${c.followers_data}
+            <%include file='followers_data.html'/>
         </div>
     </div>
 </div>
--- a/kallithea/templates/forks/forks.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/forks/forks.html	Sat Feb 21 22:04:54 2015 +0100
@@ -23,7 +23,7 @@
     <!-- end box / title -->
     <div class="table">
         <div id="forks">
-            ${c.forks_data}
+            <%include file='forks_data.html'/>
         </div>
     </div>
 </div>
--- a/kallithea/templates/journal/journal.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/journal/journal.html	Sat Feb 21 22:04:54 2015 +0100
@@ -36,7 +36,9 @@
            </li>
          </ul>
         </div>
-        <div id="journal">${c.journal_data}</div>
+        <div id="journal">
+            <%include file='journal_data.html'/>
+        </div>
     </div>
     <div class="box box-right">
         <!-- box / title -->
--- a/kallithea/templates/journal/public_journal.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/journal/public_journal.html	Sat Feb 21 22:04:54 2015 +0100
@@ -28,7 +28,9 @@
      </ul>
   </div>
 
-  <div id="journal">${c.journal_data}</div>
+  <div id="journal">
+    <%include file='journal_data.html'/>
+  </div>
 </div>
 
 </%def>
--- a/kallithea/templates/pullrequests/pullrequest_show_all.html	Thu Feb 26 23:57:38 2015 +0100
+++ b/kallithea/templates/pullrequests/pullrequest_show_all.html	Sat Feb 21 22:04:54 2015 +0100
@@ -51,7 +51,7 @@
         </div>
     </div>
 
-    ${c.pullrequest_data}
+    <%include file='pullrequest_data.html'/>
 
 </div>
 </%def>