More changes to responsive tables and make top liks depend on email or web

This commit is contained in:
Brian Read 2024-06-07 10:35:28 +01:00
parent 52c1bfba48
commit 389175c392
3 changed files with 33 additions and 23 deletions

View File

@ -8,6 +8,7 @@ $event = 'smeserver-mailstats-update';
foreach my $file (qw(
/etc/systemd/system-preset/49-koozali.preset
/etc/e-smith/sql/init/99smeserver-mailstats.sql
/etc/httpd/conf/httpd.conf
))
{
templates2events( $file, $event );
@ -18,7 +19,7 @@ event_link('systemd-reload', $event, '50');
#action specific to this package
#event_link('action', $event, '30');
#services we need to restart
#safe_symlink('restart', 'root/etc/e-smith/events/$event/services2adjust/<service>)
safe_symlink('restart', "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith");
#and Server Mmanager panel link
#panel_link('somefunction', 'manager');

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<!-- 1. Take out style for table for email
2. Switch "see in Browser" to "index" in web version
>
-->
<html><head>
<meta charset="utf-8">
<title>SMEServer Mailstats</title>
@ -39,28 +39,27 @@
</style>
</head>
<body>
<div style="width:100%;overflow-x:auto;font-size:1cqw">
<!---Navigation here-->
<br />
<h2>${title}</h2>
<br />
<div style="width:100%;overflow-x:auto;font-size:1.35cqw">
<table border="1">
<thead>
<tr>
<th>Date/Time</th>
<th tal:repeat="header column_headers" tal:content="header">Header</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="row array_2d">
<td tal:condition="repeat.row.index == 24" tal:content="'TOTALS'">Totals</td>
<td tal:condition="repeat.row.index == 25" tal:content="'PERCENT'">Percent</td>
<td tal:condition="repeat.row.index < 24" tal:content="string:${reporting_date}, ${repeat.row.index}">Hour</td>
<td tal:repeat="cell row" tal:content="cell">Cell</td>
</tr>
</tbody>
</table>
</div>
<table border="1">
<thead>
<tr>
<th>Date/Time</th>
<th tal:repeat="header column_headers" tal:content="header">Header</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="row array_2d">
<td tal:condition="repeat.row.index == 24" tal:content="'TOTALS'">Totals</td>
<td tal:condition="repeat.row.index == 25" tal:content="'PERCENT'">Percent</td>
<td tal:condition="repeat.row.index < 24" tal:content="string:${reporting_date}, ${repeat.row.index}">Hour</td>
<td tal:repeat="cell row" tal:content="cell">Cell</td>
</tr>
</tbody>
</table>
<!---Add in sub tables here -->
<br />
<footer>${version}</footer>
@ -78,6 +77,6 @@
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</div>
</body>
</html>

View File

@ -588,7 +588,14 @@ def send_email(subject, from_email, to_email, smtp_server, smtp_port, HTML_conte
if smtp_user and smtp_password:
server.login(smtp_user, smtp_password) # Authenticate only if credentials are provided
server.sendmail(from_email, to_email, msg.as_string())
def replace_between(text, start, end, replacement):
# Escaping start and end in case they contain special regex characters
pattern = re.escape(start) + '.*?' + re.escape(end)
# Using re.DOTALL to match any character including newline
replaced_text = re.sub(pattern, replacement, text, flags=re.DOTALL)
return replaced_text
if __name__ == "__main__":
try:
chameleon_version = pkg_resources.get_distribution("Chameleon").version
@ -897,7 +904,7 @@ if __name__ == "__main__":
previous_date_str = previous_date.strftime(day_format)
navigation_str_html = "<div class='linksattop'>\
<a class='prevlink' href='http://${DomainName}/mailstats/mailstats_for_${PreviousDate}.html'>Previous</a>\
<div class='divseeinbrowser'><a class='seeinbrowser' href='http://${DomainName}/mailstats/mailstats_for_${TodayDate}.html'>See in browser</a></div>\
<div class='divshowindex'><a class='showindex' href='http://${DomainName}/mailstats/'>Index of files</a></div>\
<a class='nextlink' href='http://${DomainName}/mailstats/mailstats_for_${NextDate}.html'>Next</a>\
</div>"
template = PageTemplate(navigation_str_html)
@ -923,6 +930,9 @@ if __name__ == "__main__":
# Send html email (default))
filepath = html_page_dir+"mailstats_for_"+formatted_yesterday+".html"
html_content = read_html_from_file(filepath)
# Replace the Navigation by a "See in browser" prompt
replace_str = f"<div class='divseeinbrowser' style='text-align:center;'><a class='seeinbrowser' href='http://{DomainName}/mailstats/mailstats_for_{formatted_yesterday}.html'>See in browser</a></div>"
html_content = replace_between(html_content, "<div class='linksattop'>", ">Next</a></div>", replace_str)
if EmailTextOrHTML == "Text" or EmailTextOrHTML == "Both":
filepath = html_page_dir+"mailstats_for_"+formatted_yesterday+".txt"
text_content = read_text_from_file(filepath)