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' %}
@@ -13,14 +22,23 @@
{% spaceless %}{# for inline blocks #} -

{% formatted_title self %}

+

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

- {{ self.display_date }} + {{ self.display_date }} | + {% if self.file_url %} {{ self.extension }} + {% else %} + {{ self.extension }} + {% endif %} + {% if self.size %} | ({{ self.size }}){% endif %} +
{% endspaceless %}
@@ -31,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 %}
- {{ document.category }} + {{ document.category }}
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 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]'), )