diff --git a/cfgov/regulations3k/fixtures/parts.json b/cfgov/regulations3k/fixtures/parts.json
index 092080af79f..6c9922f34cb 100644
--- a/cfgov/regulations3k/fixtures/parts.json
+++ b/cfgov/regulations3k/fixtures/parts.json
@@ -4,7 +4,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1002",
- "letter_code": "B",
+ "short_name": "Regulation B",
"title": "Equal Credit Opportunity Act"
},
"model": "regulations3k.part",
@@ -15,7 +15,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1003",
- "letter_code": "C",
+ "short_name": "Regulation C",
"title": "Home Mortgage Disclosure"
},
"model": "regulations3k.part",
@@ -26,7 +26,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1004",
- "letter_code": "D",
+ "short_name": "Regulation D",
"title": "Alternative Mortgage Transaction Parity"
},
"model": "regulations3k.part",
@@ -37,7 +37,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1005",
- "letter_code": "E",
+ "short_name": "Regulation E",
"title": "Electronic Fund Transfers"
},
"model": "regulations3k.part",
@@ -48,7 +48,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1010",
- "letter_code": "J",
+ "short_name": "Regulation J",
"title": "Land Registration"
},
"model": "regulations3k.part",
@@ -59,7 +59,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1011",
- "letter_code": "K",
+ "short_name": "Regulation K",
"title": "Purchasers' Revocation Rights, Sales Practices And Standards"
},
"model": "regulations3k.part",
@@ -70,7 +70,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1012",
- "letter_code": "L",
+ "short_name": "Regulation L",
"title": "Special Rules Of Practice"
},
"model": "regulations3k.part",
@@ -81,7 +81,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1013",
- "letter_code": "M",
+ "short_name": "Regulation M",
"title": "Consumer Leasing"
},
"model": "regulations3k.part",
@@ -92,7 +92,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1024",
- "letter_code": "X",
+ "short_name": "Regulation X",
"title": "Real Estate Settlement Procedures Act"
},
"model": "regulations3k.part",
@@ -103,7 +103,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1026",
- "letter_code": "Z",
+ "short_name": "Regulation Z",
"title": "Truth In Lending"
},
"model": "regulations3k.part",
@@ -114,7 +114,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1030",
- "letter_code": "DD",
+ "short_name": "Regulation DD",
"title": "Truth In Savings"
},
"model": "regulations3k.part",
diff --git a/cfgov/regulations3k/fixtures/regdata.json b/cfgov/regulations3k/fixtures/regdata.json
index bc49fc187bf..6d790af3688 100644
--- a/cfgov/regulations3k/fixtures/regdata.json
+++ b/cfgov/regulations3k/fixtures/regdata.json
@@ -4,7 +4,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1002",
- "letter_code": "B",
+ "short_name": "Regulation B",
"title": "Equal Credit Opportunity Act"
},
"model": "regulations3k.part",
@@ -15,7 +15,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1003",
- "letter_code": "C",
+ "short_name": "Regulation C",
"title": "Home Mortgage Disclosure"
},
"model": "regulations3k.part",
@@ -26,7 +26,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1004",
- "letter_code": "D",
+ "short_name": "Regulation D",
"title": "Alternative Mortgage Transaction Parity"
},
"model": "regulations3k.part",
@@ -37,7 +37,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1005",
- "letter_code": "E",
+ "short_name": "Regulation E",
"title": "Electronic Fund Transfers"
},
"model": "regulations3k.part",
@@ -48,7 +48,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1010",
- "letter_code": "J",
+ "short_name": "Regulation J",
"title": "Land Registration"
},
"model": "regulations3k.part",
@@ -59,7 +59,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1011",
- "letter_code": "K",
+ "short_name": "Regulation K",
"title": "Purchasers' Revocation Rights, Sales Practices And Standards"
},
"model": "regulations3k.part",
@@ -70,7 +70,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1012",
- "letter_code": "L",
+ "short_name": "Regulation L",
"title": "Special Rules Of Practice"
},
"model": "regulations3k.part",
@@ -81,7 +81,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1013",
- "letter_code": "M",
+ "short_name": "Regulation M",
"title": "Consumer Leasing"
},
"model": "regulations3k.part",
@@ -92,7 +92,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1024",
- "letter_code": "X",
+ "short_name": "Regulation X",
"title": "Real Estate Settlement Procedures Act"
},
"model": "regulations3k.part",
@@ -103,7 +103,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1026",
- "letter_code": "Z",
+ "short_name": "Regulation Z",
"title": "Truth In Lending"
},
"model": "regulations3k.part",
@@ -114,7 +114,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1030",
- "letter_code": "DD",
+ "short_name": "Regulation DD",
"title": "Truth In Savings"
},
"model": "regulations3k.part",
diff --git a/cfgov/regulations3k/fixtures/test_parts.json b/cfgov/regulations3k/fixtures/test_parts.json
index 5b4aff395cb..a34d9673bc4 100644
--- a/cfgov/regulations3k/fixtures/test_parts.json
+++ b/cfgov/regulations3k/fixtures/test_parts.json
@@ -1 +1 @@
-[{"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1004", "letter_code": "D", "title": "Alternative Mortgage Transaction Parity"}, "model": "regulations3k.part", "pk": 3}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1005", "letter_code": "E", "title": "Electronic Fund Transfers"}, "model": "regulations3k.part", "pk": 4}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1010", "letter_code": "J", "title": "Land Registration"}, "model": "regulations3k.part", "pk": 5}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1011", "letter_code": "K", "title": "Purchasers' Revocation Rights, Sales Practices And Standards"}, "model": "regulations3k.part", "pk": 6}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1012", "letter_code": "L", "title": "Special Rules Of Practice"}, "model": "regulations3k.part", "pk": 7}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1013", "letter_code": "M", "title": "Consumer Leasing"}, "model": "regulations3k.part", "pk": 8}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1024", "letter_code": "X", "title": "Real Estate Settlement Procedures Act"}, "model": "regulations3k.part", "pk": 9}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1030", "letter_code": "DD", "title": "Truth In Savings"}, "model": "regulations3k.part", "pk": 11}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1003", "letter_code": "C", "title": "Home Mortgage Disclosure"}, "model": "regulations3k.part", "pk": 1003}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1026", "letter_code": "Z", "title": "Truth In Lending"}, "model": "regulations3k.part", "pk": 1026}]
+[{"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1004", "short_name": "Regulation D", "title": "Alternative Mortgage Transaction Parity"}, "model": "regulations3k.part", "pk": 3}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1005", "short_name": "Regulation E", "title": "Electronic Fund Transfers"}, "model": "regulations3k.part", "pk": 4}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1010", "short_name": "Regulation J", "title": "Land Registration"}, "model": "regulations3k.part", "pk": 5}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1011", "short_name": "Regulation K", "title": "Purchasers' Revocation Rights, Sales Practices And Standards"}, "model": "regulations3k.part", "pk": 6}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1012", "short_name": "Regulation L", "title": "Special Rules Of Practice"}, "model": "regulations3k.part", "pk": 7}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1013", "short_name": "Regulation M", "title": "Consumer Leasing"}, "model": "regulations3k.part", "pk": 8}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1024", "short_name": "Regulation X", "title": "Real Estate Settlement Procedures Act"}, "model": "regulations3k.part", "pk": 9}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1030", "short_name": "Regulation DD", "title": "Truth In Savings"}, "model": "regulations3k.part", "pk": 11}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1003", "short_name": "Regulation C", "title": "Home Mortgage Disclosure"}, "model": "regulations3k.part", "pk": 1003}, {"fields": {"cfr_title_number": "12", "chapter": "X", "part_number": "1026", "short_name": "Regulation Z", "title": "Truth In Lending"}, "model": "regulations3k.part", "pk": 1026}]
diff --git a/cfgov/regulations3k/fixtures/tree_limb.json b/cfgov/regulations3k/fixtures/tree_limb.json
index 303de24259e..72d0b212920 100644
--- a/cfgov/regulations3k/fixtures/tree_limb.json
+++ b/cfgov/regulations3k/fixtures/tree_limb.json
@@ -4,7 +4,7 @@
"cfr_title_number": "12",
"chapter": "X",
"part_number": "1002",
- "letter_code": "B",
+ "short_name": "Regulation B",
"title": "Equal Credit Opportunity Act"
},
"model": "regulations3k.part",
diff --git a/cfgov/regulations3k/jinja2/regulations3k/browse-regulation.html b/cfgov/regulations3k/jinja2/regulations3k/browse-regulation.html
index b29c49c6bc8..649b14d813d 100644
--- a/cfgov/regulations3k/jinja2/regulations3k/browse-regulation.html
+++ b/cfgov/regulations3k/jinja2/regulations3k/browse-regulation.html
@@ -92,7 +92,7 @@
{{section.title}}
diff --git a/cfgov/regulations3k/jinja2/regulations3k/search-regulations-results.html b/cfgov/regulations3k/jinja2/regulations3k/search-regulations-results.html
index 2ecbb3666d0..39a4fb64e02 100644
--- a/cfgov/regulations3k/jinja2/regulations3k/search-regulations-results.html
+++ b/cfgov/regulations3k/jinja2/regulations3k/search-regulations-results.html
@@ -28,6 +28,7 @@
No results match your filters.
{% for reg in page.results.all_regs %}
{% if reg.selected %}
{%- set reg_name = '(Reg
ulation ' ~ reg.letter_code ~ ')' -%}
+ {%- set reg_name = '(' ~ reg.short_name | regs_hide_on_mobile ~ ')' -%}
{{ tag.render({
'label': reg.id ~ ' ' ~ reg_name | safe,
'value': reg.id,
diff --git a/cfgov/regulations3k/jinja2/regulations3k/search-regulations.html b/cfgov/regulations3k/jinja2/regulations3k/search-regulations.html
index 9f69b18c7c2..5cb22b11f0a 100644
--- a/cfgov/regulations3k/jinja2/regulations3k/search-regulations.html
+++ b/cfgov/regulations3k/jinja2/regulations3k/search-regulations.html
@@ -104,6 +104,7 @@
Refine results
{% for reg in page.results.all_regs %}
{%- set reg_name = '(Regulation ' ~ reg.letter_code ~ ')' -%}
+ {%- set reg_name = '(' ~ reg.short_name ~ ')' -%}
-
{{ checkbox.render({
'label': reg.id ~ ' ' ~ reg_name | safe,
diff --git a/cfgov/regulations3k/jinja2tags.py b/cfgov/regulations3k/jinja2tags.py
index 1b7d066e168..95d2644e211 100644
--- a/cfgov/regulations3k/jinja2tags.py
+++ b/cfgov/regulations3k/jinja2tags.py
@@ -32,6 +32,15 @@ def regdown_filter(text):
return do_mark_safe(regdown_func(text))
+def regs_hide_on_mobile(text):
+ """ Mark specific patterns in text as hidden on mobile """
+ text = do_mark_safe(text.replace(
+ 'Regulation',
+ 'Regulation'
+ ))
+ return text
+
+
class RegulationsExtension(Extension):
def __init__(self, environment):
@@ -43,6 +52,7 @@ def __init__(self, environment):
})
self.environment.filters.update({
'regdown': regdown_filter,
+ 'regs_hide_on_mobile': regs_hide_on_mobile,
})
diff --git a/cfgov/regulations3k/migrations/0025_part_short_name.py b/cfgov/regulations3k/migrations/0025_part_short_name.py
new file mode 100644
index 00000000000..65811b1103d
--- /dev/null
+++ b/cfgov/regulations3k/migrations/0025_part_short_name.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-06-27 15:05
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('regulations3k', '0024_add_standard_notification_regs_landing'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='part',
+ name='short_name',
+ field=models.CharField(blank=True, max_length=255),
+ ),
+ ]
diff --git a/cfgov/regulations3k/migrations/0026_migrate_letter_code_to_short_name.py b/cfgov/regulations3k/migrations/0026_migrate_letter_code_to_short_name.py
new file mode 100644
index 00000000000..55ccb339665
--- /dev/null
+++ b/cfgov/regulations3k/migrations/0026_migrate_letter_code_to_short_name.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-06-27 15:06
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+def forwards(apps, schema_editor):
+ Part = apps.get_model('regulations3k', 'Part')
+ for part in Part.objects.all():
+ part.short_name = 'Regulation ' + part.letter_code
+ part.save()
+
+
+def backwards(apps, schema_editor):
+ Part = apps.get_model('regulations3k', 'Part')
+ for part in Part.objects.all():
+ if part.startswith('Regulation '):
+ part.letter_code = part.short_name[11:]
+ else:
+ part.letter_code = ''
+ part.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('regulations3k', '0025_part_short_name'),
+ ]
+
+ operations = [
+ migrations.RunPython(forwards, backwards),
+ ]
diff --git a/cfgov/regulations3k/models/django.py b/cfgov/regulations3k/models/django.py
index ac8a867cf87..7de108ff8cc 100644
--- a/cfgov/regulations3k/models/django.py
+++ b/cfgov/regulations3k/models/django.py
@@ -49,24 +49,24 @@ class Part(models.Model):
part_number = models.CharField(max_length=255)
title = models.CharField(max_length=255)
letter_code = models.CharField(max_length=10)
+ short_name = models.CharField(max_length=255, blank=True)
panels = [
FieldPanel('cfr_title_number'),
FieldPanel('title'),
FieldPanel('part_number'),
- FieldPanel('letter_code'),
+ FieldPanel('short_name'),
FieldPanel('chapter'),
]
@property
def cfr_title(self):
- return "{} CFR Part {} (Regulation {})".format(
- self.cfr_title_number, self.part_number, self.letter_code)
+ return str(self)
def __str__(self):
- name = "12 CFR Part {}".format(self.part_number)
- if self.letter_code:
- name += " (Regulation {})".format(self.letter_code)
+ name = "{} CFR Part {}".format(self.cfr_title_number, self.part_number)
+ if self.short_name:
+ name += " ({})".format(self.short_name)
return name
class Meta:
diff --git a/cfgov/regulations3k/models/pages.py b/cfgov/regulations3k/models/pages.py
index de2f13d1f48..2af8fc8ca8e 100644
--- a/cfgov/regulations3k/models/pages.py
+++ b/cfgov/regulations3k/models/pages.py
@@ -30,7 +30,6 @@
from ask_cfpb.models.pages import SecondaryNavigationJSMixin
from regulations3k.blocks import RegulationsListingFullWidthText
from regulations3k.models import Part, Section, SectionParagraph
-from regulations3k.parser.integer_conversion import LETTER_CODES
from regulations3k.resolver import get_contents_resolver, get_url_resolver
from v1.atomic_elements import molecules, organisms
from v1.models import CFGOVPage, CFGOVPageManager
@@ -81,7 +80,7 @@ def regulation_results_page(self, request):
sqs = SearchQuerySet().filter(content=search_query)
payload.update({
'all_regs': [{
- 'letter_code': reg.letter_code,
+ 'short_name': reg.short_name,
'id': reg.part_number,
'num_results': sqs.filter(
part=reg.part_number).models(SectionParagraph).count(),
@@ -107,11 +106,12 @@ def regulation_results_page(self, request):
"Query string {} produced a TypeError: {}".format(
search_query, e))
continue
- letter_code = LETTER_CODES.get(hit.part)
+
+ short_name = all_regs.get(part_number=hit.part).short_name
hit_payload = {
'id': hit.paragraph_id,
'part': hit.part,
- 'reg': 'Regulation {}'.format(letter_code),
+ 'reg': short_name,
'label': hit.title,
'snippet': snippet,
'url': "{}{}/{}/#{}".format(
@@ -119,6 +119,7 @@ def regulation_results_page(self, request):
hit.section_label, hit.paragraph_id),
}
payload['results'].append(hit_payload)
+
payload.update({'current_count': sqs.count()})
self.results = payload
context = self.get_context(request)
diff --git a/cfgov/regulations3k/tests/test_blocks.py b/cfgov/regulations3k/tests/test_blocks.py
index ef169cb483f..207c4547473 100644
--- a/cfgov/regulations3k/tests/test_blocks.py
+++ b/cfgov/regulations3k/tests/test_blocks.py
@@ -32,14 +32,14 @@ def setUp(self):
Part,
part_number='1002',
title='Equal Credit Opportunity Act',
- letter_code='B',
+ short_name='Regulation B',
chapter='X'
)
self.part_1003 = mommy.make(
Part,
part_number='1003',
title='Home Mortgage Disclosure',
- letter_code='C',
+ short_name='Regulation C',
chapter='X'
)
self.effective_version = mommy.make(
diff --git a/cfgov/regulations3k/tests/test_copyable_modeladmin.py b/cfgov/regulations3k/tests/test_copyable_modeladmin.py
index df7188181a1..4918173ed2a 100644
--- a/cfgov/regulations3k/tests/test_copyable_modeladmin.py
+++ b/cfgov/regulations3k/tests/test_copyable_modeladmin.py
@@ -20,7 +20,7 @@ def setUp(self):
Part,
part_number='1002',
title='Equal Credit Opportunity Act',
- letter_code='B',
+ short_name='Regulation B',
chapter='X'
)
self.effective_version = mommy.make(
diff --git a/cfgov/regulations3k/tests/test_hooks.py b/cfgov/regulations3k/tests/test_hooks.py
index b31e9a119a8..06f3547a922 100644
--- a/cfgov/regulations3k/tests/test_hooks.py
+++ b/cfgov/regulations3k/tests/test_hooks.py
@@ -27,7 +27,7 @@ def setUp(self):
Part,
part_number='1002',
title='Equal Credit Opportunity Act',
- letter_code='B',
+ short_name='Regulation B',
chapter='X'
)
self.effective_version = mommy.make(
diff --git a/cfgov/regulations3k/tests/test_jinja2tags.py b/cfgov/regulations3k/tests/test_jinja2tags.py
index 8b29b9ef09c..74ee4359434 100644
--- a/cfgov/regulations3k/tests/test_jinja2tags.py
+++ b/cfgov/regulations3k/tests/test_jinja2tags.py
@@ -3,7 +3,7 @@
from django.template import engines
from django.test import TestCase
-from regulations3k.jinja2tags import ap_date
+from regulations3k.jinja2tags import ap_date, regs_hide_on_mobile
class RegulationsExtensionTestCase(TestCase):
@@ -47,3 +47,10 @@ def test_regdown_filter_available(self):
'id="be34deef8eb9a480514ed3b4a5ebdaea61c711d2b11d40e830cb0656">'
'Hello'
)
+
+ def test_regs_hide_on_mobile(self):
+ test_str = 'Regulation C'
+ result = regs_hide_on_mobile(test_str)
+ self.assertEqual(
+ result, 'Regulation C'
+ )
diff --git a/cfgov/regulations3k/tests/test_models.py b/cfgov/regulations3k/tests/test_models.py
index 7863fb7d603..6004a3c4fa9 100644
--- a/cfgov/regulations3k/tests/test_models.py
+++ b/cfgov/regulations3k/tests/test_models.py
@@ -48,16 +48,18 @@ def setUp(self):
self.part_1002 = mommy.make(
Part,
+ cfr_title_number=12,
part_number='1002',
title='Equal Credit Opportunity Act',
- letter_code='B',
+ short_name='Regulation B',
chapter='X'
)
self.part_1030 = mommy.make(
Part,
+ cfr_title_number=12,
part_number='1030',
title='Truth In Savings',
- letter_code='DD',
+ short_name='Regulation DD',
chapter='X'
)
@@ -208,10 +210,10 @@ def test_part_cfr_title_method(self):
part = self.part_1002
self.assertEqual(
part.cfr_title,
- "{} CFR Part {} (Regulation {})".format(
+ "{} CFR Part {} ({})".format(
part.cfr_title_number,
part.part_number,
- part.letter_code))
+ part.short_name))
def test_subpart_string_method(self):
self.assertEqual(
diff --git a/cfgov/regulations3k/tests/test_resolver.py b/cfgov/regulations3k/tests/test_resolver.py
index 9faa65f5506..bc22a0579d0 100644
--- a/cfgov/regulations3k/tests/test_resolver.py
+++ b/cfgov/regulations3k/tests/test_resolver.py
@@ -42,7 +42,7 @@ def setUp(self):
Part,
part_number='1002',
title='Equal Credit Opportunity Act',
- letter_code='B',
+ short_name='Regulation B',
chapter='X'
)
self.effective_version = mommy.make(
diff --git a/cfgov/regulations3k/wagtail_hooks.py b/cfgov/regulations3k/wagtail_hooks.py
index ef2335724d2..8171174d2bd 100644
--- a/cfgov/regulations3k/wagtail_hooks.py
+++ b/cfgov/regulations3k/wagtail_hooks.py
@@ -119,7 +119,7 @@ class PartModelAdmin(TreeModelAdmin):
list_display = (
'part_number',
'title',
- 'letter_code'
+ 'short_name'
)
child_field = 'versions'
child_model_admin = EffectiveVersionModelAdmin