Split calendar view into months
There is one overview page with one entry per month (currently the longest thread, could also be an abbreviated list of threads, but not all of the threads (or we are back where we started).The entries link to the monthly pages which contain links to all threads with at least one mail in that month.
This commit is contained in:
parent
10ce9fad8b
commit
15c70e6836
57
mbox2web
57
mbox2web
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from collections import defaultdict
|
||||
import datetime
|
||||
import email.header
|
||||
import email.parser
|
||||
|
@ -1144,6 +1145,31 @@ class Thread:
|
|||
def subject(self):
|
||||
return list(self.messages.values())[0].subject
|
||||
|
||||
def index(self, message):
|
||||
for i, m in enumerate(sorted(self.messages.values(), key=lambda x: x.date)):
|
||||
if m == message:
|
||||
return i
|
||||
|
||||
class Month:
|
||||
def __init__(self, year, month):
|
||||
self.year = year
|
||||
self.month = month
|
||||
self.threads = defaultdict(int)
|
||||
|
||||
def add(self, thread):
|
||||
self.threads[thread] += 1
|
||||
|
||||
@property
|
||||
def longest_thread(self):
|
||||
thread = None
|
||||
maxcount = 0
|
||||
for t, c in self.threads.items():
|
||||
if c > maxcount:
|
||||
maxcount = c
|
||||
thread = t
|
||||
print("longest_thread: found thread", thread)
|
||||
return thread
|
||||
|
||||
|
||||
class Archive:
|
||||
def __init__(self):
|
||||
|
@ -1215,16 +1241,19 @@ class Archive:
|
|||
|
||||
|
||||
def webify_calendar(self):
|
||||
caltmpl = jenv.get_template("calendar.html")
|
||||
|
||||
ovrtmpl = jenv.get_template("overview.html")
|
||||
bmotmpl = jenv.get_template("by_month.html")
|
||||
cal = {}
|
||||
for t in self.thread_list:
|
||||
y = t.date.year
|
||||
m = t.date.month
|
||||
if y not in cal:
|
||||
cal[y] = {}
|
||||
if m not in cal[y]:
|
||||
cal[y][m] = []
|
||||
cal[y][m].append(t)
|
||||
for m in t.messages.values():
|
||||
y = m.date.year
|
||||
m = m.date.month
|
||||
if y not in cal:
|
||||
cal[y] = {}
|
||||
if m not in cal[y]:
|
||||
cal[y][m] = Month(y, m)
|
||||
cal[y][m].add(t)
|
||||
caldir = basedir + "/cal"
|
||||
os.makedirs(caldir, exist_ok=True)
|
||||
with open(caldir + "/index.html", "w") as hfd:
|
||||
|
@ -1232,8 +1261,18 @@ class Archive:
|
|||
"list": "LUGA",
|
||||
"cal": cal,
|
||||
}
|
||||
calhtml = caltmpl.render(context)
|
||||
calhtml = ovrtmpl.render(context)
|
||||
hfd.write(calhtml)
|
||||
for y in cal.keys():
|
||||
for m in cal[y].keys():
|
||||
monthdir = f"{caldir}/{y}/{m}"
|
||||
os.makedirs(monthdir, exist_ok=True)
|
||||
with open(monthdir + "/index.html", "w") as hfd:
|
||||
context = {
|
||||
"month": cal[y][m]
|
||||
}
|
||||
monthhtml = bmotmpl.render(context)
|
||||
hfd.write(monthhtml)
|
||||
|
||||
|
||||
def self_check(self):
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>
|
||||
{{list}}: {{month.year}}-{{month.month}}
|
||||
</title>
|
||||
<link rel="stylesheet" href="../../../style/luga.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1> Mailinglist {{list}} {{month.year}}-{{month.month}}</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="../">nach Datum</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
<article>
|
||||
<ul>
|
||||
{% for t in month.threads %}
|
||||
<li>
|
||||
<a href="../../../thread/{{t.threadid}}/">{{t.subject}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</article>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>
|
||||
{{list}}: Overview
|
||||
</title>
|
||||
<link rel="stylesheet" href="../../style/luga.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Mailinglist {{list}} nach Datum</h1>
|
||||
</header>
|
||||
<nav>
|
||||
Hier sollte wohl ein Link zu einer Liste aller Listen
|
||||
hinkommen
|
||||
</nav>
|
||||
<article>
|
||||
{% for y in cal | dictsort(reverse=True) %}
|
||||
<h2>{{y.0}}</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th class="month">Monat</th>
|
||||
<th>Längster Thread</th>
|
||||
</tr>
|
||||
{% for m in y.1 | dictsort(reverse=True) %}
|
||||
<tr>
|
||||
<th class="month"><a href="{{y.0}}/{{m.0}}/">{{m.0}}</a></th>
|
||||
<td>{{m.1.longest_thread.subject}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endfor %}
|
||||
</article>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue