# HG changeset patch # User Thomas De Schampheleire # Date 2015-02-21 21:04:54 # Node ID a40824531f684ed7d4e7ec74b9332c1f49ea1b97 # Parent 5e94c0f9720c908d8be2d4b717cf3e63db2bbc96 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 @@ 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') 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 @@ 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') 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 @@ 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') 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 @@ 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) 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 @@ 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') 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 @@ -27,7 +27,7 @@
- ${c.log_data} + <%include file='admin_log.html'/>
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 @@ -22,7 +22,7 @@
- ${c.followers_data} + <%include file='followers_data.html'/>
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 @@ -23,7 +23,7 @@
- ${c.forks_data} + <%include file='forks_data.html'/>
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 @@ -36,7 +36,9 @@ -
${c.journal_data}
+
+ <%include file='journal_data.html'/> +
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 @@ -28,7 +28,9 @@
-
${c.journal_data}
+
+ <%include file='journal_data.html'/> +
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 @@ -51,7 +51,7 @@ - ${c.pullrequest_data} + <%include file='pullrequest_data.html'/>