mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Add a component for picking the time to send a job
Users need to pick a time in the next 24hrs, or send a file immediately. Rationale for this is a bit lost in time-before-holiday, but generally: ‘Now’ and ‘later’ as the inital choices makes it really clear what this feature is about conceptually. The choice of times is absolute, eg ‘1pm’ not ‘in 3 hours’
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import pytz
|
||||
from flask_wtf import Form
|
||||
from datetime import datetime, timedelta
|
||||
from notifications_utils.recipients import (
|
||||
validate_phone_number,
|
||||
InvalidPhoneError
|
||||
@@ -22,6 +24,30 @@ from app.main.validators import (Blacklist, CsvFileValidator, ValidEmailDomainRe
|
||||
from app.notify_client.api_key_api_client import KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM
|
||||
|
||||
|
||||
def get_time_value_and_label(future_time):
|
||||
return (
|
||||
future_time.replace(tzinfo=None).isoformat(),
|
||||
get_human_time(future_time.astimezone(pytz.timezone('Europe/London')))
|
||||
)
|
||||
|
||||
|
||||
def get_human_time(time):
|
||||
return {
|
||||
'0': 'Midnight',
|
||||
'12': 'Midday'
|
||||
}.get(
|
||||
time.strftime('%-H'),
|
||||
time.strftime('%-I%p').lower()
|
||||
)
|
||||
|
||||
|
||||
def get_next_hours_from(now, hours=23):
|
||||
return [
|
||||
(now + timedelta(hours=i)).replace(minute=0, second=0).replace(tzinfo=pytz.utc)
|
||||
for i in range(1, hours + 1)
|
||||
]
|
||||
|
||||
|
||||
def email_address(label='Email address'):
|
||||
return EmailField(label, validators=[
|
||||
Length(min=5, max=255),
|
||||
@@ -288,6 +314,23 @@ class ConfirmMobileNumberForm(Form):
|
||||
raise ValidationError(msg)
|
||||
|
||||
|
||||
class ChooseTimeForm(Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ChooseTimeForm, self).__init__(*args, **kwargs)
|
||||
self.scheduled_for.choices = [('', 'Now')] + [
|
||||
get_time_value_and_label(hour) for hour in get_next_hours_from(datetime.utcnow())
|
||||
]
|
||||
|
||||
scheduled_for = RadioField(
|
||||
'When should Notify send these messages?',
|
||||
default='',
|
||||
validators=[
|
||||
DataRequired()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class CreateKeyForm(Form):
|
||||
def __init__(self, existing_key_names=[], *args, **kwargs):
|
||||
self.existing_key_names = [x.lower() for x in existing_key_names]
|
||||
|
||||
@@ -31,7 +31,7 @@ def cookies():
|
||||
|
||||
@main.route('/trial-mode')
|
||||
def trial_mode():
|
||||
return render_template('views/trial-mode.html')
|
||||
return render_template('views/trial-mode.html', hours=hours)
|
||||
|
||||
|
||||
@main.route('/pricing')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import itertools
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from string import ascii_uppercase
|
||||
|
||||
from contextlib import suppress
|
||||
@@ -23,7 +23,7 @@ from notifications_utils.template import Template
|
||||
from notifications_utils.recipients import RecipientCSV, first_column_heading, validate_and_format_phone_number
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import CsvUploadForm
|
||||
from app.main.forms import CsvUploadForm, ChooseTimeForm
|
||||
from app.main.uploader import (
|
||||
s3upload,
|
||||
s3download
|
||||
@@ -276,6 +276,7 @@ def check_messages(service_id, template_type, upload_id):
|
||||
upload_id=upload_id,
|
||||
form=CsvUploadForm(),
|
||||
remaining_messages=remaining_messages,
|
||||
choose_time_form=ChooseTimeForm(),
|
||||
back_link=back_link,
|
||||
help=get_help_argument()
|
||||
)
|
||||
@@ -310,7 +311,8 @@ def start_job(service_id, upload_id):
|
||||
service_id,
|
||||
upload_data.get('template_id'),
|
||||
upload_data.get('original_file_name'),
|
||||
upload_data.get('notification_count')
|
||||
upload_data.get('notification_count'),
|
||||
scheduled_for=request.form.get('scheduled_for', '')
|
||||
)
|
||||
|
||||
return redirect(
|
||||
|
||||
Reference in New Issue
Block a user