Commit 10389e8da7bcfabf75560b7f54aa1b9c410bc0c6

Authored by hitier
1 parent 3d797ac4
Exists in rhitier-dev

Fix start_stop() when both given

Showing 1 changed file with 14 additions and 8 deletions   Show diff stats
web/run.py
... ... @@ -1082,26 +1082,32 @@ def get_input_slug_from_query(inp=None):
1082 1082 return input_slug
1083 1083  
1084 1084  
1085   -def get_default_sta_sto(sta=None, sto=None):
  1085 +def get_default_sta_sto(sta_str=None, sto_str=None):
1086 1086  
1087   - # TODO : maybe get from configuration
1088 1087 relative_after = config['defaults']['relative_after']
1089 1088 relative_before = config['defaults']['relative_before']
1090 1089 before = relativedelta(months=relative_before)
1091 1090 after = relativedelta(months=relative_after)
1092 1091  
1093   - if sta is None and sto is None:
  1092 + if sta_str is None and sto_str is None:
1094 1093 today = datetime.datetime.now().replace(hour=0, minute=0, second=0)
1095 1094 sta_date = today - before
1096 1095 sto_date = today + after
1097 1096  
1098   - if sta is None and sto is not None:
1099   - sto_date = dateparser.isoparse(sto)
  1097 + elif sta_str is not None and sto_str is None:
  1098 + sta_date = dateparser.isoparse(sta_str)
  1099 + sto_date = sta_date + after
  1100 +
  1101 + elif sta_str is None and sto_str is not None:
  1102 + sto_date = dateparser.isoparse(sto_str)
1100 1103 sta_date = sto_date - before
1101 1104  
1102   - if sta is not None and sto is None:
1103   - sta_date = dateparser.isoparse(sta)
1104   - sto_date = sta_date + after
  1105 + elif sta_str is not None and sto_str is not None:
  1106 + sto_date = dateparser.isoparse(sto_str)
  1107 + sta_date = dateparser.isoparse(sta_str)
  1108 +
  1109 + else:
  1110 + raise Exception("IMPOSSIBLE")
1105 1111  
1106 1112 return sta_date, sto_date
1107 1113  
... ...