# HG changeset patch # User Thomas De Schampheleire <thomas.de_schamphele...@alcatel-lucent.com> # Date 1424552694 -3600 # Sat Feb 21 22:04:54 2015 +0100 # Node ID fe50f1415d66f5be1cc05cca0b103d3a502fe6af # Parent 1619d9ebc1b9b40379c192ddb45e5802ecfb8f2b 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 diff --git a/kallithea/controllers/admin/admin.py b/kallithea/controllers/admin/admin.py --- a/kallithea/controllers/admin/admin.py +++ b/kallithea/controllers/admin/admin.py @@ -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') diff --git a/kallithea/controllers/followers.py b/kallithea/controllers/followers.py --- a/kallithea/controllers/followers.py +++ b/kallithea/controllers/followers.py @@ -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') diff --git a/kallithea/controllers/forks.py b/kallithea/controllers/forks.py --- a/kallithea/controllers/forks.py +++ b/kallithea/controllers/forks.py @@ -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') diff --git a/kallithea/controllers/journal.py b/kallithea/controllers/journal.py --- a/kallithea/controllers/journal.py +++ b/kallithea/controllers/journal.py @@ -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) diff --git a/kallithea/controllers/pullrequests.py b/kallithea/controllers/pullrequests.py --- a/kallithea/controllers/pullrequests.py +++ b/kallithea/controllers/pullrequests.py @@ -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') diff --git a/kallithea/templates/admin/admin.html b/kallithea/templates/admin/admin.html --- a/kallithea/templates/admin/admin.html +++ b/kallithea/templates/admin/admin.html @@ -30,7 +30,7 @@ <!-- end box / title --> <div class="table"> <div id="user_log"> - ${c.log_data} + <%include file='admin_log.html'/> </div> </div> </div> diff --git a/kallithea/templates/followers/followers.html b/kallithea/templates/followers/followers.html --- a/kallithea/templates/followers/followers.html +++ b/kallithea/templates/followers/followers.html @@ -25,7 +25,7 @@ <!-- end box / title --> <div class="table"> <div id="followers"> - ${c.followers_data} + <%include file='followers_data.html'/> </div> </div> </div> diff --git a/kallithea/templates/forks/forks.html b/kallithea/templates/forks/forks.html --- a/kallithea/templates/forks/forks.html +++ b/kallithea/templates/forks/forks.html @@ -26,7 +26,7 @@ <!-- end box / title --> <div class="table"> <div id="forks"> - ${c.forks_data} + <%include file='forks_data.html'/> </div> </div> </div> diff --git a/kallithea/templates/journal/journal.html b/kallithea/templates/journal/journal.html --- a/kallithea/templates/journal/journal.html +++ b/kallithea/templates/journal/journal.html @@ -39,7 +39,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 --> diff --git a/kallithea/templates/journal/public_journal.html b/kallithea/templates/journal/public_journal.html --- a/kallithea/templates/journal/public_journal.html +++ b/kallithea/templates/journal/public_journal.html @@ -31,7 +31,9 @@ </ul> </div> - <div id="journal">${c.journal_data}</div> + <div id="journal"> + <%include file='journal_data.html'/> + </div> </div> </%def> diff --git a/kallithea/templates/pullrequests/pullrequest_show_all.html b/kallithea/templates/pullrequests/pullrequest_show_all.html --- a/kallithea/templates/pullrequests/pullrequest_show_all.html +++ b/kallithea/templates/pullrequests/pullrequest_show_all.html @@ -54,7 +54,7 @@ </div> </div> - ${c.pullrequest_data} + <%include file='pullrequest_data.html'/> </div> </%def> _______________________________________________ kallithea-general mailing list kallithea-general@sfconservancy.org http://lists.sfconservancy.org/mailman/listinfo/kallithea-general