fix: more timezone fixes

This commit is contained in:
Jennifer Richards 2022-09-23 17:12:06 -03:00
parent 981f22a5ee
commit 2eb5723574
No known key found for this signature in database
GPG key ID: 26801E4DC0928410
9 changed files with 32 additions and 19 deletions

View file

@ -17,13 +17,14 @@ from ietf.doc.models import Document, LastCallDocEvent, ConsensusDocEvent
from ietf.doc.utils_search import fill_in_telechat_date
from ietf.iesg.models import TelechatDate, TelechatAgendaItem
from ietf.review.utils import review_assignments_to_list_for_docs
from ietf.utils.timezone import date_today
def get_agenda_date(date=None):
if not date:
try:
return TelechatDate.objects.active().order_by('date')[0].date
except IndexError:
return datetime.date.today()
return date_today()
else:
try:
return TelechatDate.objects.active().get(date=datetime.datetime.strptime(date, "%Y-%m-%d").date()).date

View file

@ -2,12 +2,13 @@
# -*- coding: utf-8 -*-
import datetime
from django.conf import settings
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from ietf.doc.models import Document, TelechatDocEvent
from ietf.utils.timezone import date_today
class IESGAgendaFeed(Feed):
title = "Documents on Future IESG Telechat Agendas"
@ -16,7 +17,7 @@ class IESGAgendaFeed(Feed):
description_template = "iesg/feed_item_description.html"
def items(self):
docs = Document.objects.filter(docevent__telechatdocevent__telechat_date__gte=datetime.date.today()).distinct()
docs = Document.objects.filter(docevent__telechatdocevent__telechat_date__gte=date_today(settings.TIME_ZONE)).distinct()
for d in docs:
d.latest_telechat_event = d.latest_event(TelechatDocEvent, type="scheduled_for_telechat")
docs = [d for d in docs if d.latest_telechat_event.telechat_date]

View file

