Changeset - a40824531f68
[Not reviewed]
default
0 11 0
Thomas De Schampheleire - 11 years ago 2015-02-21 22:04:54
thomas.de_schampheleire@alcatel-lucent.com
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
11 files changed with 18 insertions and 21 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/admin.py
Show inline comments
 
@@ -141,8 +141,8 @@ class AdminController(BaseController):
 
            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')
kallithea/controllers/followers.py
Show inline comments
 
@@ -53,9 +53,7 @@ class FollowersController(BaseRepoContro
 
            .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')
kallithea/controllers/forks.py
Show inline comments
 
@@ -123,10 +123,8 @@ class ForksController(BaseRepoController
 
            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')
 

	
kallithea/controllers/journal.py
Show inline comments
 
@@ -207,9 +207,8 @@ class JournalController(BaseController):
 
        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 @@ class JournalController(BaseController):
 

	
 
        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)
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -204,10 +204,8 @@ class PullrequestsController(BaseRepoCon
 

	
 
        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')
 

	
kallithea/templates/admin/admin.html
Show inline comments
 
@@ -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>
kallithea/templates/followers/followers.html
Show inline comments
 
@@ -22,7 +22,7 @@ ${self.repo_context_bar('followers')}
 
    <!-- end box / title -->
 
    <div class="table">
 
        <div id="followers">
 
            ${c.followers_data}
 
            <%include file='followers_data.html'/>
 
        </div>
 
    </div>
 
</div>
kallithea/templates/forks/forks.html
Show inline comments
 
@@ -23,7 +23,7 @@ ${self.repo_context_bar('showforks')}
 
    <!-- end box / title -->
 
    <div class="table">
 
        <div id="forks">
 
            ${c.forks_data}
 
            <%include file='forks_data.html'/>
 
        </div>
 
    </div>
 
</div>
kallithea/templates/journal/journal.html
Show inline comments
 
@@ -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 -->
kallithea/templates/journal/public_journal.html
Show inline comments
 
@@ -28,7 +28,9 @@
 
     </ul>
 
  </div>
 

	
 
  <div id="journal">${c.journal_data}</div>
 
  <div id="journal">
 
    <%include file='journal_data.html'/>
 
  </div>
 
</div>
 

	
 
</%def>
kallithea/templates/pullrequests/pullrequest_show_all.html
Show inline comments
 
@@ -51,7 +51,7 @@ ${self.repo_context_bar('showpullrequest
 
        </div>
 
    </div>
 

	
 
    ${c.pullrequest_data}
 
    <%include file='pullrequest_data.html'/>
 

	
 
</div>
 
</%def>
0 comments (0 inline, 0 general)