Accordion-Logik und Panel-Index korrigiert, kombinierte Plus/Minus-Funktion, Tests aktualisiert
This commit is contained in:
82
app.py
82
app.py
@@ -41,6 +41,7 @@ def index():
|
||||
f.write(f"{dt.now().isoformat()} PAGEVIEW\n")
|
||||
tage = werktage = wochentag = datumsrechnung = werktagsrechnung = kw_berechnen = kw_datum = wochen_monate = None
|
||||
active_idx = 0
|
||||
plusminus_result = None
|
||||
if request.method == 'POST':
|
||||
action = request.form.get('action')
|
||||
# Funktions-Logging
|
||||
@@ -64,48 +65,15 @@ def index():
|
||||
except Exception:
|
||||
tage = 'Ungültige Eingabe'
|
||||
elif action == 'wochentag':
|
||||
active_idx = 2
|
||||
active_idx = 1
|
||||
datum = request.form.get('datum3')
|
||||
try:
|
||||
d = datetime.strptime(datum, '%Y-%m-%d')
|
||||
wochentag = WOCHENTAGE[d.weekday()]
|
||||
except Exception:
|
||||
wochentag = 'Ungültige Eingabe'
|
||||
elif action == 'datumsrechnung':
|
||||
active_idx = 3
|
||||
datum = request.form.get('datum4')
|
||||
tage_input = request.form.get('tage4')
|
||||
richtung = request.form.get('richtung4')
|
||||
try:
|
||||
d = datetime.strptime(datum, '%Y-%m-%d')
|
||||
tage_int = int(tage_input)
|
||||
if richtung == 'add':
|
||||
result = d + timedelta(days=tage_int)
|
||||
else:
|
||||
result = d - timedelta(days=tage_int)
|
||||
datumsrechnung = result.strftime('%d.%m.%Y')
|
||||
except Exception:
|
||||
datumsrechnung = 'Ungültige Eingabe'
|
||||
elif action == 'werktagsrechnung':
|
||||
active_idx = 4
|
||||
datum = request.form.get('datum5')
|
||||
tage_input = request.form.get('tage5')
|
||||
richtung = request.form.get('richtung5')
|
||||
try:
|
||||
d = datetime.strptime(datum, '%Y-%m-%d').date()
|
||||
tage_int = int(tage_input)
|
||||
if richtung == 'add':
|
||||
result = np.busday_offset(d, tage_int, roll='forward')
|
||||
else:
|
||||
result = np.busday_offset(d, -tage_int, roll='backward')
|
||||
werktagsrechnung = np.datetime_as_string(result, unit='D')
|
||||
# Formatierung auf deutsch
|
||||
dt = datetime.strptime(werktagsrechnung, '%Y-%m-%d')
|
||||
werktagsrechnung = dt.strftime('%d.%m.%Y')
|
||||
except Exception:
|
||||
werktagsrechnung = 'Ungültige Eingabe'
|
||||
elif action == 'kw_berechnen':
|
||||
active_idx = 5
|
||||
active_idx = 2
|
||||
datum = request.form.get('datum6')
|
||||
try:
|
||||
d = datetime.strptime(datum, '%Y-%m-%d')
|
||||
@@ -114,7 +82,7 @@ def index():
|
||||
except Exception:
|
||||
kw_berechnen = 'Ungültige Eingabe'
|
||||
elif action == 'kw_datum':
|
||||
active_idx = 6
|
||||
active_idx = 3
|
||||
jahr = request.form.get('jahr7')
|
||||
kw = request.form.get('kw7')
|
||||
try:
|
||||
@@ -126,24 +94,42 @@ def index():
|
||||
kw_datum = f"{start.strftime('%d.%m.%Y')} bis {end.strftime('%d.%m.%Y')}"
|
||||
except Exception:
|
||||
kw_datum = 'Ungültige Eingabe'
|
||||
elif action == 'wochen_monate':
|
||||
datum = request.form.get('datum8')
|
||||
anzahl = request.form.get('anzahl8')
|
||||
einheit = request.form.get('einheit8')
|
||||
richtung = request.form.get('richtung8')
|
||||
elif action == 'plusminus':
|
||||
active_idx = 4
|
||||
datum = request.form.get('datum_pm')
|
||||
anzahl = request.form.get('anzahl_pm')
|
||||
einheit = request.form.get('einheit_pm')
|
||||
richtung = request.form.get('richtung_pm')
|
||||
is_werktage = request.form.get('werktage_pm') in ('on', 'true', '1', True)
|
||||
try:
|
||||
d = datetime.strptime(datum, '%Y-%m-%d')
|
||||
anzahl_int = int(anzahl)
|
||||
if richtung == 'sub':
|
||||
anzahl_int = -anzahl_int
|
||||
if einheit == 'wochen':
|
||||
result = d + timedelta(weeks=anzahl_int)
|
||||
else:
|
||||
result = d + relativedelta(months=anzahl_int)
|
||||
wochen_monate = result.strftime('%d.%m.%Y')
|
||||
if einheit == 'tage':
|
||||
if is_werktage:
|
||||
# Werktage: numpy busday_offset
|
||||
result = np.busday_offset(d.date(), anzahl_int, roll='forward')
|
||||
result_dt = datetime.strptime(str(result), '%Y-%m-%d')
|
||||
plusminus_result = f"Datum {d.strftime('%d.%m.%Y')} {'plus' if anzahl_int>=0 else 'minus'} {abs(anzahl_int)} Werktage: {result_dt.strftime('%d.%m.%Y')}"
|
||||
else:
|
||||
result = d + timedelta(days=anzahl_int)
|
||||
plusminus_result = f"Datum {d.strftime('%d.%m.%Y')} {'plus' if anzahl_int>=0 else 'minus'} {abs(anzahl_int)} Tage: {result.strftime('%d.%m.%Y')}"
|
||||
elif einheit == 'wochen':
|
||||
if is_werktage:
|
||||
plusminus_result = 'Nicht unterstützt: Werktage + Wochen.'
|
||||
else:
|
||||
result = d + timedelta(weeks=anzahl_int)
|
||||
plusminus_result = f"Datum {d.strftime('%d.%m.%Y')} {'plus' if anzahl_int>=0 else 'minus'} {abs(anzahl_int)} Wochen: {result.strftime('%d.%m.%Y')}"
|
||||
elif einheit == 'monate':
|
||||
if is_werktage:
|
||||
plusminus_result = 'Nicht unterstützt: Werktage + Monate.'
|
||||
else:
|
||||
result = d + relativedelta(months=anzahl_int)
|
||||
plusminus_result = f"Datum {d.strftime('%d.%m.%Y')} {'plus' if anzahl_int>=0 else 'minus'} {abs(anzahl_int)} Monate: {result.strftime('%d.%m.%Y')}"
|
||||
except Exception:
|
||||
wochen_monate = 'Ungültige Eingabe'
|
||||
return render_template('index.html', tage=tage, werktage=werktage, wochentag=wochentag, datumsrechnung=datumsrechnung, werktagsrechnung=werktagsrechnung, kw_berechnen=kw_berechnen, kw_datum=kw_datum, active_idx=active_idx, wochen_monate=wochen_monate)
|
||||
plusminus_result = 'Ungültige Eingabe'
|
||||
return render_template('index.html', tage=tage, werktage=werktage, wochentag=wochentag, plusminus_result=plusminus_result, kw_berechnen=kw_berechnen, kw_datum=kw_datum, active_idx=active_idx)
|
||||
|
||||
|
||||
@app.route('/stats', methods=['GET', 'POST'])
|
||||
|
Reference in New Issue
Block a user