From 92243965ec7f982e8c6e1809bc4436d1eb88a0d2 Mon Sep 17 00:00:00 2001
From: leigh-mil
Date: Wed, 25 Sep 2019 16:30:53 -0400
Subject: [PATCH] parse contract dates into datetime objects
---
atst/app.py | 7 +++++++
atst/forms/task_order.py | 9 ++-------
js/components/pop_date_range.js | 2 +-
templates/components/clin_fields.html | 2 --
templates/components/pop_date_range.html | 6 +++---
tests/forms/test_task_order.py | 8 ++------
6 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/atst/app.py b/atst/app.py
index 6a23abfe..f3e7276f 100644
--- a/atst/app.py
+++ b/atst/app.py
@@ -2,6 +2,7 @@ import os
import re
import pathlib
from configparser import ConfigParser
+from datetime import datetime
from flask import Flask, request, g, session
from flask_session import Session
import redis
@@ -175,6 +176,12 @@ def map_config(config):
# with a Beat job once a day)
"CELERY_RESULT_EXPIRES": 0,
"CELERY_RESULT_EXTENDED": True,
+ "CONTRACT_START_DATE": datetime.strptime(
+ config.get("default", "CONTRACT_START_DATE"), "%Y-%m-%d"
+ ).date(),
+ "CONTRACT_END_DATE": datetime.strptime(
+ config.get("default", "CONTRACT_END_DATE"), "%Y-%m-%d"
+ ).date(),
}
diff --git a/atst/forms/task_order.py b/atst/forms/task_order.py
index ddf029f8..fe764f27 100644
--- a/atst/forms/task_order.py
+++ b/atst/forms/task_order.py
@@ -9,7 +9,6 @@ from wtforms.fields import (
from wtforms.fields.html5 import DateField
from wtforms.validators import Required, Optional, Length, NumberRange, ValidationError
from flask_wtf import FlaskForm
-from datetime import datetime
from numbers import Number
from .data import JEDI_CLIN_TYPES
@@ -85,12 +84,8 @@ class CLINForm(FlaskForm):
def validate(self, *args, **kwargs):
valid = super().validate(*args, **kwargs)
- contract_start = datetime.strptime(
- app.config.get("CONTRACT_START_DATE"), "%Y-%m-%d"
- ).date()
- contract_end = datetime.strptime(
- app.config.get("CONTRACT_END_DATE"), "%Y-%m-%d"
- ).date()
+ contract_start = app.config.get("CONTRACT_START_DATE")
+ contract_end = app.config.get("CONTRACT_END_DATE")
if (
self.start_date.data
diff --git a/js/components/pop_date_range.js b/js/components/pop_date_range.js
index 52446593..7abac268 100644
--- a/js/components/pop_date_range.js
+++ b/js/components/pop_date_range.js
@@ -46,7 +46,7 @@ export default {
this.minEndDate = this.calcMinEndDate(date)
}
} else if (event.name.includes(END_DATE)) {
- if (event.valid != undefined && event.valid ) {
+ if (event.valid != undefined && event.valid) {
var date = new Date(event.value)
this.maxStartDate = this.calcMaxStartDate(date)
}
diff --git a/templates/components/clin_fields.html b/templates/components/clin_fields.html
index 6c91d7fe..2baf6419 100644
--- a/templates/components/clin_fields.html
+++ b/templates/components/clin_fields.html
@@ -128,8 +128,6 @@
{{ 'task_orders.form.pop' | translate }}
- {% set contract_start_formatted = contract_start | dateFromString(formatter="%Y-%m-%d") %}
- {% set contract_end_formatted = contract_end | dateFromString(formatter="%Y-%m-%d") %}
{% if fields %}
{{ PopDateRange(start_field=fields.start_date, end_field=fields.end_date, watch=True, optional=False, mindate=contract_start, maxdate=contract_end) }}
{% else %}
diff --git a/templates/components/pop_date_range.html b/templates/components/pop_date_range.html
index b4f6e540..bde27736 100644
--- a/templates/components/pop_date_range.html
+++ b/templates/components/pop_date_range.html
@@ -48,7 +48,7 @@
- PoP start date must be on or after {{ mindate | dateFromString(formatter="%Y-%m-%d") | formattedDate(formatter="%B %d, %Y") }}.
+ PoP start date must be on or after {{ mindate | formattedDate(formatter="%B %d, %Y") }}.
- PoP end date must be on or after {{ maxdate | dateFromString(formatter="%Y-%m-%d") | formattedDate(formatter="%B %d, %Y") }}.
+ PoP end date must be on or after {{ formatted_end_date }}.
diff --git a/tests/forms/test_task_order.py b/tests/forms/test_task_order.py
index 9fb12bcf..85a7c6af 100644
--- a/tests/forms/test_task_order.py
+++ b/tests/forms/test_task_order.py
@@ -38,12 +38,8 @@ def test_clin_form_start_date_before_end_date():
def test_clin_form_pop_dates_within_contract_dates():
- CONTRACT_START_DATE = datetime.datetime.strptime(
- app.config.get("CONTRACT_START_DATE"), "%Y-%m-%d"
- ).date()
- CONTRACT_END_DATE = datetime.datetime.strptime(
- app.config.get("CONTRACT_END_DATE"), "%Y-%m-%d"
- ).date()
+ CONTRACT_START_DATE = app.config.get("CONTRACT_START_DATE")
+ CONTRACT_END_DATE = app.config.get("CONTRACT_END_DATE")
invalid_start = CONTRACT_START_DATE - relativedelta(months=1)
invalid_end = CONTRACT_END_DATE + relativedelta(months=1)