@ -36,8 +36,12 @@
import datetime
from django.conf import settings
from django.db import models
from ietf.utils.timezone import date_today
class TelechatAgendaItem(models.Model):
TYPE_CHOICES = (
(1, "Any Other Business (WG News, New Proposals, etc.)"),
@ -72,11 +76,11 @@ def next_telechat_date():
dates = TelechatDate.objects.order_by("-date")
if dates:
return dates[0].date + datetime.timedelta(days=14)
return datetime.date.today()
return date_today(settings.TIME_ZONE)
class TelechatDateManager(models.Manager):
def active(self):
return self.get_queryset().filter(date__gte=datetime.date.today())
return self.get_queryset().filter(date__gte=date_today(settings.TIME_ZONE))
class TelechatDate(models.Model):
objects = TelechatDateManager()

View file

@ -28,6 +28,7 @@ from ietf.name.models import StreamName
from ietf.person.models import Person
from ietf.utils.test_utils import TestCase, login_testing_unauthorized, unicontent
from ietf.iesg.factories import IESGMgmtItemFactory
from ietf.utils.timezone import date_today, DEADLINE_TZINFO
class IESGTests(TestCase):
@ -58,7 +59,7 @@ class IESGTests(TestCase):
m = GroupMilestone.objects.create(group=draft.group,
state_id="review",
desc="Test milestone",
due=datetime.date.today())
due=date_today(DEADLINE_TZINFO))
url = urlreverse("ietf.iesg.views.milestones_needing_review")
login_testing_unauthorized(self, "ad", url)
@ -142,7 +143,7 @@ class IESGAgendaTests(TestCase):
mgmtitem = self.mgmt_items
# put on agenda
date = datetime.date.today() + datetime.timedelta(days=50)
date = date_today(settings.TIME_ZONE) + datetime.timedelta(days=50)
TelechatDate.objects.create(date=date)
telechat_event = TelechatDocEvent.objects.create(
type="scheduled_for_telechat",
@ -430,7 +431,7 @@ class IESGAgendaTests(TestCase):
self.assertNotIn(d.title, unicontent(r))
# Add the documents to a past telechat
by = Person.objects.get(name="Areað Irector")
date = datetime.date.today() - datetime.timedelta(days=14)
date = date_today(settings.TIME_ZONE) - datetime.timedelta(days=14)
approved = State.objects.get(type='draft-iesg', slug='approved')
iesg_eval = State.objects.get(type='draft-iesg', slug='iesg-eva')
for d in list(self.telechat_docs.values()):
@ -485,7 +486,7 @@ class IESGAgendaTests(TestCase):
def test_admin_change(self):
draft = Document.objects.get(name="draft-ietf-mars-test")
today = datetime.date.today()
today = date_today(settings.TIME_ZONE)
telechat_date = TelechatDate.objects.get(date=draft.telechat_date())
url = urlreverse('admin:iesg_telechatdate_change', args=(telechat_date.id,))
self.client.login(username="secretary", password="secretary+password")

View file

@ -46,6 +46,8 @@ from ietf.stats.models import MeetingRegistration
from ietf.utils.decorators import skip_coverage
from ietf.utils.mail import outbox, empty_outbox, get_payload_text
from ietf.utils.test_utils import TestCase, login_testing_unauthorized
from ietf.utils.timezone import date_today
import ietf.ietfauth.views
@ -506,7 +508,7 @@ class IetfAuthTests(TestCase):
UnavailablePeriod.objects.create(
team=review_req.team,
person=reviewer,
start_date=datetime.date.today() - datetime.timedelta(days=10),
start_date=date_today() - datetime.timedelta(days=10),
availability="unavailable",
)
@ -789,7 +791,7 @@ class IetfAuthTests(TestCase):
for i in range(count):
for key in person.apikeys.all():
self.client.post(key.endpoint, {'apikey':key.hash(), 'dummy': 'dummy', })
date = str(datetime.date.today())
date = str(date_today())
empty_outbox()
cmd = Command()
@ -906,7 +908,7 @@ class OpenIDConnectTests(TestCase):
# an additional email
EmailFactory(person=person)
email_list = person.email_set.all().values_list('address', flat=True)
meeting = MeetingFactory(type_id='ietf', date=datetime.date.today())
meeting = MeetingFactory(type_id='ietf', date=date_today())
MeetingRegistration.objects.create(
meeting=meeting, person=None, first_name=person.first_name(), last_name=person.last_name(),
email=email_list[0], ticket_type='full_week', reg_type='remote', affiliation='Some Company',

View file

@ -18,6 +18,7 @@ from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.utils.decorators import available_attrs
from django.utils.http import urlquote
@ -282,8 +283,7 @@ class OidcExtraScopeClaims(oidc_provider.lib.claims.ScopeClaims):
info = {}
if regs:
# maybe register attendance if logged in to follow a meeting
today = datetime.date.today()
if meeting.date <= today <= meeting.end_date():
if meeting.start_datetime() <= timezone.now() <= meeting.end_datetime():
client = ClientRecord.objects.get(client_id=self.client.client_id)
if client.name == 'Meetecho':
for reg in regs:

View file

@ -28,6 +28,7 @@ from ietf.message.models import Message
from ietf.utils.mail import outbox, empty_outbox, get_payload_text
from ietf.utils.test_utils import TestCase, login_testing_unauthorized
from ietf.utils.text import text_to_dict
from ietf.utils.timezone import date_today
def make_data_from_content(content):
@ -573,7 +574,7 @@ I would like to revoke this declaration.
self.assertEqual(r.status_code,302)
self.assertEqual(len(outbox),len_before+2)
self.assertTrue('george@acme.com' in outbox[len_before]['To'])
self.assertIn('posted on '+datetime.date.today().strftime("%Y-%m-%d"), get_payload_text(outbox[len_before]).replace('\n',' '))
self.assertIn('posted on '+date_today().strftime("%Y-%m-%d"), get_payload_text(outbox[len_before]).replace('\n',' '))
self.assertTrue('draft-ietf-mars-test@ietf.org' in outbox[len_before+1]['To'])
self.assertTrue('mars-wg@ietf.org' in outbox[len_before+1]['Cc'])
self.assertIn('Secretariat on '+ipr.get_latest_event_submitted().time.strftime("%Y-%m-%d"), get_payload_text(outbox[len_before+1]).replace('\n',' '))
@ -601,7 +602,7 @@ I would like to revoke this declaration.
ipr = HolderIprDisclosureFactory()
url = urlreverse('ietf.ipr.views.email',kwargs={ "id": ipr.id })
self.client.login(username="secretary", password="secretary+password")
yesterday = datetime.date.today() - datetime.timedelta(1)
yesterday = date_today() - datetime.timedelta(1)
data = dict(
to='joe@test.com',
frm='ietf-ipr@ietf.org',

View file

@ -10,6 +10,8 @@ from django.template.loader import render_to_string
from ietf.utils.mail import send_mail_text
from ietf.group.models import Role
from ietf.mailtrigger.utils import gather_address_lists
from ietf.utils.timezone import date_today, DEADLINE_TZINFO
def send_liaison_by_email(request, liaison):
subject = 'New Liaison Statement, "%s"' % (liaison.title)
@ -61,7 +63,7 @@ def possibly_send_deadline_reminder(liaison):
0: 'today'
}
days_to_go = (liaison.deadline - datetime.date.today()).days
days_to_go = (liaison.deadline - date_today(DEADLINE_TZINFO)).days
if not (days_to_go < 0 or days_to_go in list(PREVIOUS_DAYS.keys())):
return None # no reminder

View file

@ -8,13 +8,14 @@ from django.core.management.base import BaseCommand
from ietf.liaisons.models import LiaisonStatement
from ietf.liaisons.mails import possibly_send_deadline_reminder
from ietf.utils.timezone import date_today, DEADLINE_TZINFO
class Command(BaseCommand):
help = ("Check liaison deadlines and send a reminder if we are close to a deadline")
def handle(self, *args, **options):
today = datetime.date.today()
today = date_today(DEADLINE_TZINFO)
cutoff = today - datetime.timedelta(14)
msgs = []