Skip to content

Commit

Permalink
Merge pull request #128 from openhealthcare/single-model-problems
Browse files Browse the repository at this point in the history
single step modal page pathways for multiple models weren't rendering
  • Loading branch information
davidmiller committed May 19, 2017
2 parents 6167242 + 98738bf commit f2b19e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 6 additions & 4 deletions pathway/templates/pathway/templates/modal_page_pathway.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ <h3>
</div>
{% endfor %}
{% else %}
<div pathway-step="{{ pathway.get_steps.0.get_api_name }}" class="row">
<div class="col-md-12">
{% include pathway.get_steps.0.get_template %}
{% with step=pathway.get_steps.0 %}
<div pathway-step="{{ step.get_api_name }}" class="row">
<div class="col-md-12">
{% include step.get_template %}
</div>
</div>
</div>
{% endwith %}
{% endif %}
{% endblock pathway_body %}
13 changes: 11 additions & 2 deletions pathway/templatetags/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
register = template.Library()


@register.inclusion_tag('_helpers/multisave.html', takes_context=True)
def multisave(context, subrecord):
def add_common_context(context, subrecord):
context = copy.copy(context)
ctx = {}
ctx["subrecord"] = subrecord
ctx["model"] = "editing.{}".format(subrecord.get_api_name())
context.update(ctx)
return context


@register.inclusion_tag('_helpers/multisave.html', takes_context=True)
def multisave(context, subrecord):
return add_common_context(context, subrecord)


@register.inclusion_tag('_helpers/collapsed_multisave.html', takes_context=True)
def collapsed_multisave(context, subrecord):
return add_common_context(context, subrecord)
18 changes: 17 additions & 1 deletion pathway/tests/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from opal.tests.models import Colour
from django.template import Template, Context
from mock import patch
from pathway.templatetags import pathways as template_tags


@patch.object(Colour, 'get_form_template')
class MultSaveTest(OpalTestCase):
Expand All @@ -23,8 +25,22 @@ def test_global_template_context_not_changed(self, get_form_template):
def test_nested_template_context(self, get_form_template):
template = Template('{% load pathways %}{% multisave models.Colour %}')
models = dict(models=dict(Colour=Colour), some_test_var="onions")
rendered = template.render(Context(models))
template.render(Context(models))
self.assertEqual(
get_form_template.render.call_args[0][0]["some_test_var"],
'onions'
)

def test_add_common_context(self, get_form_template):
ctx = template_tags.add_common_context({}, Colour)
self.assertEqual(ctx["subrecord"], Colour)
self.assertEqual(ctx["model"], "editing.colour")

def test_multisave(self, get_form_template):
ctx = template_tags.multisave({}, Colour)
self.assertEqual(ctx["subrecord"], Colour)
self.assertEqual(ctx["model"], "editing.colour")

def test_collapsed_multisave(self, get_form_template):
ctx = template_tags.collapsed_multisave({}, Colour)
self.assertEqual(ctx["subrecord"], Colour)

0 comments on commit f2b19e7

Please sign in to comment.