mirror of
https://github.com/django-components/django-components.git
synced 2025-07-23 08:15:01 +00:00
Renamed get_context
to get_context_data
This commit is contained in:
parent
b322ab0294
commit
5fcabaa5ba
7 changed files with 22 additions and 22 deletions
|
@ -16,7 +16,7 @@ class SlottedComponent(component.Component):
|
||||||
class SimpleComponent(component.Component):
|
class SimpleComponent(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def get_context(self, variable, variable2="default"):
|
def get_context_data(self, variable, variable2="default"):
|
||||||
return {
|
return {
|
||||||
"variable": variable,
|
"variable": variable,
|
||||||
"variable2": variable2,
|
"variable2": variable2,
|
||||||
|
@ -41,7 +41,7 @@ class BreadcrumbComponent(component.Component):
|
||||||
'Document and website structure')
|
'Document and website structure')
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_context(self, items):
|
def get_context_data(self, items):
|
||||||
if items > 4:
|
if items > 4:
|
||||||
items = 4
|
items = 4
|
||||||
elif items < 0:
|
elif items < 0:
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
||||||
self.instance_template = None
|
self.instance_template = None
|
||||||
self.slots = {}
|
self.slots = {}
|
||||||
|
|
||||||
def get_context(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_template_name(self, context=None):
|
def get_template_name(self, context=None):
|
||||||
|
|
|
@ -149,7 +149,7 @@ class ComponentNode(Node):
|
||||||
# context method to get values to insert into the context
|
# context method to get values to insert into the context
|
||||||
resolved_context_args = [safe_resolve(arg, context) for arg in self.context_args]
|
resolved_context_args = [safe_resolve(arg, context) for arg in self.context_args]
|
||||||
resolved_context_kwargs = {key: safe_resolve(kwarg, context) for key, kwarg in self.context_kwargs.items()}
|
resolved_context_kwargs = {key: safe_resolve(kwarg, context) for key, kwarg in self.context_kwargs.items()}
|
||||||
component_context = self.component.get_context(*resolved_context_args, **resolved_context_kwargs)
|
component_context = self.component.get_context_data(*resolved_context_args, **resolved_context_kwargs)
|
||||||
|
|
||||||
# Create a fresh context if requested
|
# Create a fresh context if requested
|
||||||
if self.isolated_context:
|
if self.isolated_context:
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ComponentTest(SimpleTestCase):
|
||||||
class SimpleComponent(component.Component):
|
class SimpleComponent(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def get_context(self, variable=None):
|
def get_context_data(self, variable=None):
|
||||||
return {
|
return {
|
||||||
"variable": variable,
|
"variable": variable,
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class ComponentTest(SimpleTestCase):
|
||||||
js = "script.js"
|
js = "script.js"
|
||||||
|
|
||||||
comp = SimpleComponent("simple_component")
|
comp = SimpleComponent("simple_component")
|
||||||
context = Context(comp.get_context(variable="test"))
|
context = Context(comp.get_context_data(variable="test"))
|
||||||
|
|
||||||
self.assertHTMLEqual(comp.render_dependencies(), dedent("""
|
self.assertHTMLEqual(comp.render_dependencies(), dedent("""
|
||||||
<link href="style.css" type="text/css" media="all" rel="stylesheet">
|
<link href="style.css" type="text/css" media="all" rel="stylesheet">
|
||||||
|
@ -61,14 +61,14 @@ class ComponentTest(SimpleTestCase):
|
||||||
class FilteredComponent(component.Component):
|
class FilteredComponent(component.Component):
|
||||||
template_name = "filtered_template.html"
|
template_name = "filtered_template.html"
|
||||||
|
|
||||||
def get_context(self, var1=None, var2=None):
|
def get_context_data(self, var1=None, var2=None):
|
||||||
return {
|
return {
|
||||||
"var1": var1,
|
"var1": var1,
|
||||||
"var2": var2,
|
"var2": var2,
|
||||||
}
|
}
|
||||||
|
|
||||||
comp = FilteredComponent("filtered_component")
|
comp = FilteredComponent("filtered_component")
|
||||||
context = Context(comp.get_context(var1="test1", var2="test2"))
|
context = Context(comp.get_context_data(var1="test1", var2="test2"))
|
||||||
|
|
||||||
self.assertHTMLEqual(comp.render(context), dedent("""
|
self.assertHTMLEqual(comp.render(context), dedent("""
|
||||||
Var1: <strong>test1</strong>
|
Var1: <strong>test1</strong>
|
||||||
|
@ -77,7 +77,7 @@ class ComponentTest(SimpleTestCase):
|
||||||
|
|
||||||
def test_component_with_dynamic_template(self):
|
def test_component_with_dynamic_template(self):
|
||||||
class SvgComponent(component.Component):
|
class SvgComponent(component.Component):
|
||||||
def get_context(self, name, css_class="", title="", **attrs):
|
def get_context_data(self, name, css_class="", title="", **attrs):
|
||||||
return {"name": name, "css_class": css_class, "title": title, **attrs}
|
return {"name": name, "css_class": css_class, "title": title, **attrs}
|
||||||
|
|
||||||
def get_template_name(self, context):
|
def get_template_name(self, context):
|
||||||
|
@ -85,13 +85,13 @@ class ComponentTest(SimpleTestCase):
|
||||||
|
|
||||||
comp = SvgComponent("svg_component")
|
comp = SvgComponent("svg_component")
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
comp.render(Context(comp.get_context(name="dynamic1"))),
|
comp.render(Context(comp.get_context_data(name="dynamic1"))),
|
||||||
dedent("""\
|
dedent("""\
|
||||||
<svg>Dynamic1</svg>
|
<svg>Dynamic1</svg>
|
||||||
""")
|
""")
|
||||||
)
|
)
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
comp.render(Context(comp.get_context(name="dynamic2"))),
|
comp.render(Context(comp.get_context_data(name="dynamic2"))),
|
||||||
dedent("""\
|
dedent("""\
|
||||||
<svg>Dynamic2</svg>
|
<svg>Dynamic2</svg>
|
||||||
""")
|
""")
|
||||||
|
|
|
@ -10,7 +10,7 @@ from .testutils import Django30CompatibleSimpleTestCase as SimpleTestCase
|
||||||
class SimpleComponent(component.Component):
|
class SimpleComponent(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def get_context(self, variable=None):
|
def get_context_data(self, variable=None):
|
||||||
return {"variable": variable} if variable is not None else {}
|
return {"variable": variable} if variable is not None else {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -21,7 +21,7 @@ class SimpleComponent(component.Component):
|
||||||
class ParentComponent(component.Component):
|
class ParentComponent(component.Component):
|
||||||
template_name = "parent_template.html"
|
template_name = "parent_template.html"
|
||||||
|
|
||||||
def get_context(self):
|
def get_context_data(self):
|
||||||
return {
|
return {
|
||||||
"shadowing_variable": 'NOT SHADOWED'
|
"shadowing_variable": 'NOT SHADOWED'
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ class ParentComponent(component.Component):
|
||||||
class ParentComponentWithArgs(component.Component):
|
class ParentComponentWithArgs(component.Component):
|
||||||
template_name = "parent_with_args_template.html"
|
template_name = "parent_with_args_template.html"
|
||||||
|
|
||||||
def get_context(self, parent_value):
|
def get_context_data(self, parent_value):
|
||||||
return {"inner_parent_value": parent_value}
|
return {"inner_parent_value": parent_value}
|
||||||
|
|
||||||
|
|
||||||
class VariableDisplay(component.Component):
|
class VariableDisplay(component.Component):
|
||||||
template_name = "variable_display.html"
|
template_name = "variable_display.html"
|
||||||
|
|
||||||
def get_context(self, shadowing_variable=None, new_variable=None):
|
def get_context_data(self, shadowing_variable=None, new_variable=None):
|
||||||
context = {}
|
context = {}
|
||||||
if shadowing_variable is not None:
|
if shadowing_variable is not None:
|
||||||
context['shadowing_variable'] = shadowing_variable
|
context['shadowing_variable'] = shadowing_variable
|
||||||
|
@ -49,7 +49,7 @@ class VariableDisplay(component.Component):
|
||||||
class IncrementerComponent(component.Component):
|
class IncrementerComponent(component.Component):
|
||||||
template_name = "incrementer.html"
|
template_name = "incrementer.html"
|
||||||
|
|
||||||
def get_context(self, value=0):
|
def get_context_data(self, value=0):
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if hasattr(self, 'call_count'):
|
if hasattr(self, 'call_count'):
|
||||||
self.call_count += 1
|
self.call_count += 1
|
||||||
|
@ -65,7 +65,7 @@ class IncrementerComponent(component.Component):
|
||||||
class OuterContextComponent(component.Component):
|
class OuterContextComponent(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def get_context(self):
|
def get_context_data(self):
|
||||||
return self.outer_context
|
return self.outer_context
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SimpleComponentAlternate(component.Component):
|
||||||
class SimpleComponentWithSharedDependency(component.Component):
|
class SimpleComponentWithSharedDependency(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def context(self, variable, variable2="default"):
|
def get_context_data(self, variable, variable2="default"):
|
||||||
return {
|
return {
|
||||||
"variable": variable,
|
"variable": variable,
|
||||||
"variable2": variable2,
|
"variable2": variable2,
|
||||||
|
|
|
@ -10,7 +10,7 @@ from .testutils import Django30CompatibleSimpleTestCase as SimpleTestCase
|
||||||
class SimpleComponent(component.Component):
|
class SimpleComponent(component.Component):
|
||||||
template_name = "simple_template.html"
|
template_name = "simple_template.html"
|
||||||
|
|
||||||
def get_context(self, variable, variable2="default"):
|
def get_context_data(self, variable, variable2="default"):
|
||||||
return {
|
return {
|
||||||
"variable": variable,
|
"variable": variable,
|
||||||
"variable2": variable2,
|
"variable2": variable2,
|
||||||
|
@ -44,14 +44,14 @@ class SlottedComponentNoSlots(component.Component):
|
||||||
class SlottedComponentWithContext(component.Component):
|
class SlottedComponentWithContext(component.Component):
|
||||||
template_name = "slotted_template.html"
|
template_name = "slotted_template.html"
|
||||||
|
|
||||||
def get_context(self, variable):
|
def get_context_data(self, variable):
|
||||||
return {"variable": variable}
|
return {"variable": variable}
|
||||||
|
|
||||||
|
|
||||||
class ComponentWithProvidedAndDefaultParameters(component.Component):
|
class ComponentWithProvidedAndDefaultParameters(component.Component):
|
||||||
template_name = "template_with_provided_and_default_parameters.html"
|
template_name = "template_with_provided_and_default_parameters.html"
|
||||||
|
|
||||||
def get_context(self, variable, default_param="default text"):
|
def get_context_data(self, variable, default_param="default text"):
|
||||||
return {"variable": variable, 'default_param': default_param}
|
return {"variable": variable, 'default_param': default_param}
|
||||||
|
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ class ConditionalSlotTests(SimpleTestCase):
|
||||||
class ConditionalComponent(component.Component):
|
class ConditionalComponent(component.Component):
|
||||||
template_name = "conditional_template.html"
|
template_name = "conditional_template.html"
|
||||||
|
|
||||||
def get_context(self, branch=None):
|
def get_context_data(self, branch=None):
|
||||||
return {'branch': branch}
|
return {'branch': branch}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue