Promene u dizajnu dokumenata, controla, residual graph, residual tabele...

This commit is contained in:
2025-06-13 17:45:22 +02:00
parent fa734e5be9
commit aff66589e9
14 changed files with 711 additions and 2132 deletions

View File

@@ -18,6 +18,50 @@ def render_universal_segment(segment, context_data):
rendered = []
context = Context(context_data)
if segment_type == 'organization':
rendered.append(
f'<div class="front-page">'
f'<img src="path/to/your/logo.png" alt="Risklet Logo" class="logo">'
f'<h1>Cyber Risk Assessment Report</h1>'
f'<p>Comprehensive Evaluation and Strategic Recommendations for Enhanced Cybersecurity Posture</p>'
f'<div class="prepared-by">'
f'<p>Prepared for</p>')
for item in content:
name = Template(item.get('name', '')).render(context)
date = Template(item.get('date', '')).render(context)
if name:
rendered.append(f'<p><strong>{name}</strong></p>')
rendered.append(f'<p>Prepared by</p>'
f'<p><strong>Risklet</strong></p>'
f'</div>')
if date:
rendered.append(f'<p style="margin-top: 40px;">{date}</p>')
rendered.append(f'</div>')
return '\n'.join(rendered)
elif segment_type == 'disclaimer':
rendered.append(
f'<div class="disclaimer-page">'
f'<img src="path/to/your/logo.png" alt="Risklet Logo" class="logo">'
)
for item in content:
subtitle = Template(item.get('subtitle', '')).render(context)
description = Template(item.get('description', '')).render(context)
if subtitle:
rendered.append(f'<h3>{subtitle}</h3>')
if description:
processed_desc = []
for line in description.split('\n'):
line = line.strip()
if line:
processed_desc.append(f'<p>{line}</p>')
rendered.append('\n'.join(processed_desc))
rendered.append(f'</div>')
return '\n'.join(rendered)
else:
rendered.append(f'<div class="section">')
for item in content:
if not isinstance(item, dict):
continue
@@ -27,10 +71,10 @@ def render_universal_segment(segment, context_data):
description = Template(item.get('description', '')).render(context)
if title:
rendered.append(f'<h2 style="color: #2c3e50; margin-top: 30px;">{title}</h2>')
rendered.append(f'<h2>{title}</h2>')
if subtitle:
rendered.append(f'<h3 style="color: #34495e; margin-top: 20px;">{subtitle}</h3>')
rendered.append(f'<h3>{subtitle}</h3>')
if description:
processed_desc = []
@@ -47,7 +91,7 @@ def render_universal_segment(segment, context_data):
processed_desc.append('</ul>')
in_list = False
if line:
processed_desc.append(f'<p style="margin: 10px 0; line-height: 1.6;">{line}</p>')
processed_desc.append(f'<p>{line}</p>')
if in_list:
processed_desc.append('</ul>')
rendered.append('\n'.join(processed_desc))
@@ -68,20 +112,53 @@ def render_universal_segment(segment, context_data):
table_html.append('</tbody></table>')
rendered.append('\n'.join(table_html))
if 'html' in item:
html_template = Template(item['html'])
rendered_html = html_template.render(context)
rendered.append(rendered_html)
if 'image' in item:
image_url = Template(item['image']).render(context)
rendered.append(f'<img src="{image_url}" alt="{title}" style="max-width: 100%; height: auto; margin: 20px 0;">')
if 'warning' in item:
warning_text = Template(item['warning']).render(context)
rendered.append(f'<p style="color: #e74c3c; font-weight: bold;">{warning_text}</p>')
if 'note' in item:
note_text = Template(item['note']).render(context)
rendered.append(f'<p><em>{note_text}</p></em>')
if 'html' in segment:
html_template = Template(segment['html'])
rendered_html = html_template.render(context)
rendered.append(rendered_html)
rendered.append('</div>')
return '\n'.join(rendered)
def render_template(template_segments, context_data):
final_output = []
container_segments = []
disclaimer_segment = None
for segment in template_segments:
segment_html = render_universal_segment(segment, context_data)
final_output.append(f'<div class="segment {segment.get("segment_type", "")}">{segment_html}</div>')
segment_type = segment.get('segment_type', 'unknown')
if segment_type == 'organization':
final_output.append(render_universal_segment(segment, context_data))
elif segment_type == 'disclaimer':
disclaimer_segment = segment
else:
container_segments.append(segment)
if container_segments:
container_html = ['<div class="container">']
for segment in container_segments:
container_html.append(render_universal_segment(segment, context_data))
container_html.append('</div>')
final_output.append('\n'.join(container_html))
if disclaimer_segment:
final_output.append(render_universal_segment(disclaimer_segment, context_data))
return '\n'.join(final_output)