Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed May 14, 2019
2 parents e4b6869 + cbf62fc commit 7db5378
Show file tree
Hide file tree
Showing 8 changed files with 769 additions and 27 deletions.
55 changes: 55 additions & 0 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,61 @@ def postp(r, output):
csv_stylesheet = ("auth", "consent_option.xsl"),
)

# -----------------------------------------------------------------------------
@auth.s3_requires_membership(1)
def consent_question():
"""
Controller to request consent on data processing from
the currently logged-in user
- currently only for TESTING
- to be moved into default/user/consent once completed (WIP)
- can be used as standalone controller for consent renewal after expiry
"""

person_id = auth.s3_logged_in_person()
if not person_id:
redirect(URL(c="default", f="user", args=["login"], vars={"_next": URL()}))

output = {}

widget_id = "consent_question"

consent = s3db.auth_Consent()
formfields = [Field("question",
label = T("Consent"),
widget = consent.widget,
),
]

# Generate the form and add it to the output
formstyle = settings.get_ui_formstyle()
form = SQLFORM.factory(record = None,
showid = False,
formstyle = formstyle,
table_name = "auth_consent",
#buttons = buttons,
#hidden = hidden,
_id = widget_id,
*formfields)

# Process the form
formname = "consent_question/None"
if form.accepts(request.post_vars,
current.session,
#onvalidation = self.validate,
formname = formname,
keepvalues = True,
hideerror = False,
):

consent.track(person_id, form.vars.question)

output["form"] = form
response.view = "create.html"

return output

# =============================================================================
@auth.s3_requires_membership(1)
def acl():
Expand Down
70 changes: 58 additions & 12 deletions modules/s3/codecs/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ def get_resource_flowable(self, resource, doc):
if fields:
list_fields = [f for f in fields if f != "id"]
else:
list_fields = [f.name for f in resource.readable_fields()
if f.type != "id" and
f.name != "comments" or
not self.pdf_hide_comments]
list_fields = resource.list_fields("pdf_fields", id_column=False)
if self.pdf_hide_comments:
list_fields = [f for f in list_fields if f != "comments"]

get_vars = Storage(current.request.get_vars)
get_vars["iColumns"] = len(list_fields)
Expand Down Expand Up @@ -800,8 +799,7 @@ def __init__(self,
self.row_heights = []

# -------------------------------------------------------------------------
@classmethod
def convert(cls, rfield, value):
def convert(self, rfield, value):
"""
Convert represented field value into a suitable
ReportLab element
Expand All @@ -826,13 +824,61 @@ def convert(cls, rfield, value):

elif isinstance(value, DIV):

if len(value.components) > 0:
pdf_value = cls.convert(rfield, value.components[0])
else:
pdf_value = biDiText(value)
num_components = len(value.components)

# Paragraph style
if isinstance(value, (H1, H2, H3, H4, H5, H6)):
font = self.font_name_bold
else:
font = self.font_name
stylesheet = getSampleStyleSheet()
para_style = stylesheet["Normal"]
para_style.fontName = font

if num_components == 1:
# Simple tag => convert to string
pdf_value = self.convert(rfield, value.components[0])

# Wrap in paragraph if string contains newlines or component is
# a block-element, preserving newlines and setting font weight
if isinstance(pdf_value, basestring) and \
isinstance(value, (H1, H2, H3, H4, H5, H6, P, DIV)) or "\n" in pdf_value:
pdf_value = Paragraph(pdf_value.replace("\n", "<br/>"), para_style)

elif num_components > 0:
# Complex tag => convert to list of paragraphs
# @todo: support bulleted lists and tables in represents
pdf_value = []

def add_paragraph(text):
# Wrap text in Paragraph to preserve newlines and set font weight
para = Paragraph(biDiText(text).replace("\n", "<br/>"), para_style)
pdf_value.append(para)

text = ""
for component in value.components:
if isinstance(component, basestring):
# Concatenate consecutive strings
text = "".join((text, component))
else:
# Convert component
sub = self.convert(rfield, component)
if isinstance(sub, basestring):
text = "".join((text, sub))
continue
elif text:
add_paragraph(text)
text = ""
if isinstance(sub, list):
pdf_value.extend(sub)
else:
pdf_value.append(sub)
if text:
add_paragraph(text)
else:
# Empty tag => empty string
pdf_value = ""
else:

pdf_value = biDiText(value)

return pdf_value
Expand Down Expand Up @@ -1011,7 +1057,7 @@ def calc(self, data, style):
else:
temp_row = []
for col_index, item in enumerate(row):
if col_index in para_cols:
if col_index in para_cols and isinstance(item, basestring):
col_widths[col_index] = min_width
para = main_doc.addParagraph(item,
style=para_style,
Expand Down
1 change: 0 additions & 1 deletion modules/s3/s3crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,6 @@ def select(self, r, **attr):
exporter = S3Exporter().pdf
return exporter(resource,
request = r,
list_fields = list_fields,
report_hide_comments = report_hide_comments,
report_filename = report_filename,
report_formname = report_formname,
Expand Down
Loading

0 comments on commit 7db5378

Please sign in to comment.