Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions fec/fec/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'))
Expand Down
5 changes: 3 additions & 2 deletions fec/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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([
Expand Down
34 changes: 31 additions & 3 deletions fec/home/templates/home/document_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@
{% load static %}
{% block body_class %}template-{{ self.get_verbose_name | slugify }}{% endblock %}



{% block content %}

<!--{% if "reports-about-fec" in request.path and page.content_type.model == "documentpage" and self.file_url %}
<meta http-equiv="refresh" content="0; url={% include_block self.file_url %}">
{% endif %} -->




{% include 'partials/breadcrumbs.html' with page=self links=self.get_ancestors style='secondary' %}

<article class="main">
<div class="container">
<header class="heading--main heading--with-date">
<ul class="tags">
<li class="tag tag--secondary t-upper">
{{ self.category }}
<a href="{{self.get_parent.url}}?category={{ self.category | cms_query_syntax }}">{{ self.category }}</a>
</li>
</ul>
<div class="row">
{% spaceless %}{# for inline blocks #}
<h1 class="heading__left">{% formatted_title self %}</h1>
<h1 class="heading__left">{% if self.file_url %}<a href="{{ self.file_url }}">{% formatted_title self %}</a>
{% else %}
{% formatted_title self %}
{% endif %}</h1>
<div class="heading__right">
<span class="t-sans">{{ self.display_date }}</span>
<span class="t-sans">{{ self.display_date }} |
{% if self.file_url %} <a href="{{ self.file_url }}">{{ self.extension }}</a>
{% else %}
{{ self.extension }}
{% endif %}
{% if self.size %} | ({{ self.size }}){% endif %}</span>

</div>
{% endspaceless %}
</div>
Expand All @@ -31,5 +49,15 @@ <h1 class="heading__left">{% formatted_title self %}</h1>
</article>

{% include 'partials/disclaimer.html' %}
<script>
// document.getElementsByClassName('main')[0].insertAdjacentHTML("beforebegin", "<p>You will be directed</p>")
// setTimeout(() => {
// var meta = document.createElement('meta');
// meta.httpEquiv = "refresh" ;
// meta.content = "3; url={% include_block self.file_url %}";
// document.getElementsByTagName('head')[0].appendChild(meta);
// }, "0");

</script>

{% endblock %}
2 changes: 1 addition & 1 deletion fec/home/templates/partials/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ <h3>
</h3>
{% endif %}
<div class="post__meta">
<a class="tag tag--secondary" href="">{{ document.category }}</a>
<a class="tag tag--secondary" href="{{self.get_parent.url}}?category={{ document.category | cms_query_syntax }}">{{ document.category }}</a>
</div>
</article>
7 changes: 7 additions & 0 deletions fec/home/templatetags/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]'),
)
Expand Down