Skip to content

Commit 1832b7e

Browse files
authored
Merge pull request #8039 from cfpb/deprecate/ask-annotate-links
Remove unused ask_cfpb.views.annotate_links
2 parents e95c8db + a3668eb commit 1832b7e

File tree

2 files changed

+0
-61
lines changed

2 files changed

+0
-61
lines changed

cfgov/ask_cfpb/tests/test_views.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
AnswerLandingPage,
1717
AnswerPage,
1818
)
19-
from ask_cfpb.views import annotate_links
2019

2120

2221
now = timezone.now()
@@ -156,30 +155,3 @@ def test_answer_page_not_live_on_sharing_site(self, mock_serve):
156155
def test_redirect_view_with_no_recognized_facet(self):
157156
response = self.client.get("/askcfpb/search/?selected_facets=hoodoo")
158157
self.assertEqual(response.status_code, 404)
159-
160-
161-
class AnswerViewTestCase(TestCase):
162-
def test_annotate_links(self):
163-
mock_answer = (
164-
'<p>Answer with a <a href="http://fake.com">fake link.</a></p>'
165-
)
166-
(annotated_answer, links) = annotate_links(mock_answer)
167-
self.assertEqual(
168-
annotated_answer,
169-
'<html><body><p>Answer with a <a href="http://fake.com">fake '
170-
"link.</a><sup>1</sup></p></body></html>",
171-
)
172-
self.assertEqual(links, [(1, str("http://fake.com"))])
173-
174-
def test_annotate_links_no_href(self):
175-
mock_answer = "<p>Answer with a <a>fake link.</a></p>"
176-
(annotated_answer, links) = annotate_links(mock_answer)
177-
self.assertEqual(links, [])
178-
179-
def test_annotate_links_no_site(self):
180-
site = Site.objects.get(is_default_site=True)
181-
site.is_default_site = False
182-
site.save()
183-
with self.assertRaises(RuntimeError) as context:
184-
annotate_links("answer")
185-
self.assertIn("no default wagtail site", str(context.exception))

cfgov/ask_cfpb/views.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,17 @@
11
import json
2-
from urllib.parse import urljoin
32

43
from django.core.exceptions import ValidationError
54
from django.http import Http404, HttpResponse, JsonResponse
65
from django.shortcuts import get_object_or_404, redirect
76
from django.template.defaultfilters import slugify
87

9-
from wagtail.models import Site
108
from wagtailsharing.models import SharingSite
119
from wagtailsharing.views import ServeView
1210

13-
from bs4 import BeautifulSoup as bs
14-
1511
from ask_cfpb.forms import AutocompleteForm, SearchForm, legacy_facet_validator
1612
from ask_cfpb.models import AnswerPage, AnswerPageSearch, AnswerResultsPage
1713

1814

19-
def annotate_links(answer_text):
20-
"""
21-
Parse and annotate links from answer text.
22-
23-
Return the annotated answer
24-
and an enumerated list of links as footnotes.
25-
"""
26-
try:
27-
_site = Site.objects.get(is_default_site=True)
28-
except Site.DoesNotExist as err:
29-
raise RuntimeError("no default wagtail site configured") from err
30-
31-
footnotes = []
32-
soup = bs(answer_text, "lxml")
33-
links = soup.findAll("a")
34-
index = 1
35-
for link in links:
36-
if not link.get("href"):
37-
continue
38-
footnotes.append((index, urljoin(_site.root_url, link.get("href"))))
39-
parent = link.parent
40-
link_location = parent.index(link)
41-
super_tag = soup.new_tag("sup")
42-
super_tag.string = str(index)
43-
parent.insert(link_location + 1, super_tag)
44-
index += 1
45-
return (str(soup), footnotes)
46-
47-
4815
def view_answer(request, slug, language, answer_id):
4916
answer_page = get_object_or_404(
5017
AnswerPage, language=language, answer_base__id=answer_id

0 commit comments

Comments
 (0)