mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 22:25:35 +00:00
Fix templates to use user's timezone when displaying dates
This commit is contained in:
parent
818ccad56f
commit
260f6e36a7
5 changed files with 34 additions and 7 deletions
hc
templates
|
@ -255,6 +255,7 @@ class Profile(models.Model):
|
|||
"num_down": num_down,
|
||||
"month_boundaries": boundaries[:-1],
|
||||
"monthly_or_weekly": self.reports,
|
||||
"tz": self.tz,
|
||||
}
|
||||
|
||||
emails.report(self.user.email, ctx, headers)
|
||||
|
|
|
@ -106,7 +106,7 @@ class SendReportsTestCase(BaseTestCase):
|
|||
self.assertIn("Dec 30 - Jan 5", html)
|
||||
self.assertIn("Jan 6 - Jan 12", html)
|
||||
|
||||
def test_it_obeys_profiles_timezone(self):
|
||||
def test_it_handles_positive_utc_offset(self):
|
||||
self.profile.reports = "weekly"
|
||||
self.profile.tz = "America/New_York"
|
||||
self.profile.save()
|
||||
|
@ -117,12 +117,31 @@ class SendReportsTestCase(BaseTestCase):
|
|||
|
||||
email = mail.outbox[0]
|
||||
html = email.alternatives[0][0]
|
||||
# In UTC the current time is Monday, Jan 13, 2AM.
|
||||
# But in New York it is still Sunday, Jan 12, 9PM.
|
||||
# UTC: Monday, Jan 13, 2AM.
|
||||
# New York: Sunday, Jan 12, 9PM.
|
||||
# The report should not contain the Jan 6 - Jan 12 week, because
|
||||
# in New York it is the current week.
|
||||
self.assertIn("Dec 23 - Dec 29", html)
|
||||
self.assertIn("Dec 30 - Jan 5", html)
|
||||
self.assertNotIn("Jan 6 - Jan 12", html)
|
||||
|
||||
def test_it_handles_negative_utc_offset(self):
|
||||
self.profile.reports = "weekly"
|
||||
self.profile.tz = "Asia/Tokyo"
|
||||
self.profile.save()
|
||||
|
||||
cmd = Command(stdout=Mock())
|
||||
cmd.pause = Mock() # don't pause for 1s
|
||||
cmd.handle_one_report()
|
||||
|
||||
email = mail.outbox[0]
|
||||
html = email.alternatives[0][0]
|
||||
# UTC: Monday, Jan 13, 2AM.
|
||||
# Tokyo: Monday, Jan 13, 11AM
|
||||
self.assertNotIn("Dec 23 - Dec 29", html)
|
||||
self.assertIn("Dec 30 - Jan 5", html)
|
||||
self.assertIn("Jan 6 - Jan 12", html)
|
||||
|
||||
def test_it_obeys_next_report_date(self):
|
||||
self.profile.next_report_date = CURRENT_TIME + td(days=1)
|
||||
self.profile.save()
|
||||
|
|
|
@ -826,6 +826,7 @@ def details(request, code):
|
|||
"enabled_channels": list(check.channel_set.all()),
|
||||
"timezones": all_timezones,
|
||||
"downtimes": check.downtimes(3, request.profile.tz),
|
||||
"tz": request.profile.tz,
|
||||
"is_copied": "copied" in request.GET,
|
||||
"all_tags": " ".join(sorted(all_tags)),
|
||||
}
|
||||
|
@ -923,7 +924,9 @@ def status_single(request, code):
|
|||
if updated != request.GET.get("u"):
|
||||
doc["events"] = EVENTS_TMPL.render({"check": check, "events": events})
|
||||
downtimes = check.downtimes(3, request.profile.tz)
|
||||
doc["downtimes"] = DOWNTIMES_TMPL.render({"downtimes": downtimes})
|
||||
doc["downtimes"] = DOWNTIMES_TMPL.render(
|
||||
{"downtimes": downtimes, "tz": request.profile.tz}
|
||||
)
|
||||
|
||||
return JsonResponse(doc)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load humanize hc_extras %}
|
||||
{% load humanize hc_extras tz %}
|
||||
{% regroup checks by project as groups %}
|
||||
{% timezone tz %}
|
||||
{% spaceless %}
|
||||
<table style="margin: 0; width: 100%; font-size: 16px;" cellpadding="0" cellspacing="0">
|
||||
{% for group in groups %}
|
||||
|
@ -86,3 +87,4 @@
|
|||
</table>
|
||||
<br />
|
||||
{% endspaceless %}
|
||||
{% endtimezone %}
|
|
@ -1,4 +1,5 @@
|
|||
{% load hc_extras %}
|
||||
{% load hc_extras tz %}
|
||||
{% timezone tz %}
|
||||
<table id="downtimes" class="table">
|
||||
{% for boundary, down_duration_secs, count in downtimes reversed %}
|
||||
<tr>
|
||||
|
@ -15,4 +16,5 @@
|
|||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</table>
|
||||
{% endtimezone %}
|
Loading…
Add table
Reference in a new issue