mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Remove PY_TIMEZONE references (#547)
This changeset removes the PY_TIMEZONE configuration variable and updates all references to it to refer directly to pytz.utc instead. It also cleans up a few of the import statements and removes those that are no longer needed (like the current_app reference from Flask). Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
@@ -4,7 +4,7 @@ from itertools import chain
|
||||
from numbers import Number
|
||||
|
||||
import pytz
|
||||
from flask import Markup, current_app, render_template, request
|
||||
from flask import Markup, render_template, request
|
||||
from flask_login import current_user
|
||||
from flask_wtf import FlaskForm as Form
|
||||
from flask_wtf.file import FileAllowed
|
||||
@@ -74,8 +74,8 @@ def get_time_value_and_label(future_time):
|
||||
return (
|
||||
future_time.astimezone(pytz.utc).replace(tzinfo=None).isoformat(),
|
||||
'{} at {} UTC'.format(
|
||||
get_human_day(future_time.astimezone(current_app.config['PY_TIMEZONE'])),
|
||||
get_human_time(future_time.astimezone(current_app.config['PY_TIMEZONE']))
|
||||
get_human_day(future_time.astimezone(pytz.utc)),
|
||||
get_human_time(future_time.astimezone(pytz.utc))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -93,20 +93,20 @@ def get_human_time(time):
|
||||
def get_human_day(time, prefix_today_with='T'):
|
||||
# Add 1 hour to get ‘midnight today’ instead of ‘midnight tomorrow’
|
||||
time = (time - timedelta(hours=1)).strftime('%A')
|
||||
if time == datetime.now(current_app.config['PY_TIMEZONE']).strftime('%A'):
|
||||
if time == datetime.now(pytz.utc).strftime('%A'):
|
||||
return '{}oday'.format(prefix_today_with)
|
||||
if time == (datetime.now(current_app.config['PY_TIMEZONE']) + timedelta(days=1)).strftime('%A'):
|
||||
if time == (datetime.now(pytz.utc) + timedelta(days=1)).strftime('%A'):
|
||||
return 'Tomorrow'
|
||||
return time
|
||||
|
||||
|
||||
def get_furthest_possible_scheduled_time():
|
||||
# We want local time to find date boundaries
|
||||
return (datetime.now(current_app.config['PY_TIMEZONE']) + timedelta(days=4)).replace(hour=0)
|
||||
return (datetime.now(pytz.utc) + timedelta(days=4)).replace(hour=0)
|
||||
|
||||
|
||||
def get_next_hours_until(until):
|
||||
now = datetime.now(current_app.config['PY_TIMEZONE'])
|
||||
now = datetime.now(pytz.utc)
|
||||
hours = int((until - now).total_seconds() / (60 * 60))
|
||||
return [
|
||||
(now + timedelta(hours=i)).replace(minute=0, second=0, microsecond=0)
|
||||
@@ -115,7 +115,7 @@ def get_next_hours_until(until):
|
||||
|
||||
|
||||
def get_next_days_until(until):
|
||||
now = datetime.now(current_app.config['PY_TIMEZONE'])
|
||||
now = datetime.now(pytz.utc)
|
||||
days = int((until - now).total_seconds() / (60 * 60 * 24))
|
||||
return [
|
||||
get_human_day(
|
||||
|
||||
@@ -3,7 +3,8 @@ from itertools import groupby
|
||||
from operator import itemgetter
|
||||
from statistics import mean
|
||||
|
||||
from flask import current_app, render_template
|
||||
import pytz
|
||||
from flask import render_template
|
||||
|
||||
from app import performance_dashboard_api_client, status_api_client
|
||||
from app.main import main
|
||||
@@ -12,8 +13,8 @@ from app.main import main
|
||||
@main.route("/performance")
|
||||
def performance():
|
||||
stats = performance_dashboard_api_client.get_performance_dashboard_stats(
|
||||
start_date=(datetime.now(current_app.config['PY_TIMEZONE']) - timedelta(days=7)).date(),
|
||||
end_date=datetime.now(current_app.config['PY_TIMEZONE']).date(),
|
||||
start_date=(datetime.now(pytz.utc) - timedelta(days=7)).date(),
|
||||
end_date=datetime.now(pytz.utc).date(),
|
||||
)
|
||||
stats['organisations_using_notify'] = sorted(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user