Program to generate responses to right of access requests
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

89 lines
3.3 KiB

# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of right-of-access.
#
# right-of-access is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# right-of-access is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with right-of-access. If not, see <http://www.gnu.org/licenses/>.
import time
import yaml
import json
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib.colors import Color, HexColor
# Load config file
with open("config.yaml", "r") as file:
config = yaml.load(file, yaml.FullLoader)
sender = config["sender"]
doc = SimpleDocTemplate("right_of_access.pdf",pagesize=letter,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
Story=[]
# Add SRA logo to page
logo = "res/img/logo.png"
im = Image(logo, 2*inch, 2*inch)
Story.append(im)
# Add timestamp to page
styles=getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
styles.add(ParagraphStyle(name='Heading', fontSize=14, textColor=HexColor("#980000")))
styles.add(ParagraphStyle(name='Subheading', fontSize=12, textColor=HexColor("#980000")))
ptext = time.ctime()
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
# Generate Introduction
text = [
"Comrade,",
"Below is a copy of your personal information as retained by the Socialist Rifle Association in response to your Right to Access request as well as information about the data collected and what we use it for.",
f"This information is also included in the machine-readable JSON format. If you feel any of this information is incorrect, you can manage your membership info at https://www.joinit.org/o/socialist-rifle-association/ or contact {sender['email_address']}. "
]
for item in text:
Story.append(Paragraph(item, styles["Normal"]))
Story.append(Spacer(1, 12))
def add_section(section_name: str, section_value: str):
Story.append(Paragraph(f"{section_name}", styles["Subheading"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(section_value, styles["Normal"]))
Story.append(Spacer(1, 12))
with open("data.json", "r") as file:
data = json.load(file)["[email protected]"]
for i in data:
# Convert data to string
if type(data[i]) == str:
add_section(i, data[i])
else:
try:
add_section(i, str(data[i]))
except:
add_section(i, "No Data")
# Create contact info
ptext = 'Sincerely,'
Story.append(Paragraph(ptext, styles["Normal"]))
for key in sender:
value = sender[key]
ptext = '%s' % value.strip()
Story.append(Paragraph(ptext, styles["Normal"]))
doc.build(Story)