[Plugin] schedule: Use utils to parse datetime

This commit is contained in:
Ferdinand Thiessen 2020-11-02 13:45:10 +01:00
parent 4da4c1ee01
commit ac1189ecaa
1 changed files with 5 additions and 6 deletions

View File

@ -6,15 +6,14 @@ from datetime import datetime, timedelta, timezone
from http.client import NO_CONTENT, CREATED
from flask import Blueprint, request, jsonify
from werkzeug.exceptions import BadRequest, NotFound
from backports.datetime_fromisoformat import MonkeyPatch
from flaschengeist.plugins import Plugin
from flaschengeist.decorator import login_required
from flaschengeist.utils.datetime import from_iso_format
from . import event_controller, permissions
from . import models
MonkeyPatch.patch_fromisoformat()
schedule_bp = Blueprint("schedule", __name__, url_prefix="/schedule")
@ -214,8 +213,8 @@ def get_events(current_session, year=datetime.now().year, month=datetime.now().m
def _event_slot_from_data(data):
try:
start = datetime.fromisoformat(data["start"]).replace(tzinfo=timezone.utc)
end = datetime.fromisoformat(data["end"]).replace(tzinfo=timezone.utc) if "end" in data else None
start = from_iso_format(data["start"])
end = from_iso_format(data["end"]) if "end" in data else None
# jobs = ...
except (NotFound, KeyError, ValueError):
raise BadRequest("Missing POST parameter")
@ -239,7 +238,7 @@ def create_event(current_session):
"""
data = request.get_json()
try:
start = datetime.fromisoformat(data["start"]).replace(tzinfo=timezone.utc)
start = from_iso_format(data["start"])
event_type = event_controller.get_event_type(data["type"])
except (NotFound, KeyError, ValueError):
raise BadRequest("Missing POST parameter")
@ -273,7 +272,7 @@ def modify_event(event_id, current_session):
event = event_controller.get_event(event_id)
data = request.get_json()
if "start" in data:
event.start = datetime.fromisoformat(data["start"]).replace(tzinfo=timezone.utc)
event.start = from_iso_format(data["start"])
if "description" in data:
event.description = data["description"]
if "type" in data: