From d65d84a2853aab6e958780be8fe0857a06945bd2 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 00:55:41 -0400 Subject: [PATCH 01/12] Move setup_cors command to notice_comment. By separating notice-and-comment functionality from the regulation viewer, we can define optional dependencies. Start that process by moving over this management command. --- notice_comment/__init__.py | 0 notice_comment/management/__init__.py | 0 notice_comment/management/commands/__init__.py | 0 {regulations => notice_comment}/management/commands/setup_cors.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 notice_comment/__init__.py create mode 100644 notice_comment/management/__init__.py create mode 100644 notice_comment/management/commands/__init__.py rename {regulations => notice_comment}/management/commands/setup_cors.py (100%) diff --git a/notice_comment/__init__.py b/notice_comment/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notice_comment/management/__init__.py b/notice_comment/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notice_comment/management/commands/__init__.py b/notice_comment/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/regulations/management/commands/setup_cors.py b/notice_comment/management/commands/setup_cors.py similarity index 100% rename from regulations/management/commands/setup_cors.py rename to notice_comment/management/commands/setup_cors.py From 4afd61485f52f1ef3d3dc3e474c45a0e87502501 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 01:20:58 -0400 Subject: [PATCH 02/12] Move PrepareCommentView into "comment" module. This combines all urls that begin with "comment" into the same module, which will make them easier to move. --- regulations/urls.py | 6 +++--- regulations/views/comment.py | 18 ++++++++++++++++++ regulations/views/preamble.py | 19 ------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/regulations/urls.py b/regulations/urls.py index b2ac44c23..7d1ebb990 100644 --- a/regulations/urls.py +++ b/regulations/urls.py @@ -16,8 +16,8 @@ from regulations.views.partial_search import PartialSearch from regulations.views.partial_sxs import ParagraphSXSView from regulations.views.preamble import ( - CFRChangesView, PreambleView, PrepareCommentView, - ChromePreambleSearchView) + CFRChangesView, PreambleView, ChromePreambleSearchView +) from regulations.views.redirect import ( diff_redirect, redirect_by_current_date, @@ -48,7 +48,7 @@ url(r'^about$', about, name='about'), url(r'^comments/attachment$', comment.upload_proxy), url(r'^comments/review/(?P[\w-]+)$', - PrepareCommentView.as_view(), name='comment_review'), + comment.PrepareCommentView.as_view(), name='comment_review'), url(r'^comments/preview$', comment.preview_comment), url(r'^comments/comment/(?P[\w-]+)$', comment.SubmitCommentView.as_view(), diff --git a/regulations/views/comment.py b/regulations/views/comment.py index 40809d65b..c922ec57a 100644 --- a/regulations/views/comment.py +++ b/regulations/views/comment.py @@ -203,3 +203,21 @@ def make_cache_key(*args, **kwargs): Sort the keys to ensure repeatability """ return ":".join((key + ":" + str(kwargs[key]) for key in sorted(kwargs))) + + +class PrepareCommentView(View): + def get(self, request, doc_number): + context = common_context(doc_number) + + if context['meta']['comment_state'] != CommentState.OPEN: + raise Http404("Cannot comment on {}".format(doc_number)) + + context.update(generate_html_tree(context['preamble'], request, + id_prefix=[doc_number, 'preamble'])) + context['comment_mode'] = 'write' + context['comment_fields'] = docket.safe_get_document_fields( + settings.COMMENT_DOCUMENT_ID) + template = 'regulations/comment-review-chrome.html' + + return TemplateResponse(request=request, template=template, + context=context) diff --git a/regulations/views/preamble.py b/regulations/views/preamble.py index 533fb8d67..fc7acdf4c 100644 --- a/regulations/views/preamble.py +++ b/regulations/views/preamble.py @@ -17,7 +17,6 @@ from django.views.generic.base import View from fr_notices import navigation -from regulations import docket from regulations.generator import generator from regulations.generator.api_reader import ApiReader from regulations.generator.html_builder import ( @@ -241,24 +240,6 @@ def get_context_data(self, **kwargs): return context -class PrepareCommentView(View): - def get(self, request, doc_number): - context = common_context(doc_number) - - if context['meta']['comment_state'] != CommentState.OPEN: - raise Http404("Cannot comment on {}".format(doc_number)) - - context.update(generate_html_tree(context['preamble'], request, - id_prefix=[doc_number, 'preamble'])) - context['comment_mode'] = 'write' - context['comment_fields'] = docket.safe_get_document_fields( - settings.COMMENT_DOCUMENT_ID) - template = 'regulations/comment-review-chrome.html' - - return TemplateResponse(request=request, template=template, - context=context) - - SubpartInfo = namedtuple('SubpartInfo', ['letter', 'title', 'urls', 'idx']) From 5c1e150a2eed9ae236fe0ff231d2879029821cd0 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 01:42:07 -0400 Subject: [PATCH 03/12] Move "comments" URLs into notice_comments module. --- notice_comment/tests/__init__.py | 0 .../tests/views_tests.py | 13 +++++++------ notice_comment/urls.py | 16 ++++++++++++++++ .../views/comment.py => notice_comment/views.py | 0 regulations/settings/dev.py | 2 ++ regulations/test_urls.py | 7 +++++++ regulations/urls.py | 10 ---------- 7 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 notice_comment/tests/__init__.py rename regulations/tests/views_comment_tests.py => notice_comment/tests/views_tests.py (84%) create mode 100644 notice_comment/urls.py rename regulations/views/comment.py => notice_comment/views.py (100%) create mode 100644 regulations/test_urls.py diff --git a/notice_comment/tests/__init__.py b/notice_comment/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/regulations/tests/views_comment_tests.py b/notice_comment/tests/views_tests.py similarity index 84% rename from regulations/tests/views_comment_tests.py rename to notice_comment/tests/views_tests.py index da9e1328a..fcc668b8d 100644 --- a/regulations/tests/views_comment_tests.py +++ b/notice_comment/tests/views_tests.py @@ -3,7 +3,7 @@ from django.test import SimpleTestCase, override_settings -from regulations.views import comment +from notice_comment import views @override_settings( @@ -11,6 +11,7 @@ ATTACHMENT_ACCESS_KEY_ID='test-access-key', ATTACHMENT_SECRET_ACCESS_KEY='test-secret-key', ATTACHMENT_MAX_SIZE=42, + ROOT_URLCONF='notice_comment.urls', ) class TestUploadProxy(SimpleTestCase): @@ -22,7 +23,7 @@ def test_get_url(self, get_random, mock_client, mock_time): generate_presigned.side_effect = ['first-url', 'second-url'] get_random.return_value = 'not-so-random' mock_time.return_value = 123 - resp = self.client.get('/comments/attachment?size=42&name=foo.pdf') + resp = self.client.get('/attachment?size=42&name=foo.pdf') self.assertEqual(resp.status_code, 200) body = json.loads(resp.content.decode()) generate_presigned.assert_any_call( @@ -38,7 +39,7 @@ def test_get_url(self, get_random, mock_client, mock_time): generate_presigned.assert_any_call( ClientMethod='get_object', Params={ - 'ResponseExpires': 123 + comment.PREVIEW_EXPIRATION_SECONDS, + 'ResponseExpires': 123 + views.PREVIEW_EXPIRATION_SECONDS, 'ResponseContentDisposition': 'attachment; filename="foo.pdf"', 'Bucket': 'test-bucket', 'Key': get_random.return_value, @@ -49,19 +50,19 @@ def test_get_url(self, get_random, mock_client, mock_time): self.assertEqual(body['urls']['get'], 'second-url') def test_get_url_empty(self): - resp = self.client.get('/comments/attachment?size=0&name=foo.pdf') + resp = self.client.get('/attachment?size=0&name=foo.pdf') self.assertEqual(resp.status_code, 400) body = json.loads(resp.content.decode()) self.assertEqual(body['message'], 'Invalid attachment size') def test_get_url_over_limit(self): - resp = self.client.get('/comments/attachment?size=43&name=foo.pdf') + resp = self.client.get('/attachment?size=43&name=foo.pdf') self.assertEqual(resp.status_code, 400) body = json.loads(resp.content.decode()) self.assertEqual(body['message'], 'Invalid attachment size') def test_get_url_invalid_extension(self): - resp = self.client.get('/comments/attachment?size=42&name=foo.exe') + resp = self.client.get('/attachment?size=42&name=foo.exe') self.assertEqual(resp.status_code, 400) body = json.loads(resp.content.decode()) self.assertEqual(body['message'], 'Invalid attachment type') diff --git a/notice_comment/urls.py b/notice_comment/urls.py new file mode 100644 index 000000000..c4bd0b8a9 --- /dev/null +++ b/notice_comment/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls import url + +from notice_comment.views import (PrepareCommentView, SubmitCommentView, + get_federal_agencies, get_gov_agency_types, + preview_comment, upload_proxy) + +urlpatterns = [ + url(r'^attachment$', upload_proxy), + url(r'^review/(?P[\w-]+)$', PrepareCommentView.as_view(), + name='comment_review'), + url(r'^preview$', preview_comment), + url(r'^(?P[\w-]+)$', SubmitCommentView.as_view(), + name='comment_submit'), + url(r'^federal_agencies$', get_federal_agencies), + url(r'^gov_agency_types$', get_gov_agency_types), +] diff --git a/regulations/views/comment.py b/notice_comment/views.py similarity index 100% rename from regulations/views/comment.py rename to notice_comment/views.py diff --git a/regulations/settings/dev.py b/regulations/settings/dev.py index bcb68cd7e..e6e07bae7 100644 --- a/regulations/settings/dev.py +++ b/regulations/settings/dev.py @@ -6,6 +6,8 @@ CACHES['eregs_longterm_cache']['BACKEND'] = 'django.core.cache.backends.dummy.DummyCache' CACHES['api_cache']['TIMEOUT'] = 5 # roughly per request +ROOT_URLCONF = 'regulations.test_urls' + try: from local_settings import * except ImportError: diff --git a/regulations/test_urls.py b/regulations/test_urls.py new file mode 100644 index 000000000..79da060c9 --- /dev/null +++ b/regulations/test_urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import include, url + +from regulations.urls import urlpatterns + +urlpatterns = [ + url(r'^comments/', include('notice_comment.urls')), +] + urlpatterns diff --git a/regulations/urls.py b/regulations/urls.py index 7d1ebb990..c66d546be 100644 --- a/regulations/urls.py +++ b/regulations/urls.py @@ -26,7 +26,6 @@ ) from regulations.views.sidebar import SideBarView from regulations.views.universal_landing import universal -from regulations.views import comment # Re-usable URL patterns. meta_version = r'(?P<%s>[-\d\w_]+)' @@ -46,15 +45,6 @@ url(r'^$', universal, name='universal_landing'), # about page url(r'^about$', about, name='about'), - url(r'^comments/attachment$', comment.upload_proxy), - url(r'^comments/review/(?P[\w-]+)$', - comment.PrepareCommentView.as_view(), name='comment_review'), - url(r'^comments/preview$', comment.preview_comment), - url(r'^comments/comment/(?P[\w-]+)$', - comment.SubmitCommentView.as_view(), - name='comment_submit'), - url(r'^comments/federal_agencies$', comment.get_federal_agencies), - url(r'^comments/gov_agency_types$', comment.get_gov_agency_types), # Redirect to version by date (by GET) # Example http://.../regulation_redirect/201-3-v url(r'^regulation_redirect/%s$' % paragraph_pattern, redirect_by_date_get, From 7d2544bd375cc693d1e5397541bce409cca41bdb Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 01:53:31 -0400 Subject: [PATCH 04/12] Move tasks to notice_comment module. --- {regulations => notice_comment}/tasks.py | 0 .../tests/tasks_tests.py | 16 ++++++++-------- notice_comment/tests/views_tests.py | 4 ++-- notice_comment/views.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) rename {regulations => notice_comment}/tasks.py (100%) rename {regulations => notice_comment}/tests/tasks_tests.py (91%) diff --git a/regulations/tasks.py b/notice_comment/tasks.py similarity index 100% rename from regulations/tasks.py rename to notice_comment/tasks.py diff --git a/regulations/tests/tasks_tests.py b/notice_comment/tests/tasks_tests.py similarity index 91% rename from regulations/tests/tasks_tests.py rename to notice_comment/tests/tasks_tests.py index b22d27b49..0f8dcdcf2 100644 --- a/regulations/tests/tasks_tests.py +++ b/notice_comment/tests/tasks_tests.py @@ -8,14 +8,14 @@ from django.test import TestCase, override_settings from requests.exceptions import RequestException -from regulations.tasks import submit_comment, cache_pdf, SignedUrl +from notice_comment.tasks import submit_comment, cache_pdf, SignedUrl from regulations.models import FailedCommentSubmission -@mock.patch('regulations.tasks.submit_comment.retry') -@mock.patch('regulations.tasks.post_submission') -@mock.patch('regulations.tasks.html_to_pdf') -@mock.patch('regulations.tasks.cache_pdf') +@mock.patch('notice_comment.tasks.submit_comment.retry') +@mock.patch('notice_comment.tasks.post_submission') +@mock.patch('notice_comment.tasks.html_to_pdf') +@mock.patch('notice_comment.tasks.cache_pdf') @override_settings( ATTACHMENT_BUCKET='test-bucket', ATTACHMENT_ACCESS_KEY_ID='test-access-key', @@ -102,7 +102,7 @@ def test_error_fetching_from_s3_saves(self, cached_pdf, html_to_pdf, self.comments[1]['files'].append( {"name": "file_name.png", "key": "someKey"}) retry.return_value = MaxRetriesExceededError() - with mock.patch('regulations.tasks.boto3') as boto3: + with mock.patch('notice_comment.tasks.boto3') as boto3: client = boto3.Session.return_value.client.return_value client.download_file.side_effect = botocore.exceptions.ClientError submit_comment(self.comments, self.form, self.meta) @@ -118,8 +118,8 @@ def test_error_fetching_from_s3_saves(self, cached_pdf, html_to_pdf, class TestHelpers(TestCase): - @mock.patch('regulations.tasks.SignedUrl.generate') - @mock.patch('regulations.tasks.s3_client') + @mock.patch('notice_comment.tasks.SignedUrl.generate') + @mock.patch('notice_comment.tasks.s3_client') def test_cache_pdf(self, s3_client, url_generate): meta = SignedUrl('meta', 'https://s3.amazonaws.com/bucket/meta') url_generate.return_value = SignedUrl( diff --git a/notice_comment/tests/views_tests.py b/notice_comment/tests/views_tests.py index fcc668b8d..5e7fc9b3d 100644 --- a/notice_comment/tests/views_tests.py +++ b/notice_comment/tests/views_tests.py @@ -16,8 +16,8 @@ class TestUploadProxy(SimpleTestCase): @mock.patch('time.time') - @mock.patch('regulations.tasks.s3_client') - @mock.patch('regulations.tasks.get_random_string') + @mock.patch('notice_comment.tasks.s3_client') + @mock.patch('notice_comment.tasks.get_random_string') def test_get_url(self, get_random, mock_client, mock_time): generate_presigned = mock_client.generate_presigned_url generate_presigned.side_effect = ['first-url', 'second-url'] diff --git a/notice_comment/views.py b/notice_comment/views.py index c922ec57a..ab5347c26 100644 --- a/notice_comment/views.py +++ b/notice_comment/views.py @@ -15,7 +15,7 @@ from django.views.generic.base import View import requests -from regulations import tasks +from notice_comment import tasks from regulations import docket from regulations.views.preamble import ( common_context, CommentState, generate_html_tree, first_preamble_section, From 1d960ee212c00998618d032b9d7fa6f0dae77d02 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 11:49:29 -0400 Subject: [PATCH 05/12] Move FailedCommentSubmission into notice_comment. This will require a major version bump as it could lead to data loss. --- notice_comment/migrations/0001_initial.py | 24 +++++++++++++++++++ notice_comment/migrations/__init__.py | 0 {regulations => notice_comment}/models.py | 0 notice_comment/tasks.py | 2 +- notice_comment/tests/tasks_tests.py | 2 +- .../0003_delete_failedcommentsubmission.py | 18 ++++++++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 notice_comment/migrations/0001_initial.py create mode 100644 notice_comment/migrations/__init__.py rename {regulations => notice_comment}/models.py (100%) create mode 100644 regulations/migrations/0003_delete_failedcommentsubmission.py diff --git a/notice_comment/migrations/0001_initial.py b/notice_comment/migrations/0001_initial.py new file mode 100644 index 000000000..f826c7481 --- /dev/null +++ b/notice_comment/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-18 15:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='FailedCommentSubmission', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, + serialize=False, verbose_name='ID')), + ('body', models.TextField()), + ], + ), + ] diff --git a/notice_comment/migrations/__init__.py b/notice_comment/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/regulations/models.py b/notice_comment/models.py similarity index 100% rename from regulations/models.py rename to notice_comment/models.py diff --git a/notice_comment/tasks.py b/notice_comment/tasks.py index 285aa31ba..99866b97f 100644 --- a/notice_comment/tasks.py +++ b/notice_comment/tasks.py @@ -24,7 +24,7 @@ from django.template import loader from django.utils.crypto import get_random_string -from regulations.models import FailedCommentSubmission +from notice_comment.models import FailedCommentSubmission logger = get_task_logger(__name__) diff --git a/notice_comment/tests/tasks_tests.py b/notice_comment/tests/tasks_tests.py index 0f8dcdcf2..3cee41010 100644 --- a/notice_comment/tests/tasks_tests.py +++ b/notice_comment/tests/tasks_tests.py @@ -8,8 +8,8 @@ from django.test import TestCase, override_settings from requests.exceptions import RequestException +from notice_comment.models import FailedCommentSubmission from notice_comment.tasks import submit_comment, cache_pdf, SignedUrl -from regulations.models import FailedCommentSubmission @mock.patch('notice_comment.tasks.submit_comment.retry') diff --git a/regulations/migrations/0003_delete_failedcommentsubmission.py b/regulations/migrations/0003_delete_failedcommentsubmission.py new file mode 100644 index 000000000..f58b32fd9 --- /dev/null +++ b/regulations/migrations/0003_delete_failedcommentsubmission.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-18 15:49 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('regulations', '0002_remove_failedcommentsubmission_files'), + ] + + operations = [ + migrations.DeleteModel( + name='FailedCommentSubmission', + ), + ] From 493d1271d7cce355e9179a80454052c2283dc8fa Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 11:58:44 -0400 Subject: [PATCH 06/12] Move docket module into notice_comment. --- {regulations => notice_comment}/docket.py | 0 .../tests/docket_tests.py | 6 +++--- notice_comment/views.py | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) rename {regulations => notice_comment}/docket.py (100%) rename regulations/tests/sanitize_fields_tests.py => notice_comment/tests/docket_tests.py (94%) diff --git a/regulations/docket.py b/notice_comment/docket.py similarity index 100% rename from regulations/docket.py rename to notice_comment/docket.py diff --git a/regulations/tests/sanitize_fields_tests.py b/notice_comment/tests/docket_tests.py similarity index 94% rename from regulations/tests/sanitize_fields_tests.py rename to notice_comment/tests/docket_tests.py index b873905d8..7de3a55d2 100644 --- a/regulations/tests/sanitize_fields_tests.py +++ b/notice_comment/tests/docket_tests.py @@ -4,13 +4,13 @@ import httpretty import requests -from regulations.docket import sanitize_fields +from notice_comment.docket import sanitize_fields class SanitizeFieldsTest(TestCase): def setUp(self): self.patch_document_fields = patch( - 'regulations.docket.get_document_fields') + 'notice_comment.docket.get_document_fields') mock_object = self.patch_document_fields.start() mock_object.return_value = { 'required_field': {'maxLength': 10, 'required': True}, @@ -82,7 +82,7 @@ def test_503(self): valid, message = sanitize_fields({'something': 'else'}) self.assertTrue(valid) - @patch('regulations.docket.requests.get') + @patch('notice_comment.docket.requests.get') def test_timeout(self, get): get.side_effect = requests.Timeout with self.settings(REGS_GOV_API_URL='http://example.com'): diff --git a/notice_comment/views.py b/notice_comment/views.py index ab5347c26..d80d2281e 100644 --- a/notice_comment/views.py +++ b/notice_comment/views.py @@ -15,8 +15,7 @@ from django.views.generic.base import View import requests -from notice_comment import tasks -from regulations import docket +from notice_comment import docket, tasks from regulations.views.preamble import ( common_context, CommentState, generate_html_tree, first_preamble_section, notice_data) From 43783d1058f02f645c14a734e7e2245625c28cf7 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 12:11:42 -0400 Subject: [PATCH 07/12] Move comment-related templates to notice_comment. --- notice_comment/tasks.py | 2 +- .../templates/notice_comment/additional-info.html | 0 .../templates/notice_comment}/comment.html | 0 .../templates/notice_comment/confirm-chrome.html | 6 +++--- .../templates/notice_comment/confirm-fail.html | 0 .../templates/notice_comment/confirm-invalid.html | 2 +- .../templates/notice_comment/confirm-success.html | 0 .../templates/notice_comment/disclaimer.html | 0 .../templates/notice_comment/review-chrome.html | 4 ++-- notice_comment/views.py | 4 ++-- 10 files changed, 9 insertions(+), 9 deletions(-) rename regulations/templates/regulations/comment-additional-info.html => notice_comment/templates/notice_comment/additional-info.html (100%) rename {regulations/templates/regulations => notice_comment/templates/notice_comment}/comment.html (100%) rename regulations/templates/regulations/comment-confirm-chrome.html => notice_comment/templates/notice_comment/confirm-chrome.html (71%) rename regulations/templates/regulations/comment-confirm-fail.html => notice_comment/templates/notice_comment/confirm-fail.html (100%) rename regulations/templates/regulations/comment-confirm-invalid.html => notice_comment/templates/notice_comment/confirm-invalid.html (75%) rename regulations/templates/regulations/comment-confirm-success.html => notice_comment/templates/notice_comment/confirm-success.html (100%) rename regulations/templates/regulations/comment-disclaimer.html => notice_comment/templates/notice_comment/disclaimer.html (100%) rename regulations/templates/regulations/comment-review-chrome.html => notice_comment/templates/notice_comment/review-chrome.html (96%) diff --git a/notice_comment/tasks.py b/notice_comment/tasks.py index 99866b97f..8e47161e3 100644 --- a/notice_comment/tasks.py +++ b/notice_comment/tasks.py @@ -102,7 +102,7 @@ def json_to_html(sections, mark_as_draft=False): :param mark_as_draft: Indicates if the HTML is to be marked as DRAFT """ return loader.render_to_string( - 'regulations/comment.html', + 'notice_comment/comment.html', {'sections': sections, 'mark_as_draft': mark_as_draft} ) diff --git a/regulations/templates/regulations/comment-additional-info.html b/notice_comment/templates/notice_comment/additional-info.html similarity index 100% rename from regulations/templates/regulations/comment-additional-info.html rename to notice_comment/templates/notice_comment/additional-info.html diff --git a/regulations/templates/regulations/comment.html b/notice_comment/templates/notice_comment/comment.html similarity index 100% rename from regulations/templates/regulations/comment.html rename to notice_comment/templates/notice_comment/comment.html diff --git a/regulations/templates/regulations/comment-confirm-chrome.html b/notice_comment/templates/notice_comment/confirm-chrome.html similarity index 71% rename from regulations/templates/regulations/comment-confirm-chrome.html rename to notice_comment/templates/notice_comment/confirm-chrome.html index 031edeba6..8ee325e80 100644 --- a/regulations/templates/regulations/comment-confirm-chrome.html +++ b/notice_comment/templates/notice_comment/confirm-chrome.html @@ -9,11 +9,11 @@ data-metadata-url="{{metadata_url}}" data-doc-id="{{doc_number}}"> {% if message %} - {% include 'regulations/comment-confirm-invalid.html' %} + {% include 'notice_comment/confirm-invalid.html' %} {% elif not metadata_url %} - {% include 'regulations/comment-confirm-fail.html' %} + {% include 'notice_comment/confirm-fail.html' %} {% else %} - {% include 'regulations/comment-confirm-success.html' %} + {% include 'notice_comment/confirm-success.html' %} {% endif %} diff --git a/regulations/templates/regulations/comment-confirm-fail.html b/notice_comment/templates/notice_comment/confirm-fail.html similarity index 100% rename from regulations/templates/regulations/comment-confirm-fail.html rename to notice_comment/templates/notice_comment/confirm-fail.html diff --git a/regulations/templates/regulations/comment-confirm-invalid.html b/notice_comment/templates/notice_comment/confirm-invalid.html similarity index 75% rename from regulations/templates/regulations/comment-confirm-invalid.html rename to notice_comment/templates/notice_comment/confirm-invalid.html index 610d63871..aef70cbfc 100644 --- a/regulations/templates/regulations/comment-confirm-invalid.html +++ b/notice_comment/templates/notice_comment/confirm-invalid.html @@ -1,4 +1,4 @@ -{% extends "regulations/comment-confirm-fail.html" %} +{% extends "notice_comment/confirm-fail.html" %} {% block alert-text %}
diff --git a/regulations/templates/regulations/comment-confirm-success.html b/notice_comment/templates/notice_comment/confirm-success.html similarity index 100% rename from regulations/templates/regulations/comment-confirm-success.html rename to notice_comment/templates/notice_comment/confirm-success.html diff --git a/regulations/templates/regulations/comment-disclaimer.html b/notice_comment/templates/notice_comment/disclaimer.html similarity index 100% rename from regulations/templates/regulations/comment-disclaimer.html rename to notice_comment/templates/notice_comment/disclaimer.html diff --git a/regulations/templates/regulations/comment-review-chrome.html b/notice_comment/templates/notice_comment/review-chrome.html similarity index 96% rename from regulations/templates/regulations/comment-review-chrome.html rename to notice_comment/templates/notice_comment/review-chrome.html index 267c1d3d4..c0e5eb5be 100644 --- a/regulations/templates/regulations/comment-review-chrome.html +++ b/notice_comment/templates/notice_comment/review-chrome.html @@ -67,10 +67,10 @@

Building your PDF...

- {% include 'regulations/comment-additional-info.html' %} + {% include 'notice_comment/additional-info.html' %}
- {% include 'regulations/comment-disclaimer.html' %} + {% include 'notice_comment/disclaimer.html' %}
diff --git a/notice_comment/views.py b/notice_comment/views.py index d80d2281e..4ebe2256b 100644 --- a/notice_comment/views.py +++ b/notice_comment/views.py @@ -125,7 +125,7 @@ def post(self, request, doc_number): except Exception as exc: logger.exception(exc) - template = 'regulations/comment-confirm-chrome.html' + template = 'notice_comment/confirm-chrome.html' return TemplateResponse(request=request, template=template, context=context) @@ -216,7 +216,7 @@ def get(self, request, doc_number): context['comment_mode'] = 'write' context['comment_fields'] = docket.safe_get_document_fields( settings.COMMENT_DOCUMENT_ID) - template = 'regulations/comment-review-chrome.html' + template = 'notice_comment/review-chrome.html' return TemplateResponse(request=request, template=template, context=context) From 531d3e93d266dd32ce33b5532ff50fc6dc1f3c03 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 12:14:49 -0400 Subject: [PATCH 08/12] Separate notice_comment dependencies, add to tests. This will significantly reduce the number of transitive dependencies needed by ATF, FEC, etc. --- regulations/settings/dev.py | 1 + setup.py | 6 +++--- tox.ini | 16 +++++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/regulations/settings/dev.py b/regulations/settings/dev.py index e6e07bae7..582a5b76a 100644 --- a/regulations/settings/dev.py +++ b/regulations/settings/dev.py @@ -7,6 +7,7 @@ CACHES['api_cache']['TIMEOUT'] = 5 # roughly per request ROOT_URLCONF = 'regulations.test_urls' +INSTALLED_APPS = INSTALLED_APPS + ('notice_comment',) try: from local_settings import * diff --git a/setup.py b/setup.py index ab587d7e2..1f747ae3f 100644 --- a/setup.py +++ b/setup.py @@ -7,16 +7,16 @@ packages=find_packages(), include_package_data=True, install_requires=[ - 'boto3', 'cached-property', - 'celery', 'django>=1.8,<1.12', 'enum34', 'futures', 'requests', 'six', - 'requests-toolbelt', ], + extras_require={ + 'notice_comment': ['boto3', 'celery', 'requests-toolbelt'], + }, classifiers=[ 'License :: Public Domain', 'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication' diff --git a/tox.ini b/tox.ini index 5674bdb2b..5b09781a9 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ deps = pytest~=3.0 pytest_cov~=2.4 pytest_django~=3.1 +extras = notice_comment commands = pytest --cov @@ -24,15 +25,16 @@ deps = bandit==1.4.0 flake8==2.5.4 commands = - flake8 fr_notices regulations - bandit -r --ini tox.ini fr_notices regulations manage.py setup.py + flake8 fr_notices notice_comment regulations + bandit -r --ini tox.ini fr_notices notice_comment regulations manage.py setup.py [testenv:docs] deps = sphinx commands = # Tox won't do wildcard expansion, so run in a shell - sh -c "rm -f docs/regulations*.rst docs/fr_notices*.rst" + sh -c "rm -f docs/regulations*.rst docs/fr_notices*.rst docs/notice_comment*.rst" sphinx-apidoc -F -o docs fr_notices + sphinx-apidoc -F -o docs notice_comment sphinx-apidoc -F -o docs regulations sphinx-build -b dirhtml -d docs/_build/doctrees/ docs/ docs/_build/dirhtml/ whitelist_externals = sh @@ -55,11 +57,11 @@ passenv = commands = py.test regulations/uitests -s [bandit] -exclude = fr_notices/tests,regulations/tests,regulations/uitests +exclude = fr_notices/tests,notice_comment/tests,regulations/tests,regulations/uitests [coverage:run] -source = regulations,fr_notices -omit = regulations/uitests/*,regulations/tests/*,fr_notices/tests/* +source = regulations,fr_notices,notice_comment +omit = regulations/uitests/*,regulations/tests/*,fr_notices/tests/*,notice_comment/tests/* [flake8] exclude = regulations/settings/*.py @@ -67,7 +69,7 @@ exclude = regulations/settings/*.py [isort] [pytest] -testpaths = regulations/tests fr_notices/tests +testpaths = regulations/tests fr_notices/tests notice_comment/tests python_files = tests_*.py *_test.py *_tests.py DJANGO_SETTINGS_MODULE = regulations.settings.dev From 41b5fda4dffc80db753c38015d4917c439d7e1bc Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 13:48:15 -0400 Subject: [PATCH 09/12] Update docs. --- docs/notice_comment.management.commands.rst | 22 +++++++ docs/notice_comment.management.rst | 17 ++++++ docs/notice_comment.migrations.rst | 22 +++++++ docs/notice_comment.rst | 63 +++++++++++++++++++++ docs/notice_comment.tests.rst | 38 +++++++++++++ docs/regulations.management.commands.rst | 8 --- docs/regulations.migrations.rst | 8 +++ docs/regulations.rst | 24 -------- docs/regulations.tests.rst | 24 -------- docs/regulations.views.rst | 8 --- 10 files changed, 170 insertions(+), 64 deletions(-) create mode 100644 docs/notice_comment.management.commands.rst create mode 100644 docs/notice_comment.management.rst create mode 100644 docs/notice_comment.migrations.rst create mode 100644 docs/notice_comment.rst create mode 100644 docs/notice_comment.tests.rst diff --git a/docs/notice_comment.management.commands.rst b/docs/notice_comment.management.commands.rst new file mode 100644 index 000000000..a89baf2c4 --- /dev/null +++ b/docs/notice_comment.management.commands.rst @@ -0,0 +1,22 @@ +notice\_comment\.management\.commands package +============================================= + +Submodules +---------- + +notice\_comment\.management\.commands\.setup\_cors module +--------------------------------------------------------- + +.. automodule:: notice_comment.management.commands.setup_cors + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: notice_comment.management.commands + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/notice_comment.management.rst b/docs/notice_comment.management.rst new file mode 100644 index 000000000..fa10069a4 --- /dev/null +++ b/docs/notice_comment.management.rst @@ -0,0 +1,17 @@ +notice\_comment\.management package +=================================== + +Subpackages +----------- + +.. toctree:: + + notice_comment.management.commands + +Module contents +--------------- + +.. automodule:: notice_comment.management + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/notice_comment.migrations.rst b/docs/notice_comment.migrations.rst new file mode 100644 index 000000000..432c842b7 --- /dev/null +++ b/docs/notice_comment.migrations.rst @@ -0,0 +1,22 @@ +notice\_comment\.migrations package +=================================== + +Submodules +---------- + +notice\_comment\.migrations\.0001\_initial module +------------------------------------------------- + +.. automodule:: notice_comment.migrations.0001_initial + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: notice_comment.migrations + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/notice_comment.rst b/docs/notice_comment.rst new file mode 100644 index 000000000..20f738aea --- /dev/null +++ b/docs/notice_comment.rst @@ -0,0 +1,63 @@ +notice\_comment package +======================= + +Subpackages +----------- + +.. toctree:: + + notice_comment.management + notice_comment.migrations + notice_comment.tests + +Submodules +---------- + +notice\_comment\.docket module +------------------------------ + +.. automodule:: notice_comment.docket + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.models module +------------------------------ + +.. automodule:: notice_comment.models + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.tasks module +----------------------------- + +.. automodule:: notice_comment.tasks + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.urls module +---------------------------- + +.. automodule:: notice_comment.urls + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.views module +----------------------------- + +.. automodule:: notice_comment.views + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: notice_comment + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/notice_comment.tests.rst b/docs/notice_comment.tests.rst new file mode 100644 index 000000000..e0fe79cc1 --- /dev/null +++ b/docs/notice_comment.tests.rst @@ -0,0 +1,38 @@ +notice\_comment\.tests package +============================== + +Submodules +---------- + +notice\_comment\.tests\.docket\_tests module +-------------------------------------------- + +.. automodule:: notice_comment.tests.docket_tests + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.tests\.tasks\_tests module +------------------------------------------- + +.. automodule:: notice_comment.tests.tasks_tests + :members: + :undoc-members: + :show-inheritance: + +notice\_comment\.tests\.views\_tests module +------------------------------------------- + +.. automodule:: notice_comment.tests.views_tests + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: notice_comment.tests + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/regulations.management.commands.rst b/docs/regulations.management.commands.rst index b7d0ec1c8..0c6aff955 100644 --- a/docs/regulations.management.commands.rst +++ b/docs/regulations.management.commands.rst @@ -36,14 +36,6 @@ regulations\.management\.commands\.fetch\_wkhtmltox module :undoc-members: :show-inheritance: -regulations\.management\.commands\.setup\_cors module ------------------------------------------------------ - -.. automodule:: regulations.management.commands.setup_cors - :members: - :undoc-members: - :show-inheritance: - Module contents --------------- diff --git a/docs/regulations.migrations.rst b/docs/regulations.migrations.rst index adc3b0371..d3c02042d 100644 --- a/docs/regulations.migrations.rst +++ b/docs/regulations.migrations.rst @@ -20,6 +20,14 @@ regulations\.migrations\.0002\_remove\_failedcommentsubmission\_files module :undoc-members: :show-inheritance: +regulations\.migrations\.0003\_delete\_failedcommentsubmission module +--------------------------------------------------------------------- + +.. automodule:: regulations.migrations.0003_delete_failedcommentsubmission + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/docs/regulations.rst b/docs/regulations.rst index a865f32e2..6115c66c3 100644 --- a/docs/regulations.rst +++ b/docs/regulations.rst @@ -34,30 +34,6 @@ regulations\.context module :undoc-members: :show-inheritance: -regulations\.docket module --------------------------- - -.. automodule:: regulations.docket - :members: - :undoc-members: - :show-inheritance: - -regulations\.models module --------------------------- - -.. automodule:: regulations.models - :members: - :undoc-members: - :show-inheritance: - -regulations\.tasks module -------------------------- - -.. automodule:: regulations.tasks - :members: - :undoc-members: - :show-inheritance: - regulations\.url\_caches module ------------------------------- diff --git a/docs/regulations.tests.rst b/docs/regulations.tests.rst index 2f2c274b9..6e581e02d 100644 --- a/docs/regulations.tests.rst +++ b/docs/regulations.tests.rst @@ -204,14 +204,6 @@ regulations\.tests\.partial\_view\_tests module :undoc-members: :show-inheritance: -regulations\.tests\.sanitize\_fields\_tests module --------------------------------------------------- - -.. automodule:: regulations.tests.sanitize_fields_tests - :members: - :undoc-members: - :show-inheritance: - regulations\.tests\.sidebar\_analyses\_tests module --------------------------------------------------- @@ -228,14 +220,6 @@ regulations\.tests\.sidebar\_help\_tests module :undoc-members: :show-inheritance: -regulations\.tests\.tasks\_tests module ---------------------------------------- - -.. automodule:: regulations.tests.tasks_tests - :members: - :undoc-members: - :show-inheritance: - regulations\.tests\.templatetags\_macros\_tests module ------------------------------------------------------ @@ -292,14 +276,6 @@ regulations\.tests\.views\_chrome\_tests module :undoc-members: :show-inheritance: -regulations\.tests\.views\_comment\_tests module ------------------------------------------------- - -.. automodule:: regulations.tests.views_comment_tests - :members: - :undoc-members: - :show-inheritance: - regulations\.tests\.views\_diff\_tests module --------------------------------------------- diff --git a/docs/regulations.views.rst b/docs/regulations.views.rst index 73ea4ccc2..61be9a8ce 100644 --- a/docs/regulations.views.rst +++ b/docs/regulations.views.rst @@ -28,14 +28,6 @@ regulations\.views\.chrome\_breakaway module :undoc-members: :show-inheritance: -regulations\.views\.comment module ----------------------------------- - -.. automodule:: regulations.views.comment - :members: - :undoc-members: - :show-inheritance: - regulations\.views\.diff module ------------------------------- From c30e6c7a9f4d1c64d5043cf2d553fa662a21fa04 Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Tue, 18 Jul 2017 15:11:15 -0400 Subject: [PATCH 10/12] Include notice_comment in dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 503523703..747564358 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,10 @@ RUN npm install --quiet -g grunt-cli COPY ["manage.py", "package.json", "example-config.json", "setup.py", "frontendbuild.sh", "Gruntfile.js", ".babelrc", ".eslintignore", ".eslintrc", "/app/src/"] COPY ["regulations", "/app/src/regulations"] COPY ["fr_notices", "/app/src/fr_notices"] +COPY ["notice_comment", "/app/src/notice_comment"] WORKDIR /app/src/ RUN ./frontendbuild.sh -RUN $PIP_CMD install --no-cache-dir -e . \ +RUN $PIP_CMD install --no-cache-dir -e .[notice_comment] \ && $PYTHON_CMD manage.py migrate ENV PYTHONUNBUFFERED="1" From 9a95fa2696313ca677761836fec6ed3d16d3acfb Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Wed, 26 Jul 2017 10:03:14 -0400 Subject: [PATCH 11/12] Rename urls file to indicate general use. --- regulations/{test_urls.py => all_urls.py} | 0 regulations/settings/dev.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename regulations/{test_urls.py => all_urls.py} (100%) diff --git a/regulations/test_urls.py b/regulations/all_urls.py similarity index 100% rename from regulations/test_urls.py rename to regulations/all_urls.py diff --git a/regulations/settings/dev.py b/regulations/settings/dev.py index 582a5b76a..b41a9d8af 100644 --- a/regulations/settings/dev.py +++ b/regulations/settings/dev.py @@ -6,7 +6,7 @@ CACHES['eregs_longterm_cache']['BACKEND'] = 'django.core.cache.backends.dummy.DummyCache' CACHES['api_cache']['TIMEOUT'] = 5 # roughly per request -ROOT_URLCONF = 'regulations.test_urls' +ROOT_URLCONF = 'regulations.all_urls' INSTALLED_APPS = INSTALLED_APPS + ('notice_comment',) try: From 504c7b3773c0f88ca405203b61c3d2ec384d7dcd Mon Sep 17 00:00:00 2001 From: CM Lubinski Date: Wed, 26 Jul 2017 10:04:10 -0400 Subject: [PATCH 12/12] Update version to 8.0.0. In this release: Some of the Notice-and-Comment functionality has been split into a separate Django app. This should significantly reduce the dependencies of down-stream applications which don't use that feature. Warning of data loss: The "FailedCommentSubmission" model has moved from `regulations` to `notice_comment` without a corresponding data migration. If this data is important, please export it before running migrations. Alternatively, you may run only the `notice_comment` migrations, manually transfer the data, then run the `regulations` migrations. Upgrade steps: If your app does not need Notice-and-Comment, no changes are needed. If your app does include N&C, you will need to: * Add `regulations[notice_comment]` as a Python requirement (rather than just `regulations`) * Add `notice_comment` to your `INSTALLED_APPS` in the Django settings * Mount the N&C urls either by directly including `notice_comment.urls` or by deferring to `regulations.all_urls` * Migrate your database. Note the potential for data loss above! --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1f747ae3f..613d8c08e 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="regulations", - version="7.1.0", + version="8.0.0", packages=find_packages(), include_package_data=True, install_requires=[