Skip to content

Commit

Permalink
Merge 01295ab into b6880ef
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Mar 29, 2019
2 parents b6880ef + 01295ab commit 43f0099
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,8 @@

A User's UserProfile is now automatically created when you create a user in a post save signal.

The date of birth template tag now allows you have pass in a label to be displayed next to the form.

### 0.13.1 (Minor Release)

Upgrades the setup.py Django version from 2.0.9 to 2.0.13. Removes the six library dependency from setup.py.
Expand Down
4 changes: 2 additions & 2 deletions opal/templates/_helpers/date_of_birth_field.html
@@ -1,11 +1,11 @@
<div ng-show="editing.demographics.external_system" class="form-group">
<label class="control-label {% ifequal style "horizontal" %}col-sm-3{% endifequal %}">Date Of Birth</label>
<label class="control-label {% ifequal style "horizontal" %}col-sm-3{% endifequal %}">{{ label }}</label>
<p class="form-control-static col-sm-8">
[[ {{ model_name }} | displayDate ]]
</p>
</div>
<div ng-class="{'has-error': form.date_of_birth.$invalid}" ng-hide="editing.demographics.external_system" class="form-group">
<label class="control-label {% ifequal style "horizontal" %}col-sm-3{% endifequal %}">Date Of Birth</label>
<label class="control-label {% ifequal style "horizontal" %}col-sm-3{% endifequal %}">{{ label }}</label>
<div class="{% ifequal style "horizontal" %}col-sm-8{% endifequal %}">
<div date-of-birth ng-model="{{ model_name }}"></div>
<span class="help-block" ng-show="form.date_of_birth.$invalid">
Expand Down
8 changes: 7 additions & 1 deletion opal/templatetags/forms.py
Expand Up @@ -324,9 +324,15 @@ def icon(name):
@register.inclusion_tag('_helpers/date_of_birth_field.html')
def date_of_birth_field(**kwargs):
model_name = kwargs.get('model_name', "editing.demographics.date_of_birth")
label = kwargs.get("label")

if not label:
Demographics = get_subrecord_from_model_name("Demographics")
label = Demographics._get_field_title("date_of_birth")
return dict(
model_name=model_name,
style=get_style(kwargs)
style=get_style(kwargs),
label=label
)


Expand Down
16 changes: 14 additions & 2 deletions opal/tests/test_templatetags_forms.py
Expand Up @@ -575,19 +575,31 @@ def test_set_field(self):
ctx = date_of_birth_field(model_name="something")
expected = dict(
style="horizontal",
model_name="something"
model_name="something",
label="Date of Birth"
)
self.assertEqual(expected, ctx)

def test_default(self):
ctx = date_of_birth_field()
expected = dict(
model_name="editing.demographics.date_of_birth",
style='horizontal'
style='horizontal',
label="Date of Birth"
)
self.assertEqual(expected, ctx)

def test_render(self):
tpl = Template('{% load forms %}{% date_of_birth_field %}')
rendered = tpl.render(Context({}))
self.assertIn("editing.demographics.date_of_birth", rendered)

def test_label_not_defined(self):
tpl = Template('{% load forms %}{% date_of_birth_field %}')
rendered = tpl.render(Context({}))
self.assertIn("Date of Birth", rendered)

def test_label_defined(self):
tpl = Template('{% load forms %}{% date_of_birth_field label="altered birth date label" %}')
rendered = tpl.render(Context({}))
self.assertIn("altered birth date label", rendered)

0 comments on commit 43f0099

Please sign in to comment.