-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_manager.py
More file actions
358 lines (330 loc) · 13 KB
/
template_manager.py
File metadata and controls
358 lines (330 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import os
from typing import List, Dict
import streamlit as st
class TemplateManager:
def __init__(self):
self.templates_dir = "templates"
self.ensure_templates_dir()
self.default_templates = {
"BOV Standard Template": self._get_bov_standard_template(),
"BOV Detailed Template": self._get_bov_detailed_template(),
"BOV Summary Template": self._get_bov_summary_template()
}
def ensure_templates_dir(self):
"""Ensure templates directory exists"""
if not os.path.exists(self.templates_dir):
os.makedirs(self.templates_dir)
def get_available_templates(self) -> List[str]:
"""Get list of available template names"""
templates = list(self.default_templates.keys())
# Add custom templates from files
if os.path.exists(self.templates_dir):
for filename in os.listdir(self.templates_dir):
if filename.endswith('.html'):
template_name = filename.replace('.html', '').replace('_', ' ').title()
if template_name not in templates:
templates.append(template_name)
return templates
def load_template(self, template_name: str) -> str:
"""Load template content by name"""
# Check if it's a default template
if template_name in self.default_templates:
return self.default_templates[template_name]
# Check for custom template file
filename = template_name.lower().replace(' ', '_') + '.html'
template_path = os.path.join(self.templates_dir, filename)
if os.path.exists(template_path):
with open(template_path, 'r', encoding='utf-8') as f:
return f.read()
# Fallback to standard template
return self.default_templates["BOV Standard Template"]
def _get_bov_standard_template(self) -> str:
"""Standard BOV template"""
return """
<!DOCTYPE html>
<html>
<head>
<title>Bank Operations Verification Report</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.6;
}
.header {
text-align: center;
border-bottom: 2px solid #333;
padding-bottom: 20px;
margin-bottom: 30px;
}
.section {
margin-bottom: 25px;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
.data-table th, .data-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.data-table th {
background-color: #f2f2f2;
font-weight: bold;
}
.footer {
margin-top: 40px;
text-align: center;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="header">
<h1>Bank Operations Verification Report</h1>
<p>Generated on: {{generation_date}}</p>
</div>
<div class="section">
<h2>Report Summary</h2>
<p>Total Records: {{total_records}}</p>
<p>Data Columns: {{total_columns}}</p>
<p>Template Used: BOV Standard Template</p>
</div>
<div class="section">
<h2>Data Details</h2>
{{data_table}}
</div>
<div class="footer">
<p>This report was automatically generated by the PDF Export System.</p>
<p>For questions or issues, please contact the system administrator.</p>
</div>
</body>
</html>
"""
def _get_bov_detailed_template(self) -> str:
"""Detailed BOV template with additional sections"""
return """
<!DOCTYPE html>
<html>
<head>
<title>Detailed Bank Operations Verification Report</title>
<style>
body {
font-family: 'Times New Roman', serif;
margin: 30px;
line-height: 1.8;
color: #333;
}
.header {
text-align: center;
border: 3px solid #000;
padding: 25px;
margin-bottom: 40px;
background-color: #f8f9fa;
}
.section {
margin-bottom: 35px;
padding: 15px;
border-left: 4px solid #007bff;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 12px;
}
.data-table th, .data-table td {
border: 1px solid #333;
padding: 10px;
text-align: center;
}
.data-table th {
background-color: #343a40;
color: white;
font-weight: bold;
}
.data-table tr:nth-child(even) {
background-color: #f8f9fa;
}
.summary-box {
background-color: #e9ecef;
padding: 20px;
border-radius: 5px;
margin: 20px 0;
}
.footer {
margin-top: 50px;
text-align: center;
font-size: 11px;
color: #666;
border-top: 1px solid #ddd;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="header">
<h1>Detailed Bank Operations Verification Report</h1>
<h3>Comprehensive Data Analysis</h3>
<p>Generated on: {{generation_date}}</p>
<p>Report ID: {{report_id}}</p>
</div>
<div class="section">
<h2>Executive Summary</h2>
<div class="summary-box">
<p><strong>Total Records Processed:</strong> {{total_records}}</p>
<p><strong>Data Columns Analyzed:</strong> {{total_columns}}</p>
<p><strong>Template Version:</strong> BOV Detailed Template v2.1</p>
<p><strong>Processing Status:</strong> Complete</p>
</div>
</div>
<div class="section">
<h2>Data Quality Assessment</h2>
<p>This section provides insights into the quality and completeness of the processed data.</p>
{{data_quality_info}}
</div>
<div class="section">
<h2>Detailed Data Listing</h2>
<p>Complete record-by-record breakdown of all processed data.</p>
{{data_table}}
</div>
<div class="section">
<h2>Verification Notes</h2>
<p>All data has been processed according to standard BOV procedures and guidelines.</p>
<p>Data integrity checks have been performed and any anomalies are noted in the respective sections.</p>
</div>
<div class="footer">
<p>This detailed report was automatically generated by the Advanced PDF Export System.</p>
<p>Report generated by: System Administrator | Version: 1.0</p>
<p>For technical support or questions, please contact the IT department.</p>
</div>
</body>
</html>
"""
def _get_bov_summary_template(self) -> str:
"""Summary BOV template for quick overview"""
return """
<!DOCTYPE html>
<html>
<head>
<title>BOV Summary Report</title>
<style>
body {
font-family: Calibri, sans-serif;
margin: 20px;
line-height: 1.5;
font-size: 14px;
}
.header {
text-align: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 30px;
}
.section {
margin-bottom: 20px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 8px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-card {
background: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
text-align: center;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
background: white;
border-radius: 8px;
overflow: hidden;
}
.data-table th, .data-table td {
border: 1px solid #dee2e6;
padding: 12px;
text-align: left;
}
.data-table th {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
font-weight: bold;
}
.data-table tr:hover {
background-color: #f1f3f4;
}
.footer {
margin-top: 30px;
text-align: center;
font-size: 12px;
color: #6c757d;
padding: 15px;
background-color: #f8f9fa;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="header">
<h1>BOV Summary Report</h1>
<p>Quick Overview & Key Metrics</p>
<p>{{generation_date}}</p>
</div>
<div class="section">
<h2>Key Statistics</h2>
<div class="stats-grid">
<div class="stat-card">
<h3>{{total_records}}</h3>
<p>Total Records</p>
</div>
<div class="stat-card">
<h3>{{total_columns}}</h3>
<p>Data Fields</p>
</div>
<div class="stat-card">
<h3>100%</h3>
<p>Processing Success</p>
</div>
</div>
</div>
<div class="section">
<h2>Data Overview</h2>
{{data_table}}
</div>
<div class="footer">
<p>📄 BOV Summary Report | Generated by PDF Export System</p>
<p>This is an automated summary - for detailed analysis, generate a detailed report</p>
</div>
</body>
</html>
"""
def save_custom_template(self, template_name: str, template_content: str) -> bool:
"""Save a custom template to file"""
try:
filename = template_name.lower().replace(' ', '_') + '.html'
template_path = os.path.join(self.templates_dir, filename)
with open(template_path, 'w', encoding='utf-8') as f:
f.write(template_content)
return True
except Exception as e:
st.error(f"Error saving template: {str(e)}")
return False
def get_template_variables(self, template_content: str) -> List[str]:
"""Extract template variables from template content"""
import re
# Find all variables in {{variable}} format
variables = re.findall(r'\{\{(\w+)\}\}', template_content)
return list(set(variables)) # Remove duplicates