First version of schedule plugin
This commit is contained in:
parent
7f6ff3f001
commit
bd657d11b6
|
@ -1,289 +1,364 @@
|
||||||
|
from dateutil import parser
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
|
from werkzeug.exceptions import BadRequest, NotFound
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
from flaschengeist.system.controller import eventController
|
||||||
|
from flaschengeist.system.database import db
|
||||||
from flaschengeist.system.decorator import login_required
|
from flaschengeist.system.decorator import login_required
|
||||||
from flaschengeist import logger
|
from flaschengeist.system.models.event import Event, EventKind
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import .roles
|
schedule_bp = Blueprint("schedule", __name__)
|
||||||
|
|
||||||
schedule = Blueprint("schedule", __name__)
|
|
||||||
|
|
||||||
@schedule.route("/schedule/jobs", methods=['POST'])
|
def register():
|
||||||
@login_required(roles=['schedule_read'])
|
return schedule_bp
|
||||||
def _getUsers(**kwrags):
|
|
||||||
logger.debug("/schedule/jobs")
|
|
||||||
|
@schedule_bp.route("/schedule/events", methods=['GET'])
|
||||||
|
@schedule_bp.route("/schedule/events/<int:year>", methods=['GET'])
|
||||||
|
@schedule_bp.route("/schedule/events/<int:year>/<int:month>", methods=['GET'])
|
||||||
|
@schedule_bp.route("/schedule/events/<int:year>/<int:month>/<int:day>", methods=['GET'])
|
||||||
|
@login_required() # roles=['schedule_read'])
|
||||||
|
def _get_events(year=datetime.now().year, month=None, day=None, **kwrags):
|
||||||
|
"""Get Event objects for specified date (or month or year),
|
||||||
|
if nothing set then events for current year are returned
|
||||||
|
|
||||||
|
Args:
|
||||||
|
year (int, optional): year to query, defaults to current year
|
||||||
|
month (int, optional): month to query (if set)
|
||||||
|
day (int, optional): day to query events for (if set)
|
||||||
|
**kwrags: contains at least access_token (see flaschengeist.decorator)
|
||||||
|
Returns:
|
||||||
|
JSON list containing events found
|
||||||
|
Raises:
|
||||||
|
BadRequest: If date is invalid
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
begin = datetime(year=year, month=1, day=1)
|
||||||
from_date = data['from_date']
|
end = None
|
||||||
to_date = data['to_date']
|
if month:
|
||||||
from_date = datetime(from_date['year'], from_date['month'], from_date['day'])
|
begin = datetime(year=year, month=month, day=1)
|
||||||
to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
|
if day:
|
||||||
lockedDays = mainController.getLockedDays(from_date, to_date)
|
begin += timedelta(days=day - 1)
|
||||||
retVal = []
|
end = begin + timedelta(days=1)
|
||||||
for lockedDay in lockedDays:
|
else:
|
||||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
end = datetime(year=year, month=month + 1, day=1)
|
||||||
retDay = {
|
|
||||||
"worker": mainController.getWorker(day),
|
|
||||||
"day": {
|
|
||||||
"date": {
|
|
||||||
"year": day.year,
|
|
||||||
"month": day.month,
|
|
||||||
"day": day.day
|
|
||||||
},
|
|
||||||
"locked": lockedDay['locked']
|
|
||||||
},
|
|
||||||
"jobkinddate": mainController.getJobKindDates(day.date())
|
|
||||||
}
|
|
||||||
retVal.append(retDay)
|
|
||||||
|
|
||||||
logger.debug("return {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
logger.warn("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
@schedule.route("/user/jobsOnDates", methods=['POST'])
|
|
||||||
@login_required(groups=[USER])
|
|
||||||
def _getJobsOnDates(**kwargs):
|
|
||||||
debug.info("/user/jobsOnDates")
|
|
||||||
try:
|
|
||||||
data = request.get_json()
|
|
||||||
lockedDays = mainController.getLockedDaysFromList(data)
|
|
||||||
retVal = []
|
|
||||||
for lockedDay in lockedDays:
|
|
||||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
|
||||||
retDay = {
|
|
||||||
"worker": mainController.getWorker(day),
|
|
||||||
"day": {
|
|
||||||
"date": {
|
|
||||||
"year": day.year,
|
|
||||||
"month": day.month,
|
|
||||||
"day": day.day
|
|
||||||
},
|
|
||||||
"locked": lockedDay['locked']
|
|
||||||
},
|
|
||||||
"jobkinddate": mainController.getJobKindDates(day.date())
|
|
||||||
}
|
|
||||||
retVal.append(retDay)
|
|
||||||
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
@schedule.route("/user/job", methods=['POST'])
|
|
||||||
@login_required(groups=[USER])
|
|
||||||
def _getUser(**kwargs):
|
|
||||||
debug.info("/user/job")
|
|
||||||
try:
|
|
||||||
data = request.get_json()
|
|
||||||
day = data['day']
|
|
||||||
month = data['month']
|
|
||||||
year = data['year']
|
|
||||||
date = datetime(year, month, day, 12)
|
|
||||||
lockedDay = mainController.getLockedDay(date)
|
|
||||||
if not lockedDay:
|
|
||||||
lockedDay = {
|
|
||||||
'date': {
|
|
||||||
'year': year,
|
|
||||||
'month': month,
|
|
||||||
'day': day
|
|
||||||
},
|
|
||||||
'locked': False
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
lockedDay = {
|
end = datetime(year=year + 1, month=1, day=1)
|
||||||
'date': {
|
|
||||||
'year': year,
|
events = Event.query.filter((begin <= Event.begin), (Event.begin < end))
|
||||||
'month': month,
|
return jsonify(events)
|
||||||
'day': day
|
except ValueError:
|
||||||
},
|
raise BadRequest("Invalid date given")
|
||||||
'locked': lockedDay['locked']
|
|
||||||
}
|
|
||||||
retVal = {
|
|
||||||
'worker': mainController.getWorker(date),
|
|
||||||
'day': lockedDay
|
|
||||||
}
|
|
||||||
debug.debug("retrun {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
|
|
||||||
@schedule.route("/user/addJob", methods=['POST'])
|
@schedule_bp.route("/schedule/eventKinds", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required()
|
||||||
def _addUser(**kwargs):
|
def __new_event_kind(**kwargs):
|
||||||
debug.info("/user/addJob")
|
data = request.get_json()
|
||||||
try:
|
if "name" not in data:
|
||||||
if 'accToken' in kwargs:
|
raise BadRequest
|
||||||
accToken = kwargs['accToken']
|
event = eventController.create_event_kind(data["name"])
|
||||||
user = accToken.user
|
return jsonify({"ok": "ok", "id": event.id})
|
||||||
data = request.get_json()
|
|
||||||
day = data['day']
|
|
||||||
month = data['month']
|
|
||||||
year = data['year']
|
|
||||||
date = datetime(year, month, day, 12)
|
|
||||||
job_kind = None
|
|
||||||
if 'job_kind' in data:
|
|
||||||
job_kind = data['job_kind']
|
|
||||||
mainController.addWorker(user.uid, date, job_kind=job_kind, userExc=True)
|
|
||||||
retVal = mainController.getWorker(date)
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(
|
|
||||||
user.firstname, user.lastname, date.date()))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except DayLocked as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({'error': str(err)}), 403
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({'error': str(err)}), 409
|
|
||||||
|
|
||||||
|
|
||||||
@schedule.route("/user/deleteJob", methods=['POST'])
|
@schedule_bp.route("/schedule/events", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required()
|
||||||
def _deletJob(**kwargs):
|
def __new_event(**kwargs):
|
||||||
debug.info("/user/deleteJob")
|
data = request.get_json()
|
||||||
try:
|
event = eventController.create_event(begin=parser.isoparse(data["begin"]),
|
||||||
if 'accToken' in kwargs:
|
end=parser.isoparse(data["end"]),
|
||||||
accToken = kwargs['accToken']
|
description=data["description"],
|
||||||
user = accToken.user
|
kind=EventKind.query.get(data["kind"]))
|
||||||
data = request.get_json()
|
return jsonify({"ok": "ok", "id": event.id})
|
||||||
day = data['day']
|
|
||||||
month = data['month']
|
|
||||||
year = data['year']
|
|
||||||
date = datetime(year, month, day, 12)
|
|
||||||
mainController.deleteWorker(user.uid, date, True)
|
|
||||||
retVal = mainController.getWorker(date)
|
|
||||||
debug.debug("return ok")
|
|
||||||
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
|
||||||
user.firstname, user.lastname, date.date()))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except DayLocked as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 403
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 409
|
|
||||||
|
|
||||||
@schedule.route("/user/getJobInvites", methods=['POST'])
|
|
||||||
@login_required(groups=[USER])
|
|
||||||
def _getJobInvites(**kwargs):
|
|
||||||
try:
|
|
||||||
debug.info("/user/getJobInvites")
|
|
||||||
from_user = None
|
|
||||||
to_user = None
|
|
||||||
on_date = None
|
|
||||||
|
|
||||||
data = request.get_json()
|
|
||||||
|
|
||||||
if 'from_user' in data:
|
|
||||||
from_user = data['from_user']
|
|
||||||
if 'to_user' in data:
|
|
||||||
to_user = data['to_user']
|
|
||||||
on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
|
||||||
retVal = mainController.getJobInvites(from_user, to_user, on_date)
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
@schedule.route("/user/JobInvites", methods=['PUT', 'POST'])
|
|
||||||
@login_required(groups=[USER])
|
|
||||||
def _JobInvites(**kwargs):
|
|
||||||
try:
|
|
||||||
debug.info("/user/JobInvites")
|
|
||||||
data = request.get_json()
|
|
||||||
if request.method == 'PUT':
|
|
||||||
mainController.setJobInvites(data)
|
|
||||||
retVal = mainController.getJobInvites(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
if request.method == 'POST':
|
|
||||||
retVal = mainController.updateJobInvites(data)
|
|
||||||
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
@schedule.route("/user/deleteJobInvite", methods=['POST'])
|
|
||||||
@login_required(groups=[USER])
|
|
||||||
def _deleteJobInvite(**kwargs):
|
|
||||||
try:
|
|
||||||
debug.info("/user/deleteJobInvite")
|
|
||||||
data = request.get_json()
|
|
||||||
mainController.deleteJobInvite(data)
|
|
||||||
retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
|
|
||||||
@schedule.route("/user/getJobRequests", methods=['POST'])
|
@schedule_bp.route("/schedule/events/<int:id>", methods=["DELETE"])
|
||||||
@login_required(groups=[USER])
|
@login_required()
|
||||||
def _getJobRequests(**kwargs):
|
def __delete_event(id, **kwargs):
|
||||||
try:
|
if Event.query.filter(Event.id == id).delete() != 1:
|
||||||
debug.info("/user/getJobRequests")
|
raise NotFound
|
||||||
from_user = None
|
db.session.commit()
|
||||||
to_user = None
|
return jsonify({'ok': 'ok'})
|
||||||
on_date = None
|
|
||||||
|
|
||||||
data = request.get_json()
|
|
||||||
|
|
||||||
if 'from_user' in data:
|
def __edit_event():
|
||||||
from_user = data['from_user']
|
...
|
||||||
if 'to_user' in data:
|
|
||||||
to_user = data['to_user']
|
|
||||||
on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
|
||||||
retVal = mainController.getJobRequests(from_user, to_user, on_date)
|
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
|
||||||
return jsonify(retVal)
|
|
||||||
except Exception as err:
|
|
||||||
debug.debug("exception", exc_info=True)
|
|
||||||
return jsonify({"error": str(err)}), 500
|
|
||||||
|
|
||||||
@schedule.route("/user/JobRequests", methods=['PUT', 'POST'])
|
# try:
|
||||||
@login_required(groups=[USER])
|
# data = request.get_json()
|
||||||
def _JobRequests(**kwargs):
|
# from_date = data['from_date']
|
||||||
try:
|
# to_date = data['to_date']
|
||||||
debug.info("/user/JobRequests")
|
# from_date = datetime(from_date['year'], from_date['month'], from_date['day'])
|
||||||
data = request.get_json()
|
# to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
|
||||||
if request.method == 'PUT':
|
# lockedDays = mainController.getLockedDays(from_date, to_date)
|
||||||
mainController.setJobRequests(data)
|
# retVal = []
|
||||||
retVal = mainController.getJobRequests(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
# for lockedDay in lockedDays:
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
# day = datetime.combine(lockedDay['daydate'], time(12))
|
||||||
if request.method == 'POST':
|
# retDay = {
|
||||||
data['on_date'] = date(data['on_date']['year'], data['on_date']['month'], data['on_date']['day'])
|
# "worker": mainController.getWorker(day),
|
||||||
retVal = mainController.updateJobRequests(data)
|
# "day": {
|
||||||
|
# "date": {
|
||||||
return jsonify(retVal)
|
# "year": day.year,
|
||||||
except Exception as err:
|
# "month": day.month,
|
||||||
debug.debug("exception", exc_info=True)
|
# "day": day.day
|
||||||
return jsonify({"error": str(err)}), 500
|
# },
|
||||||
|
# "locked": lockedDay['locked']
|
||||||
@schedule.route("/user/deleteJobRequest", methods=['POST'])
|
# },
|
||||||
@login_required(groups=[USER])
|
# "jobkinddate": mainController.getJobKindDates(day.date())
|
||||||
def _deleteJobRequest(**kwargs):
|
# }
|
||||||
try:
|
# retVal.append(retDay)
|
||||||
debug.info("/user/deleteJobRequest")
|
#
|
||||||
data = request.get_json()
|
# logger.debug("return {{ {} }}".format(retVal))
|
||||||
mainController.deleteJobRequest(data)
|
# return jsonify(retVal)
|
||||||
retVal = mainController.getJobRequests(data['from_user'], None, datetime.now().date())
|
# except Exception as err:
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
# logger.warn("exception", exc_info=True)
|
||||||
return jsonify(retVal)
|
# return jsonify({"error": str(err)}), 500
|
||||||
except Exception as err:
|
#
|
||||||
debug.debug("exception", exc_info=True)
|
# @schedule.route("/user/jobsOnDates", methods=['POST'])
|
||||||
return jsonify({"error": str(err)}), 500
|
# @login_required(groups=[USER])
|
||||||
|
# def _getJobsOnDates(**kwargs):
|
||||||
|
# debug.info("/user/jobsOnDates")
|
||||||
|
# try:
|
||||||
|
# data = request.get_json()
|
||||||
|
# lockedDays = mainController.getLockedDaysFromList(data)
|
||||||
|
# retVal = []
|
||||||
|
# for lockedDay in lockedDays:
|
||||||
|
# day = datetime.combine(lockedDay['daydate'], time(12))
|
||||||
|
# retDay = {
|
||||||
|
# "worker": mainController.getWorker(day),
|
||||||
|
# "day": {
|
||||||
|
# "date": {
|
||||||
|
# "year": day.year,
|
||||||
|
# "month": day.month,
|
||||||
|
# "day": day.day
|
||||||
|
# },
|
||||||
|
# "locked": lockedDay['locked']
|
||||||
|
# },
|
||||||
|
# "jobkinddate": mainController.getJobKindDates(day.date())
|
||||||
|
# }
|
||||||
|
# retVal.append(retDay)
|
||||||
|
#
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/job", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _getUser(**kwargs):
|
||||||
|
# debug.info("/user/job")
|
||||||
|
# try:
|
||||||
|
# data = request.get_json()
|
||||||
|
# day = data['day']
|
||||||
|
# month = data['month']
|
||||||
|
# year = data['year']
|
||||||
|
# date = datetime(year, month, day, 12)
|
||||||
|
# lockedDay = mainController.getLockedDay(date)
|
||||||
|
# if not lockedDay:
|
||||||
|
# lockedDay = {
|
||||||
|
# 'date': {
|
||||||
|
# 'year': year,
|
||||||
|
# 'month': month,
|
||||||
|
# 'day': day
|
||||||
|
# },
|
||||||
|
# 'locked': False
|
||||||
|
# }
|
||||||
|
# else:
|
||||||
|
# lockedDay = {
|
||||||
|
# 'date': {
|
||||||
|
# 'year': year,
|
||||||
|
# 'month': month,
|
||||||
|
# 'day': day
|
||||||
|
# },
|
||||||
|
# 'locked': lockedDay['locked']
|
||||||
|
# }
|
||||||
|
# retVal = {
|
||||||
|
# 'worker': mainController.getWorker(date),
|
||||||
|
# 'day': lockedDay
|
||||||
|
# }
|
||||||
|
# debug.debug("retrun {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/addJob", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _addUser(**kwargs):
|
||||||
|
# debug.info("/user/addJob")
|
||||||
|
# try:
|
||||||
|
# if 'accToken' in kwargs:
|
||||||
|
# accToken = kwargs['accToken']
|
||||||
|
# user = accToken.user
|
||||||
|
# data = request.get_json()
|
||||||
|
# day = data['day']
|
||||||
|
# month = data['month']
|
||||||
|
# year = data['year']
|
||||||
|
# date = datetime(year, month, day, 12)
|
||||||
|
# job_kind = None
|
||||||
|
# if 'job_kind' in data:
|
||||||
|
# job_kind = data['job_kind']
|
||||||
|
# mainController.addWorker(user.uid, date, job_kind=job_kind, userExc=True)
|
||||||
|
# retVal = mainController.getWorker(date)
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(
|
||||||
|
# user.firstname, user.lastname, date.date()))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except DayLocked as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({'error': str(err)}), 403
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({'error': str(err)}), 409
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/deleteJob", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _deletJob(**kwargs):
|
||||||
|
# debug.info("/user/deleteJob")
|
||||||
|
# try:
|
||||||
|
# if 'accToken' in kwargs:
|
||||||
|
# accToken = kwargs['accToken']
|
||||||
|
# user = accToken.user
|
||||||
|
# data = request.get_json()
|
||||||
|
# day = data['day']
|
||||||
|
# month = data['month']
|
||||||
|
# year = data['year']
|
||||||
|
# date = datetime(year, month, day, 12)
|
||||||
|
# mainController.deleteWorker(user.uid, date, True)
|
||||||
|
# retVal = mainController.getWorker(date)
|
||||||
|
# debug.debug("return ok")
|
||||||
|
# jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
||||||
|
# user.firstname, user.lastname, date.date()))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except DayLocked as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 403
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 409
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/getJobInvites", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _getJobInvites(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/getJobInvites")
|
||||||
|
# from_user = None
|
||||||
|
# to_user = None
|
||||||
|
# on_date = None
|
||||||
|
#
|
||||||
|
# data = request.get_json()
|
||||||
|
#
|
||||||
|
# if 'from_user' in data:
|
||||||
|
# from_user = data['from_user']
|
||||||
|
# if 'to_user' in data:
|
||||||
|
# to_user = data['to_user']
|
||||||
|
# on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
||||||
|
# retVal = mainController.getJobInvites(from_user, to_user, on_date)
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/JobInvites", methods=['PUT', 'POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _JobInvites(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/JobInvites")
|
||||||
|
# data = request.get_json()
|
||||||
|
# if request.method == 'PUT':
|
||||||
|
# mainController.setJobInvites(data)
|
||||||
|
# retVal = mainController.getJobInvites(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# retVal = mainController.updateJobInvites(data)
|
||||||
|
#
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/deleteJobInvite", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _deleteJobInvite(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/deleteJobInvite")
|
||||||
|
# data = request.get_json()
|
||||||
|
# mainController.deleteJobInvite(data)
|
||||||
|
# retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/getJobRequests", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _getJobRequests(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/getJobRequests")
|
||||||
|
# from_user = None
|
||||||
|
# to_user = None
|
||||||
|
# on_date = None
|
||||||
|
#
|
||||||
|
# data = request.get_json()
|
||||||
|
#
|
||||||
|
# if 'from_user' in data:
|
||||||
|
# from_user = data['from_user']
|
||||||
|
# if 'to_user' in data:
|
||||||
|
# to_user = data['to_user']
|
||||||
|
# on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
||||||
|
# retVal = mainController.getJobRequests(from_user, to_user, on_date)
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/JobRequests", methods=['PUT', 'POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _JobRequests(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/JobRequests")
|
||||||
|
# data = request.get_json()
|
||||||
|
# if request.method == 'PUT':
|
||||||
|
# mainController.setJobRequests(data)
|
||||||
|
# retVal = mainController.getJobRequests(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# data['on_date'] = date(data['on_date']['year'], data['on_date']['month'], data['on_date']['day'])
|
||||||
|
# retVal = mainController.updateJobRequests(data)
|
||||||
|
#
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
#
|
||||||
|
# @schedule.route("/user/deleteJobRequest", methods=['POST'])
|
||||||
|
# @login_required(groups=[USER])
|
||||||
|
# def _deleteJobRequest(**kwargs):
|
||||||
|
# try:
|
||||||
|
# debug.info("/user/deleteJobRequest")
|
||||||
|
# data = request.get_json()
|
||||||
|
# mainController.deleteJobRequest(data)
|
||||||
|
# retVal = mainController.getJobRequests(data['from_user'], None, datetime.now().date())
|
||||||
|
# debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
# return jsonify(retVal)
|
||||||
|
# except Exception as err:
|
||||||
|
# debug.debug("exception", exc_info=True)
|
||||||
|
# return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
# CREDIT == Gerücht? CreditList?
|
# CREDIT == Gerücht? CreditList?
|
||||||
#creditL = getCreditLogger()
|
# creditL = getCreditLogger()
|
||||||
#@schedule.route("/user/main")
|
# @schedule.route("/user/main")
|
||||||
#@login_required(groups=[USER])
|
# @login_required(groups=[USER])
|
||||||
#def _main(**kwargs):
|
# def _main(**kwargs):
|
||||||
# debug.info("/user/main")
|
# debug.info("/user/main")
|
||||||
# try:
|
# try:
|
||||||
# if 'accToken' in kwargs:
|
# if 'accToken' in kwargs:
|
||||||
|
@ -299,9 +374,9 @@ def _deleteJobRequest(**kwargs):
|
||||||
# return jsonify("error", "something went wrong"), 500
|
# return jsonify("error", "something went wrong"), 500
|
||||||
|
|
||||||
|
|
||||||
#@schedule.route("/user/addAmount", methods=['POST'])
|
# @schedule.route("/user/addAmount", methods=['POST'])
|
||||||
#@login_required(groups=[USER])
|
# @login_required(groups=[USER])
|
||||||
#def _addAmount(**kwargs):
|
# def _addAmount(**kwargs):
|
||||||
# debug.info("/user/addAmount")
|
# debug.info("/user/addAmount")
|
||||||
# try:
|
# try:
|
||||||
# if 'accToken' in kwargs:
|
# if 'accToken' in kwargs:
|
||||||
|
@ -324,9 +399,9 @@ def _deleteJobRequest(**kwargs):
|
||||||
# return jsonify({"error": "something went wrong"}), 500
|
# return jsonify({"error": "something went wrong"}), 500
|
||||||
|
|
||||||
|
|
||||||
#@schedule.route("/user/saveConfig", methods=['POST'])
|
# @schedule.route("/user/saveConfig", methods=['POST'])
|
||||||
#@login_required(groups=[USER])
|
# @login_required(groups=[USER])
|
||||||
#def _saveConfig(**kwargs):
|
# def _saveConfig(**kwargs):
|
||||||
# debug.info("/user/saveConfig")
|
# debug.info("/user/saveConfig")
|
||||||
# try:
|
# try:
|
||||||
# if 'accToken' in kwargs:
|
# if 'accToken' in kwargs:
|
||||||
|
@ -345,9 +420,9 @@ def _deleteJobRequest(**kwargs):
|
||||||
# debug.debug("exception", exc_info=True)
|
# debug.debug("exception", exc_info=True)
|
||||||
# return jsonify({"error": str(err)}), 409
|
# return jsonify({"error": str(err)}), 409
|
||||||
#
|
#
|
||||||
#@schedule.route("/user/storno", methods=['POST'])
|
# @schedule.route("/user/storno", methods=['POST'])
|
||||||
#@login_required(groups=[USER])
|
# @login_required(groups=[USER])
|
||||||
#def _storno(**kwargs):
|
# def _storno(**kwargs):
|
||||||
# """ Function for Baruser to storno amount
|
# """ Function for Baruser to storno amount
|
||||||
#
|
#
|
||||||
# This function added to the user with the posted userID the posted amount.
|
# This function added to the user with the posted userID the posted amount.
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
from werkzeug.exceptions import BadRequest
|
||||||
|
|
||||||
|
from flaschengeist.system.models.event import EventKind, Event
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
|
from flaschengeist import logger
|
||||||
|
from flaschengeist.system.database import db
|
||||||
|
|
||||||
|
|
||||||
|
def create_event(begin, kind, end=None, description=None):
|
||||||
|
try:
|
||||||
|
event = Event(begin=begin,
|
||||||
|
end=end,
|
||||||
|
description=description,
|
||||||
|
kind=kind)
|
||||||
|
db.session.add(event)
|
||||||
|
db.session.commit()
|
||||||
|
return event
|
||||||
|
except IntegrityError:
|
||||||
|
logger.debug("Database error when creating new event", exc_info=True)
|
||||||
|
raise BadRequest
|
||||||
|
|
||||||
|
|
||||||
|
def create_event_kind(name):
|
||||||
|
try:
|
||||||
|
event = EventKind(name=name)
|
||||||
|
db.session.add(event)
|
||||||
|
db.session.commit()
|
||||||
|
return event
|
||||||
|
except IntegrityError:
|
||||||
|
logger.debug("IntegrityError: Looks like there is a name collision", exc_info=True)
|
||||||
|
raise BadRequest("Name already exists")
|
|
@ -0,0 +1,82 @@
|
||||||
|
from ..database import db
|
||||||
|
|
||||||
|
|
||||||
|
class Event(db.Model):
|
||||||
|
"""Model for an Event"""
|
||||||
|
__tablename__ = 'event'
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
begin = db.Column(db.DateTime, nullable=False)
|
||||||
|
end = db.Column(db.DateTime)
|
||||||
|
description = db.Column(db.String(240))
|
||||||
|
kind_id = db.Column(db.Integer, db.ForeignKey('event_kind.id', ondelete="CASCADE"), nullable=False)
|
||||||
|
kind = db.relationship("EventKind")
|
||||||
|
slots = db.relationship("EventSlot", back_populates="event", cascade="all, delete")
|
||||||
|
#notices = db.relationship("EventNotice", back_populates="event")
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"begin": self.begin,
|
||||||
|
"end": self.end,
|
||||||
|
"description": self.description,
|
||||||
|
"kind": self.kind
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EventKind(db.Model):
|
||||||
|
"""Model for an EventKind"""
|
||||||
|
__tablename__ = "event_kind"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
name = db.Column(db.String(30), nullable=False, unique=True)
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"name": self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EventSlot(db.Model):
|
||||||
|
"""Model for an EventSlot"""
|
||||||
|
__tablename__ = "event_slot"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
start = db.Column(db.DateTime)
|
||||||
|
end = db.Column(db.DateTime)
|
||||||
|
event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
|
||||||
|
event = db.relationship("Event", back_populates="slots")
|
||||||
|
slots = db.relationship("JobSlot", back_populates="event_slot")
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"start": self.start,
|
||||||
|
"end": self.end,
|
||||||
|
"event": self.event_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JobSlot(db.Model):
|
||||||
|
__tablename__ = "job_slot"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
needed_persons = db.Column(db.Numeric(precision=4, scale=2))
|
||||||
|
event_slot_id = db.Column(db.Integer, db.ForeignKey('event_slot.id'))
|
||||||
|
event_slot = db.relationship("EventSlot", back_populates="slots")
|
||||||
|
kind_id = db.Column(db.Integer, db.ForeignKey('job_kind.id'))
|
||||||
|
kind = db.relationship("JobKind")
|
||||||
|
jobs = db.relationship("Job", back_populates="slot")
|
||||||
|
|
||||||
|
|
||||||
|
class Job(db.Model):
|
||||||
|
__tablename__ = "job"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
value = db.Column(db.Numeric(precision=3, scale=2))
|
||||||
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
||||||
|
user = db.relationship("User")
|
||||||
|
slot_id = db.Column(db.Integer, db.ForeignKey('job_slot.id'))
|
||||||
|
slot = db.relationship("JobSlot")
|
||||||
|
|
||||||
|
|
||||||
|
class JobKind(db.Model):
|
||||||
|
__tablename__ = "job_kind"
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
name = db.Column(db.String(30))
|
Loading…
Reference in New Issue