Merge "Switch render() arguments to the new way"

This commit is contained in:
Jenkins 2017-07-03 08:31:24 +00:00 committed by Gerrit Code Review
commit 5f72d0433e
7 changed files with 30 additions and 49 deletions

View File

@ -144,5 +144,4 @@ class ResourceBrowser(html.HTMLElement):
def render(self):
browser_template = template.loader.get_template(self.template)
extra_context = {self.context_var_name: self}
context = template.RequestContext(self.request, extra_context)
return browser_template.render(context)
return browser_template.render(extra_context, self.request)

View File

@ -42,5 +42,4 @@ class Breadcrumb(html.HTMLElement):
"""Renders the table using the template from the table options."""
breadcrumb_template = template.loader.get_template(self.template)
extra_context = {"breadcrumb": self}
context = template.RequestContext(self.request, extra_context)
return breadcrumb_template.render(context)
return breadcrumb_template.render(extra_context, self.request)

View File

@ -26,7 +26,6 @@ from django.forms import fields
from django.forms import forms
from django.forms.utils import flatatt
from django.forms import widgets
from django.template import Context
from django.template.loader import get_template
from django.utils.encoding import force_text
from django.utils.functional import Promise
@ -291,14 +290,14 @@ class ThemableSelectWidget(SelectWidget):
id = attrs.pop('id', 'id_%s' % name)
template = get_template('horizon/common/fields/_themable_select.html')
context = Context({
context = {
'name': name,
'options': new_choices,
'id': id,
'value': value,
'initial_value': initial_value,
'select_attrs': attrs,
})
}
return template.render(context)

View File

@ -1394,8 +1394,7 @@ class DataTable(object):
table_template = template.loader.get_template(self._meta.template)
extra_context = {self._meta.context_var_name: self,
'hidden_title': self._meta.hidden_title}
context = template.RequestContext(self.request, extra_context)
return table_template.render(context)
return table_template.render(extra_context, self.request)
def get_absolute_url(self):
"""Returns the canonical URL for this table.
@ -1552,9 +1551,8 @@ class DataTable(object):
if self._meta.table_actions_menu_label:
extra_context['table_actions_menu_label'] = \
self._meta.table_actions_menu_label
context = template.RequestContext(self.request, extra_context)
self.set_multiselect_column_visibility(len(bound_actions) > 0)
return table_actions_template.render(context)
return table_actions_template.render(extra_context, self.request)
def render_row_actions(self, datum, row=False):
"""Renders the actions specified in ``Meta.row_actions``.
@ -1572,8 +1570,7 @@ class DataTable(object):
bound_actions = self.get_row_actions(datum)
extra_context = {"row_actions": bound_actions,
"row_id": self.get_object_id(datum)}
context = template.RequestContext(self.request, extra_context)
return row_actions_template.render(context)
return row_actions_template.render(extra_context, self.request)
@staticmethod
def parse_action(action_string):

View File

@ -84,8 +84,7 @@ class BaseCsvResponse(CsvDataMixin, HttpResponse):
if template:
# Display some header info if provided as a template
header_template = django_template.loader.get_template(template)
context = django_template.RequestContext(request, self.context)
self.header = header_template.render(context)
self.header = header_template.render(self.context, request)
if self.header:
self.out.write(self.encode(self.header))
@ -117,8 +116,7 @@ class BaseCsvStreamingResponse(CsvDataMixin, StreamingHttpResponse):
if template:
# Display some header info if provided as a template
header_template = django_template.loader.get_template(template)
context = django_template.RequestContext(request, self.context)
self.header = header_template.render(context)
self.header = header_template.render(self.context, request)
self._closable_objects.append(self.out)

View File

@ -181,8 +181,7 @@ class Action(forms.Form):
extra_context = extra_context or {}
if self.help_text_template:
tmpl = template.loader.get_template(self.help_text_template)
context = template.RequestContext(self.request, extra_context)
text += tmpl.render(context)
text += tmpl.render(extra_context, self.request)
else:
text += linebreaks(force_text(self.help_text))
return safe(text)

View File

@ -14,7 +14,6 @@
import copy
import six
from six import moves
import django
from django.conf import settings
@ -1248,23 +1247,6 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
server.id)
self.assertEqual(res.status_code, 200)
def _get_volume_row_action_from_ajax(self, res, action_name, row_id):
def _matches_row_id(context_row):
return (len(context_row.dicts) > 1 and
hasattr(context_row.dicts[1], 'get') and
context_row.dicts[1].get('row_id', None) == row_id)
matching = list(moves.filter(lambda r: _matches_row_id(r),
res.context))
self.assertGreater(len(matching), 1,
"Expected at least one row matching %s" % row_id)
row = matching[-1].dicts[1]
matching_actions = list(moves.filter(lambda a: a.name == action_name,
row['row_actions']))
self.assertEqual(1, len(matching_actions),
"Expected one row action named '%s'" % action_name)
return matching_actions[0]
@test.create_stubs({cinder: ('tenant_absolute_limits',
'volume_get',)})
def test_create_snapshot_button_attributes(self):
@ -1282,15 +1264,16 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
res = self.client.get(res_url, {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
snapshot_action = self._get_volume_row_action_from_ajax(
res, 'snapshots', volume.id)
self.assertEqual('horizon:project:volumes:create_snapshot',
snapshot_action.url)
self.assertEqual(set(['ajax-modal']), set(snapshot_action.classes))
self.assertEqual('Create Snapshot',
six.text_type(snapshot_action.verbose_name))
self.assertEqual((('volume', 'volume:create_snapshot'),),
snapshot_action.policy_rules)
action_name = ('%(table)s__row_%(id)s__action_%(action)s' %
{'table': 'volumes', 'id': volume.id,
'action': 'snapshots'})
content = res.content.decode('utf-8')
self.assertIn(action_name, content)
self.assertIn('Create Snapshot', content)
self.assertIn(reverse('horizon:project:volumes:create_snapshot',
args=[volume.id]),
content)
self.assertNotIn('disabled', content)
@test.create_stubs({cinder: ('tenant_absolute_limits',
'volume_get',)})
@ -1309,9 +1292,16 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
res = self.client.get(res_url, {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
snapshot_action = self._get_volume_row_action_from_ajax(
res, 'snapshots', volume.id)
self.assertIn('disabled', snapshot_action.classes,
action_name = ('%(table)s__row_%(id)s__action_%(action)s' %
{'table': 'volumes', 'id': volume.id,
'action': 'snapshots'})
content = res.content.decode('utf-8')
self.assertIn(action_name, content)
self.assertIn('Create Snapshot (Quota exceeded)', content)
self.assertIn(reverse('horizon:project:volumes:create_snapshot',
args=[volume.id]),
content)
self.assertIn('disabled', content,
'The create snapshot button should be disabled')
@test.create_stubs({cinder: ('tenant_absolute_limits',