From e3ab6573f48881115e841bd496461565eb256582 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Wed, 20 Sep 2023 22:40:06 -0400 Subject: [PATCH 1/9] add doc link and metadata to single doc page --- fec/home/templates/home/document_page.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fec/home/templates/home/document_page.html b/fec/home/templates/home/document_page.html index 4bee83d23e..66e95a1969 100644 --- a/fec/home/templates/home/document_page.html +++ b/fec/home/templates/home/document_page.html @@ -18,9 +18,11 @@
{% spaceless %}{# for inline blocks #} -

{% formatted_title self %}

+

{% formatted_title self %}

- {{ self.display_date }} + {{ self.display_date }} | + {{ self.extension }}{% if self.size %} | ({{ self.size }}){% endif %} +
{% endspaceless %}
From 4f0b0271b02ff066c4909763d20623d75b64f6ac Mon Sep 17 00:00:00 2001 From: John Carroll Date: Thu, 21 Sep 2023 00:08:46 -0400 Subject: [PATCH 2/9] link category button to filtered parent --- fec/home/templates/home/document_page.html | 2 +- fec/home/templatetags/filters.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fec/home/templates/home/document_page.html b/fec/home/templates/home/document_page.html index 66e95a1969..185787486f 100644 --- a/fec/home/templates/home/document_page.html +++ b/fec/home/templates/home/document_page.html @@ -13,7 +13,7 @@
diff --git a/fec/home/templatetags/filters.py b/fec/home/templatetags/filters.py index d33ae4f3bf..d94c52f237 100644 --- a/fec/home/templatetags/filters.py +++ b/fec/home/templatetags/filters.py @@ -189,3 +189,10 @@ def get_file_type(value): file_type = "EXCEL" if xl else file_extension return file_type + + +@register.filter(name='cms_query_syntax') +def cms_query_syntax(string): + query = string.replace(' ', '+').lower() + + return query From 93262352ee33df2ee37255f1b435aa8fd756744f Mon Sep 17 00:00:00 2001 From: John Carroll Date: Wed, 27 Sep 2023 21:16:25 -0400 Subject: [PATCH 3/9] meta refresh on document page and filtered button on initial load of reports search --- fec/home/models.py | 5 ++-- fec/home/templates/home/document_page.html | 32 ++++++++++++++++++++-- fec/home/templates/partials/document.html | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/fec/home/models.py b/fec/home/models.py index 4c4731d81c..37d54760ba 100644 --- a/fec/home/models.py +++ b/fec/home/models.py @@ -724,7 +724,8 @@ def display_date(self): @property def extension(self): # Return the file extension of file_url - return self.file_url.rsplit('.', 1)[1].upper() + if self.file_url: + return self.file_url.rsplit('.', 1)[1].upper() class DocumentFeedPage(ContentPage): @@ -1372,7 +1373,7 @@ class ReportingDatesTable(Page): ('html', blocks.RawHTMLBlock()), ('internal_button', InternalButtonBlock()), ('external_button', ExternalButtonBlock()), - ('dates_table', ReportingTableBlock(blank=True, required=False,form_classname='title')), + ('dates_table', ReportingTableBlock(blank=True, required=False, form_classname='title')), ], blank=True, null=True, use_json_field=True, collapsed=False) footnotes = StreamField([ diff --git a/fec/home/templates/home/document_page.html b/fec/home/templates/home/document_page.html index 185787486f..22460c0550 100644 --- a/fec/home/templates/home/document_page.html +++ b/fec/home/templates/home/document_page.html @@ -4,8 +4,17 @@ {% load static %} {% block body_class %}template-{{ self.get_verbose_name | slugify }}{% endblock %} + + {% block content %} + + + + + {% include 'partials/breadcrumbs.html' with page=self links=self.get_ancestors style='secondary' %}
@@ -13,15 +22,22 @@
{% spaceless %}{# for inline blocks #} -

{% formatted_title self %}

+

{% if self.file_url %}{% formatted_title self %} + {% else %} + {% formatted_title self %} + {% endif %}

{{ self.display_date }} | - {{ self.extension }}{% if self.size %} | ({{ self.size }}){% endif %} + {% if self.file_url %} {{ self.extension }} + {% else %} + {{ self.extension }} + {% endif %} + {% if self.size %} | ({{ self.size }}){% endif %}
{% endspaceless %} @@ -33,5 +49,15 @@

{% formatted_title self

{% include 'partials/disclaimer.html' %} + {% endblock %} diff --git a/fec/home/templates/partials/document.html b/fec/home/templates/partials/document.html index 5ea04da494..39f50d600b 100644 --- a/fec/home/templates/partials/document.html +++ b/fec/home/templates/partials/document.html @@ -29,6 +29,6 @@

{% endif %}
From 009d6ed6446f27d991512da8be84c54286c0be3a Mon Sep 17 00:00:00 2001 From: John Carroll Date: Tue, 10 Oct 2023 00:19:31 -0400 Subject: [PATCH 4/9] form and document sitemaps --- fec/fec/urls.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/fec/fec/urls.py b/fec/fec/urls.py index 89c254e1ae..de330b91b2 100644 --- a/fec/fec/urls.py +++ b/fec/fec/urls.py @@ -14,6 +14,12 @@ from home import views as home_views from search import views as search_views +# ############# NEW ############ +import re +from django.contrib.sitemaps import Sitemap +from wagtail.documents.models import Document +from home.models import DocumentPage +# ############# /END NEW ############ urlpatterns = [ re_path( @@ -55,6 +61,78 @@ ] +# ########### NEW ################ + +class FormsSitemap(Sitemap): + changefreq = "never" + priority = 0.5 + protocol = 'https' + + def items(self): + return Document.objects.filter(file__icontains="fecfrm") + + def location(self, obj): + # THIS ONE WORKS LOCALLY RESOLVING TO `MEDIA`, TEST ON DEV TO SEE IF IT RESOLVES TO `DEFAULT_FILE_STORAGE` + return obj.file.url + # WORKS + # return '/resources/cms_content/'+str(obj.file) + # return str(obj.file).replace('documents/', '/resources/cms_content/documents/') + + def lastmod(self, obj): + return obj.created_at + + +urlpatterns += [ + + re_path( + r'^sitemap-forms\.xml/$', + sitemap, + {"sitemaps": {'forms': FormsSitemap()}}, + name="django.contrib.sitemaps.views.sitemap", + ), +] + +# ################# + + +class ReportsSitemap(Sitemap): + changefreq = "never" + priority = 0.5 + protocol = 'https' + + def items(self): + return DocumentPage.objects.live() + + def location(self, obj): + # loc = obj.file_url.replace('https://www.fec.gov', '') if obj.file_url else obj.url_path.replace('/home', '') + loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) \ + if obj.file_url \ + else obj.url_path.replace('/home', '') + + # 'http://127.0.0.1:8000https://www.fec.gov/resources/cms-content/documents/2012WorkPlan.pdf' + return loc + + def lastmod(self, obj): + return obj.date + + # Not a thing + def description(self, obj): + return obj.page_title + + +urlpatterns += [ + + re_path( + r'^sitemap-reports\.xml/$', + sitemap, + {"sitemaps": {'reports': ReportsSitemap()}}, + name="django.contrib.sitemaps.views.sitemap", + ), +] + +# ################# /END NEW ################ + + if settings.FEC_CMS_ENVIRONMENT != 'LOCAL': # admin/login always must come before admin/, so place at beginning of list urlpatterns.insert(0, re_path(r'^admin/login', uaa_views.login, name='login')) From 1d604a3a9f24c02b91ee910f1b6849dbe9c209fc Mon Sep 17 00:00:00 2001 From: John Carroll Date: Tue, 10 Oct 2023 00:21:50 -0400 Subject: [PATCH 5/9] task for dev deploy --- tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 9ee9c55273..491a301aa9 100644 --- a/tasks.py +++ b/tasks.py @@ -74,7 +74,7 @@ def _detect_space(repo, branch=None, yes=False): DEPLOY_RULES = ( ('prod', _detect_prod), ('stage', lambda _, branch: branch.startswith('release')), - ('dev', lambda _, branch: branch == 'develop'), + ('dev', lambda _, branch: branch == 'feature/innovation-document-form-sitemaps'), # Uncomment below and adjust branch name to deploy desired feature branch to the feature space # ('feature', lambda _, branch: branch == '[BRANCH NAME]'), ) From 4c41b9d28534db2be12432fab6d56b17e6790c82 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Wed, 11 Oct 2023 12:20:11 -0400 Subject: [PATCH 6/9] rm app.cloud.gov domain from url --- fec/fec/urls.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fec/fec/urls.py b/fec/fec/urls.py index de330b91b2..09fd1c773c 100644 --- a/fec/fec/urls.py +++ b/fec/fec/urls.py @@ -73,11 +73,18 @@ def items(self): def location(self, obj): # THIS ONE WORKS LOCALLY RESOLVING TO `MEDIA`, TEST ON DEV TO SEE IF IT RESOLVES TO `DEFAULT_FILE_STORAGE` - return obj.file.url + # UPDATE^^: RETURNS THIS ON DEV: \ + # `https://dev.fec.govhttps://fec-dev-proxy.app.cloud.gov/resources/cms-content/documents/fecfrm2sf.pdf` + # return obj.file.url + # WORKS # return '/resources/cms_content/'+str(obj.file) # return str(obj.file).replace('documents/', '/resources/cms_content/documents/') + # THIS ONE SHOULD REMOVE THE `https://fec-dev-proxy.app.cloud.gov` ABOVE, ON DEV...NEED TO PUSH TO TEST + loc = re.sub(r'^[^:]+:\/\/[^/?#]+', '', obj.file.url) + return loc + def lastmod(self, obj): return obj.created_at From 1b49a1827e1efdc464b1914bca61a5f79c4e74cc Mon Sep 17 00:00:00 2001 From: John Carroll Date: Thu, 12 Oct 2023 18:41:31 -0400 Subject: [PATCH 7/9] update comments --- fec/fec/urls.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fec/fec/urls.py b/fec/fec/urls.py index 09fd1c773c..2d27f33e2b 100644 --- a/fec/fec/urls.py +++ b/fec/fec/urls.py @@ -72,16 +72,16 @@ def items(self): return Document.objects.filter(file__icontains="fecfrm") def location(self, obj): - # THIS ONE WORKS LOCALLY RESOLVING TO `MEDIA`, TEST ON DEV TO SEE IF IT RESOLVES TO `DEFAULT_FILE_STORAGE` + # WORKS BUT: WORKS LOCALLY RESOLVING TO `MEDIA`, TEST ON DEV TO SEE IF IT RESOLVES TO `DEFAULT_FILE_STORAGE` # UPDATE^^: RETURNS THIS ON DEV: \ # `https://dev.fec.govhttps://fec-dev-proxy.app.cloud.gov/resources/cms-content/documents/fecfrm2sf.pdf` # return obj.file.url - # WORKS + # WORKS: RETURNS JUST THE FILE THEN CONCATENATES THE PATH TO IT # return '/resources/cms_content/'+str(obj.file) # return str(obj.file).replace('documents/', '/resources/cms_content/documents/') - # THIS ONE SHOULD REMOVE THE `https://fec-dev-proxy.app.cloud.gov` ABOVE, ON DEV...NEED TO PUSH TO TEST + # WORKS: THIS ONE REMOVES THE `https://fec-dev-proxy.app.cloud.gov` , TESTED ON DEV loc = re.sub(r'^[^:]+:\/\/[^/?#]+', '', obj.file.url) return loc From 7b1e16cb9315c9e4ff1f993215eec371f76e074b Mon Sep 17 00:00:00 2001 From: John Carroll Date: Sun, 15 Oct 2023 17:53:28 -0400 Subject: [PATCH 8/9] wip use children of reports instead of all document pages --- fec/fec/urls.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/fec/fec/urls.py b/fec/fec/urls.py index 2d27f33e2b..3d82c0ac15 100644 --- a/fec/fec/urls.py +++ b/fec/fec/urls.py @@ -16,9 +16,12 @@ # ############# NEW ############ import re +from itertools import chain from django.contrib.sitemaps import Sitemap from wagtail.documents.models import Document -from home.models import DocumentPage +from wagtail.models import Page +from home.models import DocumentPage, DocumentFeedPage, ResourcePage + # ############# /END NEW ############ urlpatterns = [ @@ -108,19 +111,37 @@ class ReportsSitemap(Sitemap): protocol = 'https' def items(self): - return DocumentPage.objects.live() + #return DocumentPage.objects.live() + #return DocumentFeedPage.objects.get_children() + + docfeeds = DocumentFeedPage.objects.live() + + reports = [] + for pg in docfeeds: + rpts = DocumentPage.objects.live().descendant_of(pg, inclusive=False) ##or child_of() + #pgs = ResourcePage.objects.descendant_of(pg, inclusive=False) ##or child_of() + reports.extend(list(rpts)) + + return reports def location(self, obj): # loc = obj.file_url.replace('https://www.fec.gov', '') if obj.file_url else obj.url_path.replace('/home', '') - loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) \ - if obj.file_url \ - else obj.url_path.replace('/home', '') + # loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) \ + # if obj.file_url \ + # else obj.url_path.replace('/home', '') # 'http://127.0.0.1:8000https://www.fec.gov/resources/cms-content/documents/2012WorkPlan.pdf' + + #if hasattr(obj, 'file_url'): + if obj.file_url: + loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) + else: + loc = obj.url_path.replace('/home', '') + return loc def lastmod(self, obj): - return obj.date + return obj.latest_revision_created_at # Not a thing def description(self, obj): From 0bb65177e3f1c80e4090a0a79a6cd29a454f11b2 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Mon, 16 Oct 2023 17:21:56 -0400 Subject: [PATCH 9/9] working prototype for reports and forms sitemaps with comments --- fec/fec/urls.py | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/fec/fec/urls.py b/fec/fec/urls.py index 3d82c0ac15..b5f964a875 100644 --- a/fec/fec/urls.py +++ b/fec/fec/urls.py @@ -14,15 +14,13 @@ from home import views as home_views from search import views as search_views -# ############# NEW ############ +# ############# NEW SITEMAP IMPORTS ############ import re -from itertools import chain from django.contrib.sitemaps import Sitemap from wagtail.documents.models import Document -from wagtail.models import Page -from home.models import DocumentPage, DocumentFeedPage, ResourcePage +from home.models import DocumentPage, DocumentFeedPage -# ############# /END NEW ############ +# ############# /END NEW SITEMAP IMPORTS ############ urlpatterns = [ re_path( @@ -64,7 +62,10 @@ ] -# ########### NEW ################ +# ########### NEW SITEMAPS ################ +# SHOULD MOVE THESE CLASSES TO A views.py FILE OR ITS OWN FILE AND IMPORT IT HERE + +# ######## FORMS SITEMAP ######### class FormsSitemap(Sitemap): changefreq = "never" @@ -75,15 +76,16 @@ def items(self): return Document.objects.filter(file__icontains="fecfrm") def location(self, obj): - # WORKS BUT: WORKS LOCALLY RESOLVING TO `MEDIA`, TEST ON DEV TO SEE IF IT RESOLVES TO `DEFAULT_FILE_STORAGE` - # UPDATE^^: RETURNS THIS ON DEV: \ - # `https://dev.fec.govhttps://fec-dev-proxy.app.cloud.gov/resources/cms-content/documents/fecfrm2sf.pdf` - # return obj.file.url # WORKS: RETURNS JUST THE FILE THEN CONCATENATES THE PATH TO IT # return '/resources/cms_content/'+str(obj.file) # return str(obj.file).replace('documents/', '/resources/cms_content/documents/') + # `obj.file.url` RETURNS THIS ON LOCAL: + # https://127.0.0.1:8000/media/documents/fecfrm13.pdf (make sure to change to http to test) + # `obj.file.url` RETURNS THIS ON DEV: + # `https://dev.fec.govhttps://fec-dev-proxy.app.cloud.gov/resources/cms-content/documents/fecfrm2sf.pdf` + # WORKS: THIS ONE REMOVES THE `https://fec-dev-proxy.app.cloud.gov` , TESTED ON DEV loc = re.sub(r'^[^:]+:\/\/[^/?#]+', '', obj.file.url) return loc @@ -102,7 +104,7 @@ def lastmod(self, obj): ), ] -# ################# +# ######## REPORT SITEMAP ######### class ReportsSitemap(Sitemap): @@ -111,31 +113,23 @@ class ReportsSitemap(Sitemap): protocol = 'https' def items(self): - #return DocumentPage.objects.live() - #return DocumentFeedPage.objects.get_children() + # could just return all DocumentPages, but instead return all DocumentPages \ + # that are descendants of DocumentFeedPages + # return DocumentPage.objects.live() docfeeds = DocumentFeedPage.objects.live() reports = [] for pg in docfeeds: - rpts = DocumentPage.objects.live().descendant_of(pg, inclusive=False) ##or child_of() - #pgs = ResourcePage.objects.descendant_of(pg, inclusive=False) ##or child_of() + rpts = DocumentPage.objects.live().descendant_of(pg, inclusive=False) # or child_of() reports.extend(list(rpts)) return reports def location(self, obj): - # loc = obj.file_url.replace('https://www.fec.gov', '') if obj.file_url else obj.url_path.replace('/home', '') - # loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) \ - # if obj.file_url \ - # else obj.url_path.replace('/home', '') - - # 'http://127.0.0.1:8000https://www.fec.gov/resources/cms-content/documents/2012WorkPlan.pdf' - - #if hasattr(obj, 'file_url'): if obj.file_url: - loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) - else: + loc = re.sub(r'https:\/\/(www|beta)\.fec\.gov', '', obj.file_url) + else: loc = obj.url_path.replace('/home', '') return loc @@ -158,7 +152,7 @@ def description(self, obj): ), ] -# ################# /END NEW ################ +# ################# /END NEW SITEMAPS ################ if settings.FEC_CMS_ENVIRONMENT != 'LOCAL':