Skip to content
Merged
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
5 changes: 5 additions & 0 deletions templates/visualizer/confirmDeleteUpload.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ <h1 class="page-section-heading text-center">Delete this visualization?</h1>
Note: this visualization is updated automatically from an official data source. Deleting it will stop those updates.
</p>
{% endif %}
{% if isOnElectionPage %}
<p class="text-center">
Note: this visualization appears on an election results page. Deleting it will remove it from that page.
</p>
{% endif %}

<form method="post" class="text-center">
{% csrf_token %}
Expand Down
3 changes: 3 additions & 0 deletions visualizer/tests/testUserDashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ def test_delete(self):
self.assertEqual(response.url, reverse('userDashboard'))
self.assertFalse(JsonConfig.objects.filter(pk=config.pk).exists())
mockCloudflare.purge_vis_cache.assert_called_once_with(config.slug)
# The homepage recent list and the sitemap linked to it, too
mockCloudflare.purge_paths_cache.assert_called_once_with(
['/', '/index.html', '/sitemap.xml'])
10 changes: 10 additions & 0 deletions visualizer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from accounts.permissions import IsOwnerOrReadOnly, HasAPIAccess
from common import viewUtils
from common.cloudflare import CloudflareAPI
from electionpage.models import ElectionPage
from scraper.models import Scraper, MultiScraper
from visualizer import validators
from visualizer.common import make_complete_url, intify
Expand Down Expand Up @@ -215,14 +216,23 @@ def get_context_data(self, **kwargs):
jsonConfig=self.object).exists()
context['hasScraper'] = Scraper.objects.filter(jsonConfig=self.object).exists() or \
MultiScraper.objects.filter(jsonConfig=self.object).exists()
context['isOnElectionPage'] = ElectionPage.objects.filter(
listOfElections=self.object).exists()
return context

def form_valid(self, form):
# Cloudflare purging only happens in JsonConfig.save() - on deletion,
# we must purge here to avoid serving cached copies of a deleted page
slug = self.object.slug
electionPagePaths = [
reverse('electionPage', args=(page.slug,))
for page in ElectionPage.objects.filter(listOfElections=self.object)]
response = super().form_valid(form)
CloudflareAPI.purge_vis_cache(slug)
# The homepage's recent list, the sitemap, and any election pages that
# included this visualization would otherwise keep linking to it
CloudflareAPI.purge_paths_cache(
['/', '/index.html', '/sitemap.xml'] + electionPagePaths)
return response


Expand Down
Loading