mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 22:25:35 +00:00
Update Profile.send_report to prepare weekly totals for weekly reports
Fixes: #736
This commit is contained in:
parent
796c6b9272
commit
34bd608acd
4 changed files with 21 additions and 10 deletions
hc
templates/emails
|
@ -17,7 +17,7 @@ from django.urls import reverse
|
|||
from django.utils.timezone import now
|
||||
|
||||
from hc.lib import emails
|
||||
from hc.lib.date import month_boundaries
|
||||
from hc.lib.date import month_boundaries, week_boundaries
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from zoneinfo import ZoneInfo
|
||||
|
@ -234,9 +234,15 @@ class Profile(models.Model):
|
|||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
}
|
||||
|
||||
boundaries = month_boundaries(months=3)
|
||||
# throw away the current month, keep two previous months
|
||||
boundaries.pop()
|
||||
if self.reports == "weekly":
|
||||
boundaries = week_boundaries(weeks=3)
|
||||
else:
|
||||
boundaries = month_boundaries(months=3)
|
||||
|
||||
for check in checks:
|
||||
# Calculate the downtimes, throw away the current period,
|
||||
# keep two previous periods
|
||||
check.past_downtimes = check.downtimes_by_boundary(boundaries)[:-1]
|
||||
|
||||
ctx = {
|
||||
"checks": checks,
|
||||
|
@ -247,7 +253,7 @@ class Profile(models.Model):
|
|||
"nag": nag,
|
||||
"nag_period": self.nag_period.total_seconds(),
|
||||
"num_down": num_down,
|
||||
"month_boundaries": boundaries,
|
||||
"month_boundaries": boundaries[:-1],
|
||||
"monthly_or_weekly": self.reports,
|
||||
}
|
||||
|
||||
|
|
|
@ -497,11 +497,6 @@ class Check(models.Model):
|
|||
boundaries = month_boundaries(months=months)
|
||||
return self.downtimes_by_boundary(boundaries)
|
||||
|
||||
def past_downtimes(self):
|
||||
"""Return downtime summary for two previous months."""
|
||||
|
||||
return self.downtimes(3)[:-1]
|
||||
|
||||
def create_flip(self, new_status: str, mark_as_processed: bool = False) -> None:
|
||||
"""Create a Flip object for this check.
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import timedelta as td
|
||||
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
|
@ -242,3 +243,8 @@ def underline(s):
|
|||
@register.filter
|
||||
def first5(rid):
|
||||
return str(rid)[:5]
|
||||
|
||||
|
||||
@register.filter
|
||||
def add6days(dt):
|
||||
return dt + td(days=6)
|
||||
|
|
|
@ -9,7 +9,11 @@
|
|||
</td>
|
||||
{% for dt in month_boundaries %}
|
||||
<td style="padding: 32px 8px 8px 8px; margin: 0; font-size: 12px; color: #9BA2AB; font-family: Helvetica, Arial, sans-serif;">
|
||||
{% if monthly_or_weekly == "weekly" %}
|
||||
{{ dt|date:"M j"}} - {{ dt|add6days|date:"M j"}}
|
||||
{% else %}
|
||||
{{ dt|date:"N Y"}}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
|
Loading…
Add table
Reference in a new issue