This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #843 from cfpb/flagged-update-message
Toggle reg update messages via settings
- Loading branch information
Showing
6 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django import template | ||
from django.conf import settings | ||
|
||
|
||
register = template.Library() | ||
|
||
|
||
@register.assignment_tag | ||
def update_in_progress(reg_part): | ||
"""Given a regulation, is there an update currently in progress? | ||
This template tag checks for a list in the Django setting | ||
EREGS_REGULATION_UPDATES, and, if that setting exists, checks if the given | ||
regulation part is in that list. | ||
Use it in a template like: | ||
{% update_in_progress reg_part as reg_update_in_progress %} | ||
{% if reg_update_in_progress %} | ||
<p>An update is in progress to this regulation.</p> | ||
{% endif %} | ||
""" | ||
regulation_updates = getattr(settings, 'EREGS_REGULATION_UPDATES', []) | ||
return reg_part in regulation_updates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.conf import settings | ||
from django.template import Context, Template | ||
from django.test import SimpleTestCase, override_settings | ||
|
||
|
||
class RegUpdatesTemplateTagsTestCase(SimpleTestCase): | ||
def render(self, reg_part): | ||
template = Template( | ||
"{% load reg_updates %}" | ||
"{% update_in_progress reg_part as reg_update %}" | ||
"{{ reg_update }}" | ||
) | ||
context = Context({'reg_part': reg_part}) | ||
return template.render(context) | ||
|
||
@override_settings() | ||
def test_no_setting_reg_not_being_updated_returns_false(self): | ||
del settings.EREGS_REGULATION_UPDATES | ||
self.assertEqual(self.render('1099'), 'False') | ||
|
||
@override_settings(EREGS_REGULATION_UPDATES=['1098', '1099']) | ||
def test_setting_includes_reg_returns_true(self): | ||
self.assertEqual(self.render('1099'), 'True') | ||
|
||
@override_settings(EREGS_REGULATION_UPDATES=['1001', '1002']) | ||
def test_setting_doesnt_include_reg_returns_false(self): | ||
self.assertEqual(self.render('1099'), 'False') |