Skip to content

Commit

Permalink
removing html in pdf (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix authored Oct 26, 2021
1 parent 4c2bc0d commit a65a5a8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions agora_results/pipes/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with agora-results. If not, see <http://www.gnu.org/licenses/>.

import os
import re
import subprocess
import json
import requests
Expand Down Expand Up @@ -60,6 +61,9 @@ def configure_pdf(
assert(isinstance(language, str))
data['pdf']['languages'] = languages

def remove_html(text):
return re.sub(r"<[^>]+>", " ", text)

def gen_text(
text,
size=None,
Expand Down Expand Up @@ -168,7 +172,7 @@ def pdf_print(election_results, config_folder, election_id):
_ = translate.gettext
try:
jsonconfig = get_election_cfg(election_id)
election_title = jsonconfig['payload']['configuration']['title']
election_title = remove_html(jsonconfig['payload']['configuration']['title'])
except:
election_title = ""

Expand Down Expand Up @@ -261,7 +265,7 @@ def get_percentage(num, base):
gen_text(
_('Question {question_index}: {question_title}').format(
question_index=i+1,
question_title=question['title']
question_title=remove_html(question['title'])
),
size=15,
bold=True,
Expand Down Expand Up @@ -535,10 +539,10 @@ def get_percentage(num, base):
]
)
for answer in winners:
answer_text = answer['text']
answer_text = remove_html(answer['text'])
if dict(title='isWriteInResult', url='true') in answer.get('urls', []):
answer_text = _('{candidate_text} (Write-in)').format(
candidate_text=answer['text']
candidate_text=answer_text
)
data.append(
[
Expand All @@ -556,10 +560,10 @@ def get_percentage(num, base):
]
)
for loser in losers:
loser_text = loser['text']
loser_text = remove_html(loser['text'])
if dict(title='isWriteInResult', url='true') in loser.get('urls', []):
loser_text = _('{candidate_text} (Write-in)').format(
candidate_text=loser['text']
candidate_text=loser_text
)
data.append(
[
Expand Down

0 comments on commit a65a5a8

Please sign in to comment.