Fix bulletin timezones

This commit is contained in:
Yingtong Li 2019-07-22 09:33:20 +10:00
parent 0d44b8ec78
commit 487c2f3650
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 10 additions and 10 deletions

View File

@ -56,9 +56,9 @@ def by_email(email):
member.member_type = 1 # Ordinary Member member.member_type = 1 # Ordinary Member
# Calculate expiration date # Calculate expiration date
member.expires = timezone.now().date().replace(month=3, day=31) member.expires = timezone.localtime(timezone.now()).date().replace(month=3, day=31)
member.expires = member.expires.replace(year=member.expires.year+1) member.expires = member.expires.replace(year=member.expires.year+1)
if member.expires < timezone.now().date(): # Add 1 year if after Mar 31, else add 2 years if member.expires < timezone.localtime(timezone.now()).date(): # Add 1 year if after Mar 31, else add 2 years
member.expires = member.expires.replace(year=member.expires.year+1) member.expires = member.expires.replace(year=member.expires.year+1)
return member return member

View File

@ -182,9 +182,9 @@ def signup_save(request):
member.member_type = 2 # Associate Member member.member_type = 2 # Associate Member
# Calculate expiration date # Calculate expiration date
member.expires = timezone.now().date().replace(month=3, day=20) member.expires = timezone.localtime(timezone.now()).date().replace(month=3, day=20)
member.expires = member.expires.replace(year=member.expires.year+1) member.expires = member.expires.replace(year=member.expires.year+1)
if member.expires < timezone.now().date(): # Add 1 year if after Mar 20, else add 2 years if member.expires < timezone.localtime(timezone.now()).date(): # Add 1 year if after Mar 20, else add 2 years
member.expires = member.expires.replace(year=member.expires.year+1) member.expires = member.expires.replace(year=member.expires.year+1)
errors = member.validation_problems() errors = member.validation_problems()

View File

@ -91,9 +91,9 @@ class Command(BaseCommand):
client = boto3.client('ses', aws_access_key_id=settings.AWS_KEY_ID, aws_secret_access_key=settings.AWS_SECRET, region_name=settings.AWS_REGION) client = boto3.client('ses', aws_access_key_id=settings.AWS_KEY_ID, aws_secret_access_key=settings.AWS_SECRET, region_name=settings.AWS_REGION)
title = '{} News: {}'.format(settings.ORG_NAME, timezone.now().strftime('%d %B %Y')) title = '{} News: {}'.format(settings.ORG_NAME, timezone.localtime(timezone.now()).strftime('%d %B %Y'))
calbegin, calend, bulbegin, bulend = sspromotions.utils.bulletin_dates(timezone.now()) calbegin, calend, bulbegin, bulend = sspromotions.utils.bulletin_dates(timezone.localtime(timezone.now()))
events = list(sspromotions.utils.get_calendar_events(calbegin, calend)) events = list(sspromotions.utils.get_calendar_events(calbegin, calend))
for member in members: for member in members:

View File

@ -39,7 +39,7 @@ def bulletin_list(request):
items_upcoming = [] items_upcoming = []
items_future = [] items_future = []
dtbegin = timezone.now().date() dtbegin = timezone.localtime(timezone.now()).date()
dtend = dtbegin + datetime.timedelta(days=7) dtend = dtbegin + datetime.timedelta(days=7)
for item in models.BulletinItem.objects.all(): for item in models.BulletinItem.objects.all():
@ -70,12 +70,12 @@ def bulletin_preview(request):
dt = datetime.datetime.strptime(request.POST['date'], '%Y-%m-%d') dt = datetime.datetime.strptime(request.POST['date'], '%Y-%m-%d')
else: else:
groups = models.Group.objects.all() groups = models.Group.objects.all()
dt = timezone.now() - datetime.timedelta(days=6) dt = timezone.localtime(timezone.now()) - datetime.timedelta(days=6)
calbegin, calend, bulbegin, bulend = utils.bulletin_dates(dt) calbegin, calend, bulbegin, bulend = utils.bulletin_dates(dt)
return render(request, 'sspromotions/email/bulletin.html', utils.bulletin_args(None, groups, utils.get_calendar_events(calbegin, calend), bulbegin, bulend)) return render(request, 'sspromotions/email/bulletin.html', utils.bulletin_args(None, groups, utils.get_calendar_events(calbegin, calend), bulbegin, bulend))
else: else:
date = timezone.now().date() date = timezone.localtime(timezone.now()).date()
date += datetime.timedelta(days=(6 - date.weekday() + 7) % 7) # Next Sunday (6 = Sunday) date += datetime.timedelta(days=(6 - date.weekday() + 7) % 7) # Next Sunday (6 = Sunday)
return render(request, 'sspromotions/bulletin_preview.html', {'date': date, 'groups': models.Group.objects.filter(hidden=False).all()}) return render(request, 'sspromotions/bulletin_preview.html', {'date': date, 'groups': models.Group.objects.filter(hidden=False).all()})
@ -101,7 +101,7 @@ def bulletin_new(request):
else: else:
item = models.BulletinItem() item = models.BulletinItem()
item.author = request.user item.author = request.user
item.date = timezone.now().date() item.date = timezone.localtime(timezone.now()).date()
item.date += datetime.timedelta(days=(6 - item.date.weekday() + 7) % 7) # Next Sunday (6 = Sunday) item.date += datetime.timedelta(days=(6 - item.date.weekday() + 7) % 7) # Next Sunday (6 = Sunday)
return render(request, 'sspromotions/bulletin_edit.html', { return render(request, 'sspromotions/bulletin_edit.html', {
'item': item, 'item': item,