Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing html in pdf #68

Merged
merged 1 commit into from
Oct 26, 2021
Merged
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
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