|
1 | 1 | import json
|
2 |
| -from urllib.parse import urljoin |
3 | 2 |
|
4 | 3 | from django.core.exceptions import ValidationError
|
5 | 4 | from django.http import Http404, HttpResponse, JsonResponse
|
6 | 5 | from django.shortcuts import get_object_or_404, redirect
|
7 | 6 | from django.template.defaultfilters import slugify
|
8 | 7 |
|
9 |
| -from wagtail.models import Site |
10 | 8 | from wagtailsharing.models import SharingSite
|
11 | 9 | from wagtailsharing.views import ServeView
|
12 | 10 |
|
13 |
| -from bs4 import BeautifulSoup as bs |
14 |
| - |
15 | 11 | from ask_cfpb.forms import AutocompleteForm, SearchForm, legacy_facet_validator
|
16 | 12 | from ask_cfpb.models import AnswerPage, AnswerPageSearch, AnswerResultsPage
|
17 | 13 |
|
18 | 14 |
|
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 |
| - |
48 | 15 | def view_answer(request, slug, language, answer_id):
|
49 | 16 | answer_page = get_object_or_404(
|
50 | 17 | AnswerPage, language=language, answer_base__id=answer_id
|
|
0 commit comments