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): def render(self):
browser_template = template.loader.get_template(self.template) browser_template = template.loader.get_template(self.template)
extra_context = {self.context_var_name: self} extra_context = {self.context_var_name: self}
context = template.RequestContext(self.request, extra_context) return browser_template.render(extra_context, self.request)
return browser_template.render(context)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,6 @@
import copy import copy
import six import six
from six import moves
import django import django
from django.conf import settings from django.conf import settings
@ -1248,23 +1247,6 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
server.id) server.id)
self.assertEqual(res.status_code, 200) 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', @test.create_stubs({cinder: ('tenant_absolute_limits',
'volume_get',)}) 'volume_get',)})
def test_create_snapshot_button_attributes(self): def test_create_snapshot_button_attributes(self):
@ -1282,15 +1264,16 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
res = self.client.get(res_url, {}, res = self.client.get(res_url, {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest') HTTP_X_REQUESTED_WITH='XMLHttpRequest')
snapshot_action = self._get_volume_row_action_from_ajax( action_name = ('%(table)s__row_%(id)s__action_%(action)s' %
res, 'snapshots', volume.id) {'table': 'volumes', 'id': volume.id,
self.assertEqual('horizon:project:volumes:create_snapshot', 'action': 'snapshots'})
snapshot_action.url) content = res.content.decode('utf-8')
self.assertEqual(set(['ajax-modal']), set(snapshot_action.classes)) self.assertIn(action_name, content)
self.assertEqual('Create Snapshot', self.assertIn('Create Snapshot', content)
six.text_type(snapshot_action.verbose_name)) self.assertIn(reverse('horizon:project:volumes:create_snapshot',
self.assertEqual((('volume', 'volume:create_snapshot'),), args=[volume.id]),
snapshot_action.policy_rules) content)
self.assertNotIn('disabled', content)
@test.create_stubs({cinder: ('tenant_absolute_limits', @test.create_stubs({cinder: ('tenant_absolute_limits',
'volume_get',)}) 'volume_get',)})
@ -1309,9 +1292,16 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
res = self.client.get(res_url, {}, res = self.client.get(res_url, {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest') HTTP_X_REQUESTED_WITH='XMLHttpRequest')
snapshot_action = self._get_volume_row_action_from_ajax( action_name = ('%(table)s__row_%(id)s__action_%(action)s' %
res, 'snapshots', volume.id) {'table': 'volumes', 'id': volume.id,
self.assertIn('disabled', snapshot_action.classes, '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') 'The create snapshot button should be disabled')
@test.create_stubs({cinder: ('tenant_absolute_limits', @test.create_stubs({cinder: ('tenant_absolute_limits',