diff --git a/fec/fec/urls.py b/fec/fec/urls.py
index 89c254e1ae..b5f964a875 100644
--- a/fec/fec/urls.py
+++ b/fec/fec/urls.py
@@ -14,6 +14,13 @@
from home import views as home_views
from search import views as search_views
+# ############# NEW SITEMAP IMPORTS ############
+import re
+from django.contrib.sitemaps import Sitemap
+from wagtail.documents.models import Document
+from home.models import DocumentPage, DocumentFeedPage
+
+# ############# /END NEW SITEMAP IMPORTS ############
urlpatterns = [
re_path(
@@ -55,6 +62,99 @@
]
+# ########### 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"
+ priority = 0.5
+ protocol = 'https'
+
+ def items(self):
+ return Document.objects.filter(file__icontains="fecfrm")
+
+ def location(self, obj):
+
+ # 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
+
+ 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",
+ ),
+]
+
+# ######## REPORT SITEMAP #########
+
+
+class ReportsSitemap(Sitemap):
+ changefreq = "never"
+ priority = 0.5
+ protocol = 'https'
+
+ def items(self):
+ # 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()
+ reports.extend(list(rpts))
+
+ return reports
+
+ def location(self, obj):
+ 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.latest_revision_created_at
+
+ # 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 SITEMAPS ################
+
+
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'))
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 4bee83d23e..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' %}
{% formatted_title self %}
+ {% if self.file_url %}{% formatted_title self %}
+ {% else %}
+ {% formatted_title self %}
+ {% endif %}
{% formatted_title self %}