Skip to content

Commit

Permalink
Merge pull request #5094 from cfpb/regs3k-short-name
Browse files Browse the repository at this point in the history
Regulations: Deprecate letter codes in favor of short names
  • Loading branch information
willbarton authored Jul 29, 2019
2 parents 99b37a1 + 15d5e9b commit 23f20e3
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 46 deletions.
22 changes: 11 additions & 11 deletions cfgov/regulations3k/fixtures/parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
22 changes: 11 additions & 11 deletions cfgov/regulations3k/fixtures/regdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cfgov/regulations3k/fixtures/test_parts.json
Original file line number Diff line number Diff line change
@@ -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}]
2 changes: 1 addition & 1 deletion cfgov/regulations3k/fixtures/tree_limb.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h1>{{section.title}}</h1>
<div class="wrapper content_wrapper">
<div class="content_sidebar content__flush-top content__flush-bottom">
<span class="h4">
Regulation {{regulation.letter_code}}
{{ regulation.short_name }}
</span>
</div>
<div class="content_main content__flush-top content__flush-bottom">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h2 class="h3">No results match your filters.</h2>
{% for reg in page.results.all_regs %}
{% if reg.selected %}
{%- set reg_name = '(Reg<span class="u-hide-on-mobile">ulation</span> ' ~ reg.letter_code ~ ')' -%}
{%- set reg_name = '(' ~ reg.short_name | regs_hide_on_mobile ~ ')' -%}
{{ tag.render({
'label': reg.id ~ ' ' ~ reg_name | safe,
'value': reg.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h3>Refine results</h3>
<ul class="m-list m-list__unstyled">
{% for reg in page.results.all_regs %}
{%- set reg_name = '(Reg<span class="u-hide-on-tablet">ulation</span> ' ~ reg.letter_code ~ ')' -%}
{%- set reg_name = '(' ~ reg.short_name ~ ')' -%}
<li>
{{ checkbox.render({
'label': reg.id ~ ' ' ~ reg_name | safe,
Expand Down
10 changes: 10 additions & 0 deletions cfgov/regulations3k/jinja2tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'Reg<span class="u-hide-on-mobile">ulation</span>'
))
return text


class RegulationsExtension(Extension):

def __init__(self, environment):
Expand All @@ -43,6 +52,7 @@ def __init__(self, environment):
})
self.environment.filters.update({
'regdown': regdown_filter,
'regs_hide_on_mobile': regs_hide_on_mobile,
})


Expand Down
20 changes: 20 additions & 0 deletions cfgov/regulations3k/migrations/0025_part_short_name.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
Original file line number Diff line number Diff line change
@@ -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),
]
12 changes: 6 additions & 6 deletions cfgov/regulations3k/models/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions cfgov/regulations3k/models/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -107,18 +106,20 @@ 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(
self.parent().url, hit.part,
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)
Expand Down
Loading

0 comments on commit 23f20e3

Please sign in to comment.