vorstand can set job_kinds for day with max persons
extern user can be set if job_kind is delete, all jobs are deleted for this date and job_kind
This commit is contained in:
parent
7ce8fef278
commit
2ef50fbefd
|
@ -1,6 +1,6 @@
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
import geruecht.controller.ldapController as lc
|
import geruecht.controller.ldapController as lc
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.model import BAR, MONEY, USER, VORSTAND
|
from geruecht.model import BAR, MONEY, USER, VORSTAND
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
|
@ -12,7 +12,7 @@ creditL = getCreditLogger()
|
||||||
baruser = Blueprint("baruser", __name__)
|
baruser = Blueprint("baruser", __name__)
|
||||||
|
|
||||||
ldap = lc.LDAPController()
|
ldap = lc.LDAPController()
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
|
|
||||||
@baruser.route("/bar")
|
@baruser.route("/bar")
|
||||||
|
@ -29,7 +29,7 @@ def _bar(**kwargs):
|
||||||
debug.info("/bar")
|
debug.info("/bar")
|
||||||
try:
|
try:
|
||||||
dic = {}
|
dic = {}
|
||||||
users = userController.getAllUsersfromDB()
|
users = mainController.getAllUsersfromDB()
|
||||||
for user in users:
|
for user in users:
|
||||||
geruecht = None
|
geruecht = None
|
||||||
geruecht = user.getGeruecht(datetime.now().year)
|
geruecht = user.getGeruecht(datetime.now().year)
|
||||||
|
@ -72,9 +72,9 @@ def _baradd(**kwargs):
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
amountl = amount
|
amountl = amount
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addAmount(
|
mainController.addAmount(
|
||||||
userID, amount, year=date.year, month=date.month)
|
userID, amount, year=date.year, month=date.month)
|
||||||
user = userController.getUser(userID)
|
user = mainController.getUser(userID)
|
||||||
geruecht = user.getGeruecht(year=date.year)
|
geruecht = user.getGeruecht(year=date.year)
|
||||||
month = geruecht.getMonth(month=date.month)
|
month = geruecht.getMonth(month=date.month)
|
||||||
amount = abs(month[0] - month[1])
|
amount = abs(month[0] - month[1])
|
||||||
|
@ -135,9 +135,9 @@ def _storno(**kwargs):
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
amountl = amount
|
amountl = amount
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addCredit(
|
mainController.addCredit(
|
||||||
userID, amount, year=date.year, month=date.month)
|
userID, amount, year=date.year, month=date.month)
|
||||||
user = userController.getUser(userID)
|
user = mainController.getUser(userID)
|
||||||
geruecht = user.getGeruecht(year=date.year)
|
geruecht = user.getGeruecht(year=date.year)
|
||||||
month = geruecht.getMonth(month=date.month)
|
month = geruecht.getMonth(month=date.month)
|
||||||
amount = abs(month[0] - month[1])
|
amount = abs(month[0] - month[1])
|
||||||
|
@ -165,7 +165,7 @@ def _getUser(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['userId']
|
username = data['userId']
|
||||||
user = userController.getUser(username)
|
user = mainController.getUser(username)
|
||||||
amount = user.getGeruecht(datetime.now().year).getSchulden()
|
amount = user.getGeruecht(datetime.now().year).getSchulden()
|
||||||
if amount >= 0:
|
if amount >= 0:
|
||||||
type = 'credit'
|
type = 'credit'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from geruecht.model.accessToken import AccessToken
|
from geruecht.model.accessToken import AccessToken
|
||||||
import geruecht.controller as gc
|
import geruecht.controller as gc
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from geruecht.model import BAR
|
from geruecht.model import BAR
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -9,7 +9,7 @@ from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
debug = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
class AccesTokenController(metaclass=Singleton):
|
class AccesTokenController(metaclass=Singleton):
|
||||||
""" Control all createt AccesToken
|
""" Control all createt AccesToken
|
||||||
|
@ -34,7 +34,7 @@ class AccesTokenController(metaclass=Singleton):
|
||||||
|
|
||||||
def checkBar(self, user):
|
def checkBar(self, user):
|
||||||
debug.info("check if user {{ {} }} is baruser".format(user))
|
debug.info("check if user {{ {} }} is baruser".format(user))
|
||||||
if (userController.checkBarUser(user)):
|
if (mainController.checkBarUser(user)):
|
||||||
if BAR not in user.group:
|
if BAR not in user.group:
|
||||||
debug.debug("append bar to user {{ {} }}".format(user))
|
debug.debug("append bar to user {{ {} }}".format(user))
|
||||||
user.group.append(BAR)
|
user.group.append(BAR)
|
||||||
|
|
|
@ -1,769 +0,0 @@
|
||||||
import pymysql
|
|
||||||
from . import Singleton
|
|
||||||
from geruecht import db
|
|
||||||
from geruecht.model.user import User
|
|
||||||
from geruecht.model.creditList import CreditList
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from geruecht.exceptions import UsernameExistDB, DatabaseExecption
|
|
||||||
import traceback
|
|
||||||
from MySQLdb._exceptions import IntegrityError
|
|
||||||
|
|
||||||
class DatabaseController(metaclass=Singleton):
|
|
||||||
'''
|
|
||||||
DatabaesController
|
|
||||||
|
|
||||||
Connect to the Database and execute sql-executions
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.db = db
|
|
||||||
|
|
||||||
def getAllUser(self, extern=False, workgroups=True):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user")
|
|
||||||
data = cursor.fetchall()
|
|
||||||
|
|
||||||
if data:
|
|
||||||
retVal = []
|
|
||||||
for value in data:
|
|
||||||
if extern and value['uid'] == 'extern':
|
|
||||||
continue
|
|
||||||
user = User(value)
|
|
||||||
creditLists = self.getCreditListFromUser(user)
|
|
||||||
user.initGeruechte(creditLists)
|
|
||||||
if workgroups:
|
|
||||||
user.workgroups = self.getWorkgroupsOfUser(user.id)
|
|
||||||
retVal.append(user)
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def getUser(self, username, workgroups=True):
|
|
||||||
try:
|
|
||||||
retVal = None
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user where uid='{}'".format(username))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
if data:
|
|
||||||
retVal = User(data)
|
|
||||||
creditLists = self.getCreditListFromUser(retVal)
|
|
||||||
retVal.initGeruechte(creditLists)
|
|
||||||
if workgroups:
|
|
||||||
retVal.workgroups = self.getWorkgroupsOfUser(retVal.id)
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def getUserById(self, id, workgroups=True):
|
|
||||||
try:
|
|
||||||
retVal = None
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user where id={}".format(id))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
if data:
|
|
||||||
retVal = User(data)
|
|
||||||
creditLists = self.getCreditListFromUser(retVal)
|
|
||||||
retVal.initGeruechte(creditLists)
|
|
||||||
if workgroups:
|
|
||||||
retVal.workgroups = self.getWorkgroupsOfUser(retVal.id)
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def _convertGroupToString(self, groups):
|
|
||||||
retVal = ''
|
|
||||||
print('groups: {}'.format(groups))
|
|
||||||
if groups:
|
|
||||||
for group in groups:
|
|
||||||
if len(retVal) != 0:
|
|
||||||
retVal += ','
|
|
||||||
retVal += group
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
|
|
||||||
def insertUser(self, user):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
groups = self._convertGroupToString(user.group)
|
|
||||||
cursor.execute("insert into user (uid, dn, firstname, lastname, gruppe, lockLimit, locked, autoLock, mail) VALUES ('{}','{}','{}','{}','{}',{},{},{},'{}')".format(
|
|
||||||
user.uid, user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
|
|
||||||
def updateUser(self, user):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
print('uid: {}; group: {}'.format(user.uid, user.group))
|
|
||||||
groups = self._convertGroupToString(user.group)
|
|
||||||
sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format(
|
|
||||||
user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid)
|
|
||||||
print(sql)
|
|
||||||
cursor.execute(sql)
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
|
|
||||||
def getCreditListFromUser(self, user, **kwargs):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if 'year' in kwargs:
|
|
||||||
sql = "select * from creditList where user_id={} and year_date={}".format(user.id, kwargs['year'])
|
|
||||||
else:
|
|
||||||
sql = "select * from creditList where user_id={}".format(user.id)
|
|
||||||
cursor.execute(sql)
|
|
||||||
data = cursor.fetchall()
|
|
||||||
if len(data) == 1:
|
|
||||||
return [CreditList(data[0])]
|
|
||||||
else:
|
|
||||||
return [CreditList(value) for value in data]
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
|
|
||||||
def createCreditList(self, user_id, year=datetime.now().year):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
|
|
||||||
def updateCreditList(self, creditlist):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from creditList where user_id={} and year_date={}".format(creditlist.user_id, creditlist.year))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
if len(data) == 0:
|
|
||||||
self.createCreditList(creditlist.user_id, creditlist.year)
|
|
||||||
sql = "update creditList set jan_guthaben={}, jan_schulden={},feb_guthaben={}, feb_schulden={}, maer_guthaben={}, maer_schulden={}, apr_guthaben={}, apr_schulden={}, mai_guthaben={}, mai_schulden={}, jun_guthaben={}, jun_schulden={}, jul_guthaben={}, jul_schulden={}, aug_guthaben={}, aug_schulden={},sep_guthaben={}, sep_schulden={},okt_guthaben={}, okt_schulden={}, nov_guthaben={}, nov_schulden={}, dez_guthaben={}, dez_schulden={}, last_schulden={} where year_date={} and user_id={}".format(creditlist.jan_guthaben, creditlist.jan_schulden,
|
|
||||||
creditlist.feb_guthaben, creditlist.feb_schulden,
|
|
||||||
creditlist.maer_guthaben, creditlist.maer_schulden,
|
|
||||||
creditlist.apr_guthaben, creditlist.apr_schulden,
|
|
||||||
creditlist.mai_guthaben, creditlist.mai_schulden,
|
|
||||||
creditlist.jun_guthaben, creditlist.jun_schulden,
|
|
||||||
creditlist.jul_guthaben, creditlist.jul_schulden,
|
|
||||||
creditlist.aug_guthaben, creditlist.aug_schulden,
|
|
||||||
creditlist.sep_guthaben, creditlist.sep_schulden,
|
|
||||||
creditlist.okt_guthaben, creditlist.okt_schulden,
|
|
||||||
creditlist.nov_guthaben, creditlist.nov_schulden,
|
|
||||||
creditlist.dez_guthaben, creditlist.dez_schulden,
|
|
||||||
creditlist.last_schulden, creditlist.year, creditlist.user_id)
|
|
||||||
print(sql)
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute(sql)
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def getWorker(self, user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}} if data else None
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def getWorkers(self, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from bardienste where startdatetime='{}'".format(date))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}} for work in data]
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def setWorker(self, user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into bardienste (user_id, startdatetime, enddatetime) values ({},'{}','{}')".format(user.id, date, date + timedelta(days=1)))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
|
|
||||||
def deleteWorker(self, user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from bardienste where user_id={} and startdatetime='{}'".format(user.id, date))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def changeUsername(self, user, newUsername):
|
|
||||||
try:
|
|
||||||
cursor= self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user where uid='{}'".format(newUsername))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
if data:
|
|
||||||
raise UsernameExistDB("Username already exists")
|
|
||||||
else:
|
|
||||||
cursor.execute("update user set uid='{}' where id={}".format(newUsername, user.id))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def getLockedDay(self, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from locked_days where daydate='{}'".format(date))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
return data
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def setLockedDay(self, date, locked, hard=False):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
sql = "insert into locked_days (daydate, locked) VALUES ('{}', {})".format(date, locked)
|
|
||||||
cursor.execute(sql)
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getLockedDay(date)
|
|
||||||
except IntegrityError as err:
|
|
||||||
self.db.connection.rollback()
|
|
||||||
try:
|
|
||||||
exists = self.getLockedDay(date)
|
|
||||||
if hard:
|
|
||||||
sql = "update locked_days set locked={} where id={}".format(locked, exists['id'])
|
|
||||||
else:
|
|
||||||
sql = False
|
|
||||||
if sql:
|
|
||||||
cursor.execute(sql)
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getLockedDay(date)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
||||||
|
|
||||||
def setTransactJob(self, from_user, to_user, date):
|
|
||||||
try:
|
|
||||||
exists = self.getTransactJob(from_user, to_user, date)
|
|
||||||
if exists:
|
|
||||||
raise IntegrityError("job_transact already exists")
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into job_transact (jobdate, from_user_id, to_user_id) VALUES ('{}', {}, {})".format(date, from_user.id, to_user.id))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getTransactJob(from_user, to_user, date)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getTransactJob(self, from_user, to_user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
if data:
|
|
||||||
return {"from_user": from_user, "to_user": to_user, "date": data['jobdate'], "answerd": data['answerd'], "accepted": data['accepted']}
|
|
||||||
return None
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getAllTransactJobFromUser(self, from_user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from job_transact where from_user_id={}".format(from_user.id))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
retVal = []
|
|
||||||
for transact in data:
|
|
||||||
if date <= transact['jobdate']:
|
|
||||||
retVal.append({"from_user": from_user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']})
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getAllTransactJobToUser(self, to_user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from job_transact where to_user_id={}".format(to_user.id))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
retVal = []
|
|
||||||
for transact in data:
|
|
||||||
if date <= transact['jobdate']:
|
|
||||||
retVal.append({"to_user": to_user, "from_user": self.getUserById(transact['from_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']})
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getTransactJobToUser(self, to_user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from job_transact where to_user_id={} and jobdate='{}'".format(to_user.id, date))
|
|
||||||
data = cursor.fetchone()
|
|
||||||
if data:
|
|
||||||
return {"from_user": self.getUserById(data['from_user_id']), "to_user": to_user, "date": data['jobdate'], "accepted": data['accepted'], "answerd": data['answerd']}
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def updateTransactJob(self, from_user, to_user, date, accepted):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update job_transact set accepted={}, answerd=true where to_user_id={} and jobdate='{}'".format(accepted, to_user.id, date))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getTransactJob(from_user, to_user, date)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getTransactJobFromUser(self, user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from job_transact where from_user_id={} and jobdate='{}'".format(user.id, date))
|
|
||||||
data = cursor.fetchall()
|
|
||||||
return [{"from_user": user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']} for transact in data]
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def deleteTransactJob(self, from_user, to_user, date):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getPriceList(self):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from pricelist")
|
|
||||||
return cursor.fetchall()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getDrinkPrice(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if type(name) == str:
|
|
||||||
sql = "select * from pricelist where name='{}'".format(name)
|
|
||||||
elif type(name) == int:
|
|
||||||
sql = 'select * from pricelist where id={}'.format(name)
|
|
||||||
else:
|
|
||||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
|
||||||
cursor.execute(sql)
|
|
||||||
return cursor.fetchone()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def setDrinkPrice(self, drink):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute(
|
|
||||||
"insert into pricelist (name, price, price_big, price_club, price_club_big, premium, premium_club, price_extern_club, type) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
|
|
||||||
(
|
|
||||||
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'],
|
|
||||||
drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getDrinkPrice(str(drink['name']))
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def updateDrinkPrice(self, drink):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update pricelist set name=%s, price=%s, price_big=%s, price_club=%s, price_club_big=%s, premium=%s, premium_club=%s, price_extern_club=%s, type=%s where id=%s",
|
|
||||||
(
|
|
||||||
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'], drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type'], drink['id']
|
|
||||||
))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getDrinkPrice(drink['id'])
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def deleteDrink(self, drink):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from pricelist where id={}".format(drink['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getDrinkType(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if type(name) == str:
|
|
||||||
sql = "select * from drink_type where name='{}'".format(name)
|
|
||||||
elif type(name) == int:
|
|
||||||
sql = 'select * from drink_type where id={}'.format(name)
|
|
||||||
else:
|
|
||||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
|
||||||
cursor.execute(sql)
|
|
||||||
return cursor.fetchone()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def setDrinkType(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into drink_type (name) values ('{}')".format(name))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getDrinkType(name)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
||||||
|
|
||||||
def updateDrinkType(self, type):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update drink_type set name='{}' where id={}".format(type['name'], type['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getDrinkType(type['id'])
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
||||||
|
|
||||||
def deleteDrinkType(self, type):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from drink_type where id={}".format(type['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getAllDrinkTypes(self):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute('select * from drink_type')
|
|
||||||
return cursor.fetchall()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getAllStatus(self):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute('select * from statusgroup')
|
|
||||||
return cursor.fetchall()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def getStatus(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if type(name) == str:
|
|
||||||
sql = "select * from statusgroup where name='{}'".format(name)
|
|
||||||
elif type(name) == int:
|
|
||||||
sql = 'select * from statusgroup where id={}'.format(name)
|
|
||||||
else:
|
|
||||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
|
||||||
cursor.execute(sql)
|
|
||||||
return cursor.fetchone()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def setStatus(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into statusgroup (name) values ('{}')".format(name))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getStatus(name)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def updateStatus(self, status):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update statusgroup set name='{}' where id={}".format(status['name'], status['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getStatus(status['id'])
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def deleteStatus(self, status):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from statusgroup where id={}".format(status['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def updateStatusOfUser(self, username, status):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update user set statusgroup={} where uid='{}'".format(status['id'], username))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getUser(username)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def updateVotingOfUser(self, username, voting):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update user set voting={} where uid='{}'".format(voting, username))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getUser(username)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def getAllWorkgroups(self):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute('select * from workgroup')
|
|
||||||
list = cursor.fetchall()
|
|
||||||
for item in list:
|
|
||||||
if item['boss'] != None:
|
|
||||||
item['boss']=self.getUserById(item['boss'], workgroups=False).toJSON()
|
|
||||||
return list
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def getWorkgroup(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if type(name) == str:
|
|
||||||
sql = "select * from workgroup where name='{}'".format(name)
|
|
||||||
elif type(name) == int:
|
|
||||||
sql = 'select * from workgroup where id={}'.format(name)
|
|
||||||
else:
|
|
||||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
|
||||||
cursor.execute(sql)
|
|
||||||
retVal = cursor.fetchone()
|
|
||||||
retVal['boss'] = self.getUserById(retVal['boss'], workgroups=False).toJSON() if retVal['boss'] != None else None
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def setWorkgroup(self, name, boss):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into workgroup (name, boss) values ('{}', {})".format(name, boss['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getWorkgroup(name)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def updateWorkgroup(self, workgroup):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update workgroup set name='{}', boss={} where id={}".format(workgroup['name'], workgroup['boss']['id'], workgroup['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getWorkgroup(workgroup['id'])
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def deleteWorkgroup(self, workgroup):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from workgroup where id={}".format(workgroup['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def getWorkgroupsOfUser(self, userid):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user_workgroup where user_id={} ".format(userid))
|
|
||||||
knots = cursor.fetchall()
|
|
||||||
retVal = [self.getWorkgroup(knot['workgroup_id']) for knot in knots]
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getUsersOfWorkgroups(self, workgroupid):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user_workgroup where workgroup_id={}".format(workgroupid))
|
|
||||||
knots = cursor.fetchall()
|
|
||||||
retVal = [self.getUserById(knot['user_id'], workgroups=False).toJSON() for knot in knots]
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getUserWorkgroup(self, user, workgroup):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("select * from user_workgroup where workgroup_id={} and user_id={}".format(workgroup['id'], user['id']))
|
|
||||||
knot = cursor.fetchone()
|
|
||||||
retVal = {"workgroup": self.getWorkgroup(workgroup['id']), "user": self.getUserById(user['id'], workgroups=False).toJSON()}
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def setUserWorkgroup(self, user, workgroup):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into user_workgroup (user_id, workgroup_id) VALUES ({}, {})".format(user['id'], workgroup['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getUserWorkgroup(user, workgroup)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def deleteWorkgroupsOfUser(self, user):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from user_workgroup where user_id={}".format(user['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
||||||
|
|
||||||
def getAllJobKinds(self):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute('select * from job_kind')
|
|
||||||
list = cursor.fetchall()
|
|
||||||
for item in list:
|
|
||||||
item['workgroup'] = self.getWorkgroup(item['workgroup']) if item['workgroup'] != None else None
|
|
||||||
return list
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def getJobKind(self, name):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
if type(name) == str:
|
|
||||||
sql = "select * from job_kind where name='{}'".format(name)
|
|
||||||
elif type(name) == int:
|
|
||||||
sql = 'select * from job_kind where id={}'.format(name)
|
|
||||||
else:
|
|
||||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
|
||||||
cursor.execute(sql)
|
|
||||||
retVal = cursor.fetchone()
|
|
||||||
retVal['workgroup'] = self.getWorkgroup(retVal['workgroup']) if retVal['workgroup'] != None else None
|
|
||||||
return retVal
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def setJobKind(self, name, workgroup_id):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("insert into job_kind (name, workgroup) values ('{}', {})".format(name, workgroup_id if workgroup_id != None else 'NULL'))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getJobKind(name)
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def updateJobKind(self, jobkind):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("update job_kind set name='{}', workgroup={} where id={}".format(jobkind['name'], jobkind['workgroup']['id'] if jobkind['workgroup'] != None else 'NULL', jobkind['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
return self.getJobKind(jobkind['id'])
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
def deleteJobKind(self, jobkind):
|
|
||||||
try:
|
|
||||||
cursor = self.db.connection.cursor()
|
|
||||||
cursor.execute("delete from job_kind where id={}".format(jobkind['id']))
|
|
||||||
self.db.connection.commit()
|
|
||||||
except Exception as err:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.db.connection.rollback()
|
|
||||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
db = DatabaseController()
|
|
||||||
user = db.getUser('jhille')
|
|
||||||
db.getCreditListFromUser(user, year=2018)
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
from ..mainController import Singleton
|
||||||
|
from geruecht import db
|
||||||
|
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbJobTransactController, dbPricelistController, dbWorkerController, dbWorkgroupController
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
import traceback
|
||||||
|
from MySQLdb._exceptions import IntegrityError
|
||||||
|
|
||||||
|
class DatabaseController(dbUserController.Base, dbCreditListController.Base, dbWorkerController.Base, dbWorkgroupController.Base, dbPricelistController.Base, dbJobTransactController.Base, dbJobKindController.Base, metaclass=Singleton):
|
||||||
|
'''
|
||||||
|
DatabaesController
|
||||||
|
|
||||||
|
Connect to the Database and execute sql-executions
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.db = db
|
||||||
|
|
||||||
|
def getLockedDay(self, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from locked_days where daydate='{}'".format(date))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
return data
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def setLockedDay(self, date, locked, hard=False):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
sql = "insert into locked_days (daydate, locked) VALUES ('{}', {})".format(date, locked)
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getLockedDay(date)
|
||||||
|
except IntegrityError as err:
|
||||||
|
self.db.connection.rollback()
|
||||||
|
try:
|
||||||
|
exists = self.getLockedDay(date)
|
||||||
|
if hard:
|
||||||
|
sql = "update locked_days set locked={} where id={}".format(locked, exists['id'])
|
||||||
|
else:
|
||||||
|
sql = False
|
||||||
|
if sql:
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getLockedDay(date)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
db = DatabaseController()
|
||||||
|
user = db.getUser('jhille')
|
||||||
|
db.getCreditListFromUser(user, year=2018)
|
|
@ -0,0 +1,66 @@
|
||||||
|
import traceback
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
from geruecht.model.creditList import CreditList
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getCreditListFromUser(self, user, **kwargs):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if 'year' in kwargs:
|
||||||
|
sql = "select * from creditList where user_id={} and year_date={}".format(user.id, kwargs['year'])
|
||||||
|
else:
|
||||||
|
sql = "select * from creditList where user_id={}".format(user.id)
|
||||||
|
cursor.execute(sql)
|
||||||
|
data = cursor.fetchall()
|
||||||
|
if len(data) == 1:
|
||||||
|
return [CreditList(data[0])]
|
||||||
|
else:
|
||||||
|
return [CreditList(value) for value in data]
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
|
||||||
|
def createCreditList(self, user_id, year=datetime.now().year):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
|
||||||
|
def updateCreditList(self, creditlist):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from creditList where user_id={} and year_date={}".format(creditlist.user_id, creditlist.year))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
if len(data) == 0:
|
||||||
|
self.createCreditList(creditlist.user_id, creditlist.year)
|
||||||
|
sql = "update creditList set jan_guthaben={}, jan_schulden={},feb_guthaben={}, feb_schulden={}, maer_guthaben={}, maer_schulden={}, apr_guthaben={}, apr_schulden={}, mai_guthaben={}, mai_schulden={}, jun_guthaben={}, jun_schulden={}, jul_guthaben={}, jul_schulden={}, aug_guthaben={}, aug_schulden={},sep_guthaben={}, sep_schulden={},okt_guthaben={}, okt_schulden={}, nov_guthaben={}, nov_schulden={}, dez_guthaben={}, dez_schulden={}, last_schulden={} where year_date={} and user_id={}".format(creditlist.jan_guthaben, creditlist.jan_schulden,
|
||||||
|
creditlist.feb_guthaben, creditlist.feb_schulden,
|
||||||
|
creditlist.maer_guthaben, creditlist.maer_schulden,
|
||||||
|
creditlist.apr_guthaben, creditlist.apr_schulden,
|
||||||
|
creditlist.mai_guthaben, creditlist.mai_schulden,
|
||||||
|
creditlist.jun_guthaben, creditlist.jun_schulden,
|
||||||
|
creditlist.jul_guthaben, creditlist.jul_schulden,
|
||||||
|
creditlist.aug_guthaben, creditlist.aug_schulden,
|
||||||
|
creditlist.sep_guthaben, creditlist.sep_schulden,
|
||||||
|
creditlist.okt_guthaben, creditlist.okt_schulden,
|
||||||
|
creditlist.nov_guthaben, creditlist.nov_schulden,
|
||||||
|
creditlist.dez_guthaben, creditlist.dez_schulden,
|
||||||
|
creditlist.last_schulden, creditlist.year, creditlist.user_id)
|
||||||
|
print(sql)
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
@ -0,0 +1,112 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getAllJobKinds(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute('select * from job_kind')
|
||||||
|
list = cursor.fetchall()
|
||||||
|
for item in list:
|
||||||
|
item['workgroup'] = self.getWorkgroup(item['workgroup']) if item['workgroup'] != None else None
|
||||||
|
return list
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def getJobKind(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if type(name) == str:
|
||||||
|
sql = "select * from job_kind where name='{}'".format(name)
|
||||||
|
elif type(name) == int:
|
||||||
|
sql = 'select * from job_kind where id={}'.format(name)
|
||||||
|
else:
|
||||||
|
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||||
|
cursor.execute(sql)
|
||||||
|
retVal = cursor.fetchone()
|
||||||
|
retVal['workgroup'] = self.getWorkgroup(retVal['workgroup']) if retVal['workgroup'] != None else None
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def setJobKind(self, name, workgroup_id):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into job_kind (name, workgroup) values ('{}', {})".format(name, workgroup_id if workgroup_id != None else 'NULL'))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getJobKind(name)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateJobKind(self, jobkind):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update job_kind set name='{}', workgroup={} where id={}".format(jobkind['name'], jobkind['workgroup']['id'] if jobkind['workgroup'] != None else 'NULL', jobkind['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getJobKind(jobkind['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def deleteJobKind(self, jobkind):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from job_kind where id={}".format(jobkind['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def setJobKindDates(self, date, jobkind, maxpersons):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into job_kind_dates (daydate, job_kind, maxpersons) values ('{}', {}, {})".format(date, jobkind['id'] if jobkind != None else 'NULL', maxpersons))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateJobKindDates(self, jobkindDate):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update job_kind_dates set job_kind={}, maxpersons='{}' where id={}".format(jobkindDate['job_kind']['id'] if jobkindDate['job_kind'] != None else 'NULL', jobkindDate['maxpersons'], jobkindDate['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getJobKindDates(self, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_kind_dates where daydate='{}'".format(date))
|
||||||
|
list = cursor.fetchall()
|
||||||
|
for item in list:
|
||||||
|
item['job_kind'] = self.getJobKind(item['job_kind']) if item['job_kind'] != None else None
|
||||||
|
item['daydate'] = {'year': item['daydate'].year, 'month': item['daydate'].month, 'day': item['daydate'].day}
|
||||||
|
return list
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def deleteJobKindDates(self, jobkinddates):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from job_kind_dates where id={}".format(jobkinddates['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
@ -0,0 +1,110 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from MySQLdb._exceptions import IntegrityError
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getTransactJob(self, from_user, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
if data:
|
||||||
|
return {"from_user": from_user, "to_user": to_user, "date": data['jobdate'], "answerd": data['answerd'], "accepted": data['accepted']}
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getAllTransactJobFromUser(self, from_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_transact where from_user_id={}".format(from_user.id))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
retVal = []
|
||||||
|
for transact in data:
|
||||||
|
if date <= transact['jobdate']:
|
||||||
|
retVal.append({"from_user": from_user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']})
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getAllTransactJobToUser(self, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_transact where to_user_id={}".format(to_user.id))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
retVal = []
|
||||||
|
for transact in data:
|
||||||
|
if date <= transact['jobdate']:
|
||||||
|
retVal.append({"to_user": to_user, "from_user": self.getUserById(transact['from_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']})
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getTransactJobToUser(self, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_transact where to_user_id={} and jobdate='{}'".format(to_user.id, date))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
if data:
|
||||||
|
return {"from_user": self.getUserById(data['from_user_id']), "to_user": to_user, "date": data['jobdate'], "accepted": data['accepted'], "answerd": data['answerd']}
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def updateTransactJob(self, from_user, to_user, date, accepted):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update job_transact set accepted={}, answerd=true where to_user_id={} and jobdate='{}'".format(accepted, to_user.id, date))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getTransactJob(from_user, to_user, date)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getTransactJobFromUser(self, user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_transact where from_user_id={} and jobdate='{}'".format(user.id, date))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
return [{"from_user": user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']} for transact in data]
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def deleteTransactJob(self, from_user, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def setTransactJob(self, from_user, to_user, date):
|
||||||
|
try:
|
||||||
|
exists = self.getTransactJob(from_user, to_user, date)
|
||||||
|
if exists:
|
||||||
|
raise IntegrityError("job_transact already exists")
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into job_transact (jobdate, from_user_id, to_user_id) VALUES ('{}', {}, {})".format(date, from_user.id, to_user.id))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getTransactJob(from_user, to_user, date)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Somethin went wrong with Database: {}".format(err))
|
|
@ -0,0 +1,128 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getPriceList(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from pricelist")
|
||||||
|
return cursor.fetchall()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getDrinkPrice(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if type(name) == str:
|
||||||
|
sql = "select * from pricelist where name='{}'".format(name)
|
||||||
|
elif type(name) == int:
|
||||||
|
sql = 'select * from pricelist where id={}'.format(name)
|
||||||
|
else:
|
||||||
|
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||||
|
cursor.execute(sql)
|
||||||
|
return cursor.fetchone()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def setDrinkPrice(self, drink):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
"insert into pricelist (name, price, price_big, price_club, price_club_big, premium, premium_club, price_extern_club, type) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
|
||||||
|
(
|
||||||
|
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'],
|
||||||
|
drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getDrinkPrice(str(drink['name']))
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def updateDrinkPrice(self, drink):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update pricelist set name=%s, price=%s, price_big=%s, price_club=%s, price_club_big=%s, premium=%s, premium_club=%s, price_extern_club=%s, type=%s where id=%s",
|
||||||
|
(
|
||||||
|
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'], drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type'], drink['id']
|
||||||
|
))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getDrinkPrice(drink['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def deleteDrink(self, drink):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from pricelist where id={}".format(drink['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getDrinkType(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if type(name) == str:
|
||||||
|
sql = "select * from drink_type where name='{}'".format(name)
|
||||||
|
elif type(name) == int:
|
||||||
|
sql = 'select * from drink_type where id={}'.format(name)
|
||||||
|
else:
|
||||||
|
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||||
|
cursor.execute(sql)
|
||||||
|
return cursor.fetchone()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def setDrinkType(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into drink_type (name) values ('{}')".format(name))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getDrinkType(name)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
||||||
|
|
||||||
|
def updateDrinkType(self, type):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update drink_type set name='{}' where id={}".format(type['name'], type['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getDrinkType(type['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
||||||
|
|
||||||
|
def deleteDrinkType(self, type):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from drink_type where id={}".format(type['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getAllDrinkTypes(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute('select * from drink_type')
|
||||||
|
return cursor.fetchall()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Database: {}".format(err))
|
|
@ -0,0 +1,197 @@
|
||||||
|
from geruecht.exceptions import DatabaseExecption, UsernameExistDB
|
||||||
|
from geruecht.model.user import User
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getAllUser(self, extern=False, workgroups=True):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user")
|
||||||
|
data = cursor.fetchall()
|
||||||
|
|
||||||
|
if data:
|
||||||
|
retVal = []
|
||||||
|
for value in data:
|
||||||
|
if extern and value['uid'] == 'extern':
|
||||||
|
continue
|
||||||
|
user = User(value)
|
||||||
|
creditLists = self.getCreditListFromUser(user)
|
||||||
|
user.initGeruechte(creditLists)
|
||||||
|
if workgroups:
|
||||||
|
user.workgroups = self.getWorkgroupsOfUser(user.id)
|
||||||
|
retVal.append(user)
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getUser(self, username, workgroups=True):
|
||||||
|
try:
|
||||||
|
retVal = None
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user where uid='{}'".format(username))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
if data:
|
||||||
|
retVal = User(data)
|
||||||
|
creditLists = self.getCreditListFromUser(retVal)
|
||||||
|
retVal.initGeruechte(creditLists)
|
||||||
|
if workgroups:
|
||||||
|
retVal.workgroups = self.getWorkgroupsOfUser(retVal.id)
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getUserById(self, id, workgroups=True):
|
||||||
|
try:
|
||||||
|
retVal = None
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user where id={}".format(id))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
if data:
|
||||||
|
retVal = User(data)
|
||||||
|
creditLists = self.getCreditListFromUser(retVal)
|
||||||
|
retVal.initGeruechte(creditLists)
|
||||||
|
if workgroups:
|
||||||
|
retVal.workgroups = self.getWorkgroupsOfUser(retVal.id)
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def _convertGroupToString(self, groups):
|
||||||
|
retVal = ''
|
||||||
|
print('groups: {}'.format(groups))
|
||||||
|
if groups:
|
||||||
|
for group in groups:
|
||||||
|
if len(retVal) != 0:
|
||||||
|
retVal += ','
|
||||||
|
retVal += group
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
|
||||||
|
def insertUser(self, user):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
groups = self._convertGroupToString(user.group)
|
||||||
|
cursor.execute("insert into user (uid, dn, firstname, lastname, gruppe, lockLimit, locked, autoLock, mail) VALUES ('{}','{}','{}','{}','{}',{},{},{},'{}')".format(
|
||||||
|
user.uid, user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
|
||||||
|
def updateUser(self, user):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
print('uid: {}; group: {}'.format(user.uid, user.group))
|
||||||
|
groups = self._convertGroupToString(user.group)
|
||||||
|
sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format(
|
||||||
|
user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid)
|
||||||
|
print(sql)
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def changeUsername(self, user, newUsername):
|
||||||
|
try:
|
||||||
|
cursor= self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user where uid='{}'".format(newUsername))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
if data:
|
||||||
|
raise UsernameExistDB("Username already exists")
|
||||||
|
else:
|
||||||
|
cursor.execute("update user set uid='{}' where id={}".format(newUsername, user.id))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getAllStatus(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute('select * from statusgroup')
|
||||||
|
return cursor.fetchall()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def getStatus(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if type(name) == str:
|
||||||
|
sql = "select * from statusgroup where name='{}'".format(name)
|
||||||
|
elif type(name) == int:
|
||||||
|
sql = 'select * from statusgroup where id={}'.format(name)
|
||||||
|
else:
|
||||||
|
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||||
|
cursor.execute(sql)
|
||||||
|
return cursor.fetchone()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def setStatus(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into statusgroup (name) values ('{}')".format(name))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getStatus(name)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateStatus(self, status):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update statusgroup set name='{}' where id={}".format(status['name'], status['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getStatus(status['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def deleteStatus(self, status):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from statusgroup where id={}".format(status['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateStatusOfUser(self, username, status):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update user set statusgroup={} where uid='{}'".format(status['id'], username))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getUser(username)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateVotingOfUser(self, username, voting):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update user set voting={} where uid='{}'".format(voting, username))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getUser(username)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
|
@ -0,0 +1,67 @@
|
||||||
|
import traceback
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getWorker(self, user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date))
|
||||||
|
data = cursor.fetchone()
|
||||||
|
return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}, "job_kind": self.getJobKind(data['job_kind']) if data['job_kind'] != None else None} if data else None
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getWorkers(self, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from bardienste where startdatetime='{}'".format(date))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
retVal = []
|
||||||
|
# for work in data:
|
||||||
|
# user = self.getUserById(work['user_id']).toJSON()
|
||||||
|
# startdatetime = work['startdatetime']
|
||||||
|
# enddatetime = work['enddatetime']
|
||||||
|
# start = { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}
|
||||||
|
# job_kind = self.getJobKind(work['job_kind']) if work['job_kind'] != None else None
|
||||||
|
# retVal.append({'user': user, 'startdatetime': startdatetime, 'enddatetime': enddatetime, 'start': start, 'job_kind': job_kind})
|
||||||
|
# return retVal
|
||||||
|
return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}, "job_kind": self.getJobKind(work['job_kind']) if work['job_kind'] != None else None} for work in data]
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def setWorker(self, user, date, job_kind=None):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into bardienste (user_id, startdatetime, enddatetime, job_kind) values ({},'{}','{}', {})".format(user.id, date, date + timedelta(days=1), job_kind['id'] if job_kind != None else 'NULL'))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def deleteAllWorkerWithJobKind(self, date, job_kind):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from bardienste where startdatetime='{}' and job_kind={}".format(date, job_kind['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def deleteWorker(self, user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from bardienste where user_id={} and startdatetime='{}'".format(user.id, date))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
@ -0,0 +1,126 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getAllWorkgroups(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute('select * from workgroup')
|
||||||
|
list = cursor.fetchall()
|
||||||
|
for item in list:
|
||||||
|
if item['boss'] != None:
|
||||||
|
item['boss']=self.getUserById(item['boss'], workgroups=False).toJSON()
|
||||||
|
return list
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def getWorkgroup(self, name):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if type(name) == str:
|
||||||
|
sql = "select * from workgroup where name='{}'".format(name)
|
||||||
|
elif type(name) == int:
|
||||||
|
sql = 'select * from workgroup where id={}'.format(name)
|
||||||
|
else:
|
||||||
|
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||||
|
cursor.execute(sql)
|
||||||
|
retVal = cursor.fetchone()
|
||||||
|
retVal['boss'] = self.getUserById(retVal['boss'], workgroups=False).toJSON() if retVal['boss'] != None else None
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def setWorkgroup(self, name, boss):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into workgroup (name, boss) values ('{}', {})".format(name, boss['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getWorkgroup(name)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def updateWorkgroup(self, workgroup):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update workgroup set name='{}', boss={} where id={}".format(workgroup['name'], workgroup['boss']['id'], workgroup['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getWorkgroup(workgroup['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def deleteWorkgroup(self, workgroup):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from workgroup where id={}".format(workgroup['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||||
|
|
||||||
|
def getWorkgroupsOfUser(self, userid):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user_workgroup where user_id={} ".format(userid))
|
||||||
|
knots = cursor.fetchall()
|
||||||
|
retVal = [self.getWorkgroup(knot['workgroup_id']) for knot in knots]
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getUsersOfWorkgroups(self, workgroupid):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user_workgroup where workgroup_id={}".format(workgroupid))
|
||||||
|
knots = cursor.fetchall()
|
||||||
|
retVal = [self.getUserById(knot['user_id'], workgroups=False).toJSON() for knot in knots]
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def getUserWorkgroup(self, user, workgroup):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from user_workgroup where workgroup_id={} and user_id={}".format(workgroup['id'], user['id']))
|
||||||
|
knot = cursor.fetchone()
|
||||||
|
retVal = {"workgroup": self.getWorkgroup(workgroup['id']), "user": self.getUserById(user['id'], workgroups=False).toJSON()}
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def setUserWorkgroup(self, user, workgroup):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into user_workgroup (user_id, workgroup_id) VALUES ({}, {})".format(user['id'], workgroup['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getUserWorkgroup(user, workgroup)
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||||
|
|
||||||
|
def deleteWorkgroupsOfUser(self, user):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from user_workgroup where user_id={}".format(user['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
@ -4,23 +4,22 @@ from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from geruecht.logger import getDebugLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
from . import mailConfig
|
||||||
|
|
||||||
debug = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
class EmailController():
|
class EmailController():
|
||||||
|
|
||||||
def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""):
|
def __init__(self):
|
||||||
debug.info("init email controller")
|
debug.info("init email controller")
|
||||||
self.smtpServer = smtpServer
|
self.smtpServer = mailConfig['URL']
|
||||||
self.port = port
|
self.port = mailConfig['port']
|
||||||
self.user = user
|
self.user = mailConfig['user']
|
||||||
self.passwd = passwd
|
self.passwd = mailConfig['passwd']
|
||||||
self.crypt = crypt
|
self.crypt = mailConfig['crypt']
|
||||||
if email:
|
self.email = mailConfig['email']
|
||||||
self.email = email
|
|
||||||
else:
|
debug.debug("smtpServer is {{ {} }}, port is {{ {} }}, user is {{ {} }}, crypt is {{ {} }}, email is {{ {} }}".format(self.smtpServer, self.port, self.user, self.crypt, self.email))
|
||||||
self.email = user
|
|
||||||
debug.debug("smtpServer is {{ {} }}, port is {{ {} }}, user is {{ {} }}, crypt is {{ {} }}, email is {{ {} }}".format(smtpServer, port, user, crypt, self.email))
|
|
||||||
|
|
||||||
def __connect__(self):
|
def __connect__(self):
|
||||||
debug.info('connect to email server')
|
debug.info('connect to email server')
|
||||||
|
|
|
@ -71,6 +71,8 @@ class LDAPController(metaclass=Singleton):
|
||||||
main_group_number = self.ldap.connection.response[0]['attributes']['gidNumber']
|
main_group_number = self.ldap.connection.response[0]['attributes']['gidNumber']
|
||||||
debug.debug("main group number is {{ {} }}".format(main_group_number))
|
debug.debug("main group number is {{ {} }}".format(main_group_number))
|
||||||
if main_group_number:
|
if main_group_number:
|
||||||
|
if type(main_group_number) is list:
|
||||||
|
main_group_number = main_group_number[0]
|
||||||
self.ldap.connection.search('ou=group,{}'.format(self.dn), '(gidNumber={})'.format(main_group_number), attributes=['cn'])
|
self.ldap.connection.search('ou=group,{}'.format(self.dn), '(gidNumber={})'.format(main_group_number), attributes=['cn'])
|
||||||
group_name = self.ldap.connection.response[0]['attributes']['cn'][0]
|
group_name = self.ldap.connection.response[0]['attributes']['cn'][0]
|
||||||
debug.debug("group name is {{ {} }}".format(group_name))
|
debug.debug("group name is {{ {} }}".format(group_name))
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
from .. import Singleton, mailConfig
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
import geruecht.controller.ldapController as lc
|
||||||
|
import geruecht.controller.emailController as ec
|
||||||
|
from geruecht.model.user import User
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
from ..mainController import mainJobKindController, mainCreditListController, mainJobTransactController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
ldap = lc.LDAPController()
|
||||||
|
emailController = ec.EmailController()
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class MainController(mainJobKindController.Base,
|
||||||
|
mainCreditListController.Base,
|
||||||
|
mainJobTransactController.Base,
|
||||||
|
mainPricelistController.Base,
|
||||||
|
mainUserController.Base,
|
||||||
|
mainWorkerController.Base,
|
||||||
|
mainWorkgroupController.Base,
|
||||||
|
metaclass=Singleton):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
debug.debug("init UserController")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setLockedDay(self, date, locked, hard=False):
|
||||||
|
debug.info(
|
||||||
|
"set day locked on {{ {} }} with state {{ {} }}".format(date, locked))
|
||||||
|
retVal = db.setLockedDay(date.date(), locked, hard)
|
||||||
|
debug.debug("seted day locked is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getLockedDays(self, from_date, to_date):
|
||||||
|
debug.info("get locked days from {{ {} }} to {{ {} }}".format(
|
||||||
|
from_date.date(), to_date.date()))
|
||||||
|
oneDay = timedelta(1)
|
||||||
|
delta = to_date.date() - from_date.date()
|
||||||
|
retVal = []
|
||||||
|
startdate = from_date - oneDay
|
||||||
|
for _ in range(delta.days + 1):
|
||||||
|
startdate += oneDay
|
||||||
|
lockday = self.getLockedDay(startdate)
|
||||||
|
retVal.append(lockday)
|
||||||
|
debug.debug("lock days are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getLockedDay(self, date):
|
||||||
|
debug.info("get locked day on {{ {} }}".format(date))
|
||||||
|
now = datetime.now()
|
||||||
|
debug.debug("now is {{ {} }}".format(now))
|
||||||
|
oldMonth = False
|
||||||
|
debug.debug("check if date old month or current month")
|
||||||
|
for i in range(1, 8):
|
||||||
|
if datetime(now.year, now.month, i).weekday() == 2:
|
||||||
|
if now.day < i:
|
||||||
|
oldMonth = True
|
||||||
|
break
|
||||||
|
debug.debug("oldMonth is {{ {} }}".format(oldMonth))
|
||||||
|
lockedYear = now.year
|
||||||
|
lockedMonth = now.month if now.month < now.month else now.month - \
|
||||||
|
1 if oldMonth else now.month
|
||||||
|
endDay = 1
|
||||||
|
debug.debug("calculate end day of month")
|
||||||
|
lockedYear = lockedYear if lockedMonth != 12 else (lockedYear + 1)
|
||||||
|
lockedMonth = (lockedMonth + 1) if lockedMonth != 12 else 1
|
||||||
|
for i in range(1, 8):
|
||||||
|
nextMonth = datetime(lockedYear, lockedMonth, i)
|
||||||
|
if nextMonth.weekday() == 2:
|
||||||
|
endDay = i
|
||||||
|
break
|
||||||
|
|
||||||
|
monthLockedEndDate = datetime(
|
||||||
|
lockedYear, lockedMonth, endDay) - timedelta(1)
|
||||||
|
debug.debug("get lock day from database")
|
||||||
|
retVal = db.getLockedDay(date.date())
|
||||||
|
if not retVal:
|
||||||
|
debug.debug(
|
||||||
|
"lock day not exists, retVal is {{ {} }}".format(retVal))
|
||||||
|
if date.date() <= monthLockedEndDate.date():
|
||||||
|
debug.debug("lock day {{ {} }}".format(date.date()))
|
||||||
|
self.setLockedDay(date, True)
|
||||||
|
retVal = db.getLockedDay(date.date())
|
||||||
|
else:
|
||||||
|
retVal = {"daydate": date.date(), "locked": False}
|
||||||
|
debug.debug("locked day is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def __updateDataFromLDAP(self, user):
|
||||||
|
debug.info("update data from ldap for user {{ {} }}".format(user))
|
||||||
|
groups = ldap.getGroup(user.uid)
|
||||||
|
debug.debug("ldap gorups are {{ {} }}".format(groups))
|
||||||
|
user_data = ldap.getUserData(user.uid)
|
||||||
|
debug.debug("ldap data is {{ {} }}".format(user_data))
|
||||||
|
user_data['gruppe'] = groups
|
||||||
|
user_data['group'] = groups
|
||||||
|
user.updateData(user_data)
|
||||||
|
db.updateUser(user)
|
||||||
|
|
||||||
|
def checkBarUser(self, user):
|
||||||
|
debug.info("check if user {{ {} }} is baruser")
|
||||||
|
date = datetime.now()
|
||||||
|
zero = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
end = zero + timedelta(hours=12)
|
||||||
|
startdatetime = date.replace(
|
||||||
|
hour=12, minute=0, second=0, microsecond=0)
|
||||||
|
if date > zero and end > date:
|
||||||
|
startdatetime = startdatetime - timedelta(days=1)
|
||||||
|
enddatetime = startdatetime + timedelta(days=1)
|
||||||
|
debug.debug("startdatetime is {{ {} }} and enddatetime is {{ {} }}".format(
|
||||||
|
startdatetime, end))
|
||||||
|
result = False
|
||||||
|
if date >= startdatetime and date < enddatetime:
|
||||||
|
result = db.getWorker(user, startdatetime)
|
||||||
|
debug.debug("worker is {{ {} }}".format(result))
|
||||||
|
return True if result else False
|
||||||
|
|
||||||
|
def sendMail(self, username):
|
||||||
|
debug.info("send mail to user {{ {} }}".format(username))
|
||||||
|
if type(username) == User:
|
||||||
|
user = username
|
||||||
|
if type(username) == str:
|
||||||
|
user = db.getUser(username)
|
||||||
|
retVal = emailController.sendMail(user)
|
||||||
|
debug.debug("send mail is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def sendAllMail(self):
|
||||||
|
debug.info("send mail to all user")
|
||||||
|
retVal = []
|
||||||
|
users = db.getAllUser()
|
||||||
|
debug.debug("users are {{ {} }}".format(users))
|
||||||
|
for user in users:
|
||||||
|
retVal.append(self.sendMail(user))
|
||||||
|
debug.debug("send mails are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
import geruecht.controller.emailController as ec
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
emailController = ec.EmailController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def autoLock(self, user):
|
||||||
|
debug.info("start autolock of user {{ {} }}".format(user))
|
||||||
|
if user.autoLock:
|
||||||
|
debug.debug("autolock is active")
|
||||||
|
credit = user.getGeruecht(year=datetime.now().year).getSchulden()
|
||||||
|
limit = -1*user.limit
|
||||||
|
if credit <= limit:
|
||||||
|
debug.debug(
|
||||||
|
"credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit))
|
||||||
|
debug.debug("lock user")
|
||||||
|
user.updateData({'locked': True})
|
||||||
|
debug.debug("send mail to user")
|
||||||
|
emailController.sendMail(user)
|
||||||
|
else:
|
||||||
|
debug.debug(
|
||||||
|
"cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit))
|
||||||
|
debug.debug("unlock user")
|
||||||
|
user.updateData({'locked': False})
|
||||||
|
db.updateUser(user)
|
||||||
|
|
||||||
|
def addAmount(self, username, amount, year, month, finanzer=False):
|
||||||
|
debug.info("add amount {{ {} }} to user {{ {} }} no month {{ {} }}, year {{ {} }}".format(
|
||||||
|
amount, username, month, year))
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
if user.uid == 'extern':
|
||||||
|
debug.debug("user is extern user, so exit add amount")
|
||||||
|
return
|
||||||
|
if not user.locked or finanzer:
|
||||||
|
debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format(
|
||||||
|
user.locked, finanzer))
|
||||||
|
user.addAmount(amount, year=year, month=month)
|
||||||
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditList is {{ {} }}".format(creditLists))
|
||||||
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{ {} }}".format(creditList))
|
||||||
|
db.updateCreditList(creditList)
|
||||||
|
debug.debug("do autolock")
|
||||||
|
self.autoLock(user)
|
||||||
|
retVal = user.getGeruecht(year)
|
||||||
|
debug.debug("updated creditlists is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def addCredit(self, username, credit, year, month):
|
||||||
|
debug.info("add credit {{ {} }} to user {{ {} }} on month {{ {} }}, year {{ {} }}".format(
|
||||||
|
credit, username, month, year))
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
if user.uid == 'extern':
|
||||||
|
debug.debug("user is extern user, so exit add credit")
|
||||||
|
return
|
||||||
|
user.addCredit(credit, year=year, month=month)
|
||||||
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditlists are {{ {} }}".format(creditLists))
|
||||||
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{ {} }}".format(creditList))
|
||||||
|
db.updateCreditList(creditList)
|
||||||
|
debug.debug("do autolock")
|
||||||
|
self.autoLock(user)
|
||||||
|
retVal = user.getGeruecht(year)
|
||||||
|
debug.debug("updated creditlists are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def __updateGeruechte(self, user):
|
||||||
|
debug.debug("update creditlists")
|
||||||
|
user.getGeruecht(datetime.now().year)
|
||||||
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditlists are {{ {} }}".format(creditLists))
|
||||||
|
if user.getGeruecht(datetime.now().year).getSchulden() != 0:
|
||||||
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{ {} }}".format(creditList))
|
||||||
|
db.updateCreditList(creditList)
|
|
@ -0,0 +1,89 @@
|
||||||
|
from datetime import date, timedelta, datetime, time
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getAllJobKinds(self):
|
||||||
|
debug.info("get all jobkinds")
|
||||||
|
retVal = db.getAllJobKinds()
|
||||||
|
debug.debug("jobkinds are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getJobKind(self, name):
|
||||||
|
debug.info("get jobkinds {{ {} }}".format(name))
|
||||||
|
retVal = db.getJobKind(name)
|
||||||
|
debug.debug("jobkind is {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setJobKind(self, name, workgroup=None):
|
||||||
|
debug.info("set jobkind {{ {} }} ".format(name))
|
||||||
|
retVal = db.setJobKind(name, workgroup)
|
||||||
|
debug.debug(
|
||||||
|
"seted jobkind {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteJobKind(self, jobkind):
|
||||||
|
debug.info("delete jobkind {{ {} }}".format(jobkind))
|
||||||
|
db.deleteJobKind(jobkind)
|
||||||
|
|
||||||
|
def updateJobKind(self, jobkind):
|
||||||
|
debug.info("update workgroup {{ {} }}".format(jobkind))
|
||||||
|
retVal = db.updateJobKind(jobkind)
|
||||||
|
debug.debug("updated jobkind is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getJobKindDates(self, date):
|
||||||
|
debug.info("get jobkinddates on {{ {} }}".format(date))
|
||||||
|
retVal = db.getJobKindDates(date)
|
||||||
|
debug.debug("jobkinddates are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateJobKindDates(self, jobkindDate):
|
||||||
|
debug.info("update jobkinddate {{ {} }}".format(jobkindDate))
|
||||||
|
retVal = db.updateJobKindDates(jobkindDate)
|
||||||
|
debug.debug("updated jobkind is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteJobKindDates(self, jobkinddates):
|
||||||
|
debug.info("delete jobkinddates {{ {} }}".format(jobkinddates))
|
||||||
|
db.deleteJobKindDates(jobkinddates)
|
||||||
|
|
||||||
|
def setJobKindDates(self, datum, jobkind, maxpersons):
|
||||||
|
debug.info("set jobkinddates with {{ {}, {}, {}, }}".format(datum, jobkind, maxpersons))
|
||||||
|
retVal = db.setJobKindDates(datum, jobkind, maxpersons)
|
||||||
|
debug.debug("seted jobkinddates is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def controllJobKindDates(self, jobkinddates):
|
||||||
|
debug.info("controll jobkinddates {{ {} }}".format(jobkinddates))
|
||||||
|
datum = None
|
||||||
|
for jobkinddate in jobkinddates:
|
||||||
|
datum = date(jobkinddate['daydate']['year'], jobkinddate['daydate']['month'], jobkinddate['daydate']['day'])
|
||||||
|
if jobkinddate['id'] == -1:
|
||||||
|
self.setJobKindDates(datum, jobkinddate['job_kind'], jobkinddate['maxpersons'])
|
||||||
|
if jobkinddate['id'] == 0:
|
||||||
|
jobkinddate['id'] = jobkinddate['backupid']
|
||||||
|
db.deleteAllWorkerWithJobKind(datetime.combine(datum, time(12)), jobkinddate['job_kind'])
|
||||||
|
self.deleteJobKindDates(jobkinddate)
|
||||||
|
if jobkinddate['id'] >= 1:
|
||||||
|
self.updateJobKindDates(jobkinddate)
|
||||||
|
retVal = self.getJobKindDates(datum) if datum != None else []
|
||||||
|
debug.debug("controlled jobkinddates {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getJobKindDatesFromTo(self, from_date, to_date):
|
||||||
|
debug.info("get locked days from {{ {} }} to {{ {} }}".format(
|
||||||
|
from_date.date(), to_date.date()))
|
||||||
|
oneDay = timedelta(1)
|
||||||
|
delta = to_date.date() - from_date.date()
|
||||||
|
retVal = []
|
||||||
|
startdate = from_date - oneDay
|
||||||
|
for _ in range(delta.days + 1):
|
||||||
|
startdate += oneDay
|
||||||
|
jobkinddate = self.getJobKindDates(startdate)
|
||||||
|
retVal.append(jobkinddate)
|
||||||
|
debug.debug("lock days are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
|
@ -0,0 +1,71 @@
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
import geruecht.controller.emailController as ec
|
||||||
|
from geruecht.exceptions import TansactJobIsAnswerdException
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
emailController = ec.EmailController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def setTransactJob(self, from_user, to_user, date):
|
||||||
|
debug.info("set transact job from {{ {} }} to {{ {} }} on {{ {} }}".format(
|
||||||
|
from_user, to_user, date))
|
||||||
|
jobtransact = db.setTransactJob(from_user, to_user, date.date())
|
||||||
|
debug.debug("transact job is {{ {} }}".format(jobtransact))
|
||||||
|
debug.info("send mail with transact job to user")
|
||||||
|
emailController.sendMail(
|
||||||
|
jobtransact['to_user'], 'jobtransact', jobtransact)
|
||||||
|
return jobtransact
|
||||||
|
|
||||||
|
def getTransactJobFromUser(self, user, date):
|
||||||
|
debug.info(
|
||||||
|
"get transact job from user {{ {} }} on {{ {} }}".format(user, date))
|
||||||
|
retVal = db.getTransactJobFromUser(user, date.date())
|
||||||
|
debug.debug(
|
||||||
|
"transact job from user {{ {} }} is {{ {} }}".format(user, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getAllTransactJobFromUser(self, user, date):
|
||||||
|
debug.info(
|
||||||
|
"get all transact job from user {{ {} }} start on {{ {} }}".format(user, date))
|
||||||
|
retVal = db.getAllTransactJobFromUser(user, date.date())
|
||||||
|
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getAllTransactJobToUser(self, user, date):
|
||||||
|
debug.info(
|
||||||
|
"get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date))
|
||||||
|
retVal = db.getAllTransactJobToUser(user, date.date())
|
||||||
|
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getTransactJob(self, from_user, to_user, date):
|
||||||
|
debug.info("get transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
||||||
|
from_user, to_user, date))
|
||||||
|
retVal = db.getTransactJob(from_user, to_user, date.date())
|
||||||
|
debug.debug("transact job is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteTransactJob(self, from_user, to_user, date):
|
||||||
|
debug.info("delete transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
||||||
|
from_user, to_user, date))
|
||||||
|
transactJob = self.getTransactJob(from_user, to_user, date)
|
||||||
|
debug.debug("transact job is {{ {} }}".format(transactJob))
|
||||||
|
if transactJob['answerd']:
|
||||||
|
debug.warning(
|
||||||
|
"transactjob {{ {} }} can not delete because is answerd")
|
||||||
|
raise TansactJobIsAnswerdException(
|
||||||
|
"TransactJob is already answerd")
|
||||||
|
db.deleteTransactJob(from_user, to_user, date.date())
|
||||||
|
|
||||||
|
def answerdTransactJob(self, from_user, to_user, date, answer):
|
||||||
|
debug.info("answer transact job from user {{ {} }} to user {{ {} }} on {{ {} }} with answer {{ {} }}".format(
|
||||||
|
from_user, to_user, date, answer))
|
||||||
|
transactJob = db.updateTransactJob(
|
||||||
|
from_user, to_user, date.date(), answer)
|
||||||
|
debug.debug("transactjob is {{ {} }}".format(transactJob))
|
||||||
|
if answer:
|
||||||
|
debug.info("add worker on date {{ {} }}".format(date))
|
||||||
|
self.addWorker(to_user.uid, date)
|
||||||
|
return transactJob
|
|
@ -0,0 +1,50 @@
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def deleteDrinkType(self, type):
|
||||||
|
debug.info("delete drink type {{ {} }}".format(type))
|
||||||
|
db.deleteDrinkType(type)
|
||||||
|
|
||||||
|
def updateDrinkType(self, type):
|
||||||
|
debug.info("update drink type {{ {} }}".format(type))
|
||||||
|
retVal = db.updateDrinkType(type)
|
||||||
|
debug.debug("updated drink type is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setDrinkType(self, type):
|
||||||
|
debug.info("set drink type {{ {} }}".format(type))
|
||||||
|
retVal = db.setDrinkType(type)
|
||||||
|
debug.debug("seted drink type is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deletDrinkPrice(self, drink):
|
||||||
|
debug.info("delete drink {{ {} }}".format(drink))
|
||||||
|
db.deleteDrink(drink)
|
||||||
|
|
||||||
|
def setDrinkPrice(self, drink):
|
||||||
|
debug.info("set drink {{ {} }}".format(drink))
|
||||||
|
retVal = db.setDrinkPrice(drink)
|
||||||
|
debug.debug("seted drink is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateDrinkPrice(self, drink):
|
||||||
|
debug.info("update drink {{ {} }}".format(drink))
|
||||||
|
retVal = db.updateDrinkPrice(drink)
|
||||||
|
debug.debug("updated drink is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getAllDrinkTypes(self):
|
||||||
|
debug.info("get all drink types")
|
||||||
|
retVal = db.getAllDrinkTypes()
|
||||||
|
debug.debug("all drink types are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getPricelist(self):
|
||||||
|
debug.info("get all drinks")
|
||||||
|
list = db.getPriceList()
|
||||||
|
debug.debug("all drinks are {{ {} }}".format(list))
|
||||||
|
return list
|
|
@ -0,0 +1,160 @@
|
||||||
|
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion, PermissionDenied
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
import geruecht.controller.ldapController as lc
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
ldap = lc.LDAPController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getAllStatus(self):
|
||||||
|
debug.info("get all status for user")
|
||||||
|
retVal = db.getAllStatus()
|
||||||
|
debug.debug("status are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getStatus(self, name):
|
||||||
|
debug.info("get status of user {{ {} }}".format(name))
|
||||||
|
retVal = db.getStatus(name)
|
||||||
|
debug.debug("status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setStatus(self, name):
|
||||||
|
debug.info("set status of user {{ {} }}".format(name))
|
||||||
|
retVal = db.setStatus(name)
|
||||||
|
debug.debug(
|
||||||
|
"settet status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteStatus(self, status):
|
||||||
|
debug.info("delete status {{ {} }}".format(status))
|
||||||
|
db.deleteStatus(status)
|
||||||
|
|
||||||
|
def updateStatus(self, status):
|
||||||
|
debug.info("update status {{ {} }}".format(status))
|
||||||
|
retVal = db.updateStatus(status)
|
||||||
|
debug.debug("updated status is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateStatusOfUser(self, username, status):
|
||||||
|
debug.info("update status {{ {} }} of user {{ {} }}".format(
|
||||||
|
status, username))
|
||||||
|
retVal = db.updateStatusOfUser(username, status)
|
||||||
|
debug.debug(
|
||||||
|
"updatet status of user {{ {} }} is {{ {} }}".format(username, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateVotingOfUser(self, username, voting):
|
||||||
|
debug.info("update voting {{ {} }} of user {{ {} }}".format(
|
||||||
|
voting, username))
|
||||||
|
retVal = db.updateVotingOfUser(username, voting)
|
||||||
|
debug.debug(
|
||||||
|
"updatet voting of user {{ {} }} is {{ {} }}".format(username, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def lockUser(self, username, locked):
|
||||||
|
debug.info("lock user {{ {} }} for credit with status {{ {} }}".format(
|
||||||
|
username, locked))
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
user.updateData({'locked': locked})
|
||||||
|
db.updateUser(user)
|
||||||
|
retVal = self.getUser(username)
|
||||||
|
debug.debug("locked user is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateConfig(self, username, data):
|
||||||
|
debug.info(
|
||||||
|
"update config of user {{ {} }} with config {{ {} }}".format(username, data))
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
user.updateData(data)
|
||||||
|
db.updateUser(user)
|
||||||
|
retVal = self.getUser(username)
|
||||||
|
debug.debug("updated config of user is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getAllUsersfromDB(self, extern=True):
|
||||||
|
debug.info("get all users from database")
|
||||||
|
users = db.getAllUser()
|
||||||
|
debug.debug("users are {{ {} }}".format(users))
|
||||||
|
for user in users:
|
||||||
|
try:
|
||||||
|
debug.debug("update data from ldap")
|
||||||
|
self.__updateDataFromLDAP(user)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
debug.debug("update creditlists")
|
||||||
|
self.__updateGeruechte(user)
|
||||||
|
retVal = db.getAllUser(extern=extern)
|
||||||
|
debug.debug("all users are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getUser(self, username):
|
||||||
|
debug.info("get user {{ {} }}".format(username))
|
||||||
|
user = db.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
groups = ldap.getGroup(username)
|
||||||
|
debug.debug("groups are {{ {} }}".format(groups))
|
||||||
|
user_data = ldap.getUserData(username)
|
||||||
|
debug.debug("user data from ldap is {{ {} }}".format(user_data))
|
||||||
|
user_data['gruppe'] = groups
|
||||||
|
user_data['group'] = groups
|
||||||
|
if user is None:
|
||||||
|
debug.debug("user not exists in database -> insert into database")
|
||||||
|
user = User(user_data)
|
||||||
|
db.insertUser(user)
|
||||||
|
else:
|
||||||
|
debug.debug("update database with user")
|
||||||
|
user.updateData(user_data)
|
||||||
|
db.updateUser(user)
|
||||||
|
user = db.getUser(username)
|
||||||
|
self.__updateGeruechte(user)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
return user
|
||||||
|
|
||||||
|
def modifyUser(self, user, ldap_conn, attributes):
|
||||||
|
debug.info("modify user {{ {} }} with attributes {{ {} }} with ldap_conn {{ {} }}".format(
|
||||||
|
user, attributes, ldap_conn))
|
||||||
|
try:
|
||||||
|
if 'username' in attributes:
|
||||||
|
debug.debug("change username, so change first in database")
|
||||||
|
db.changeUsername(user, attributes['username'])
|
||||||
|
ldap.modifyUser(user, ldap_conn, attributes)
|
||||||
|
if 'username' in attributes:
|
||||||
|
retVal = self.getUser(attributes['username'])
|
||||||
|
debug.debug("user is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
else:
|
||||||
|
retVal = self.getUser(user.uid)
|
||||||
|
debug.debug("user is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
except UsernameExistLDAP as err:
|
||||||
|
debug.debug(
|
||||||
|
"username exists on ldap, rechange username on database", exc_info=True)
|
||||||
|
db.changeUsername(user, user.uid)
|
||||||
|
raise Exception(err)
|
||||||
|
except LDAPExcetpion as err:
|
||||||
|
if 'username' in attributes:
|
||||||
|
db.changeUsername(user, user.uid)
|
||||||
|
raise Exception(err)
|
||||||
|
except Exception as err:
|
||||||
|
raise Exception(err)
|
||||||
|
|
||||||
|
def validateUser(self, username, password):
|
||||||
|
debug.info("validate user {{ {} }}".format(username))
|
||||||
|
ldap.login(username, password)
|
||||||
|
|
||||||
|
def loginUser(self, username, password):
|
||||||
|
debug.info("login user {{ {} }}".format(username))
|
||||||
|
try:
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
user.password = password
|
||||||
|
ldap.login(username, password)
|
||||||
|
ldap_conn = ldap.bind(user, password)
|
||||||
|
return user, ldap_conn
|
||||||
|
except PermissionDenied as err:
|
||||||
|
debug.debug("permission is denied", exc_info=True)
|
||||||
|
raise err
|
|
@ -0,0 +1,65 @@
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
from geruecht.exceptions import DayLocked
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getWorker(self, date, username=None):
|
||||||
|
debug.info("get worker {{ {} }} on {{ {} }}".format(username, date))
|
||||||
|
if (username):
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
retVal = [db.getWorker(user, date)]
|
||||||
|
debug.debug("worker is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
retVal = db.getWorkers(date)
|
||||||
|
debug.debug("workers are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def addWorker(self, username, date, job_kind=None, userExc=False):
|
||||||
|
debug.info("add job user {{ {} }} on {{ {} }} with job_kind {{ {} }}".format(username, date, job_kind))
|
||||||
|
if (userExc):
|
||||||
|
debug.debug("this is a user execution, check if day is locked")
|
||||||
|
lockedDay = self.getLockedDay(date)
|
||||||
|
if lockedDay:
|
||||||
|
if lockedDay['locked']:
|
||||||
|
debug.debug("day is lockey. user cant get job")
|
||||||
|
raise DayLocked("Day is locked. You can't get the Job")
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
debug.debug("check if user has job on date")
|
||||||
|
if (not db.getWorker(user, date)):
|
||||||
|
debug.debug("set job to user")
|
||||||
|
db.setWorker(user, date, job_kind=job_kind)
|
||||||
|
retVal = self.getWorker(date, username=username)
|
||||||
|
debug.debug("worker on date is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteWorker(self, username, date, userExc=False):
|
||||||
|
debug.info(
|
||||||
|
"delete worker {{ {} }} on date {{ {} }}".format(username, date))
|
||||||
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
|
if userExc:
|
||||||
|
debug.debug("is user execution, check if day locked")
|
||||||
|
lockedDay = self.getLockedDay(date)
|
||||||
|
if lockedDay:
|
||||||
|
if lockedDay['locked']:
|
||||||
|
debug.debug(
|
||||||
|
"day is locked, check if accepted transact job exists")
|
||||||
|
transactJobs = self.getTransactJobFromUser(user, date)
|
||||||
|
debug.debug(
|
||||||
|
"transact job is {{ {} }}".format(transactJobs))
|
||||||
|
found = False
|
||||||
|
for job in transactJobs:
|
||||||
|
if job['accepted'] and job['answerd']:
|
||||||
|
debug.debug("accepted transact job exists")
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
debug.debug("no accepted transact job found")
|
||||||
|
raise DayLocked(
|
||||||
|
"Day is locked. You can't delete the Job")
|
||||||
|
db.deleteWorker(user, date)
|
|
@ -0,0 +1,42 @@
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def updateWorkgroupsOfUser(self, user, workgroups):
|
||||||
|
debug.info("update workgroups {{ {} }} of user {{ {} }}".format(workgroups, user))
|
||||||
|
db.deleteWorkgroupsOfUser(user)
|
||||||
|
for workgroup in workgroups:
|
||||||
|
db.setUserWorkgroup(user, workgroup)
|
||||||
|
return db.getWorkgroupsOfUser(user['id'])
|
||||||
|
|
||||||
|
def getAllWorkgroups(self):
|
||||||
|
debug.info("get all workgroups")
|
||||||
|
retVal = db.getAllWorkgroups()
|
||||||
|
debug.debug("workgroups are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def getWorkgroups(self, name):
|
||||||
|
debug.info("get Workgroup {{ {} }}".format(name))
|
||||||
|
retVal = db.getWorkgroup(name)
|
||||||
|
debug.debug("workgroup is {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setWorkgroup(self, name, boss):
|
||||||
|
debug.info("set workgroup {{ {} }} with boss {{ {} }}".format(name, boss))
|
||||||
|
retVal = db.setWorkgroup(name, boss)
|
||||||
|
debug.debug(
|
||||||
|
"seted workgroup {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def deleteWorkgroup(self, workgroup):
|
||||||
|
debug.info("delete workgroup {{ {} }}".format(workgroup))
|
||||||
|
db.deleteWorkgroup(workgroup)
|
||||||
|
|
||||||
|
def updateWorkgroup(self, workgroup):
|
||||||
|
debug.info("update workgroup {{ {} }}".format(workgroup))
|
||||||
|
retVal = db.updateWorkgroup(workgroup)
|
||||||
|
debug.debug("updated workgroup is {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
|
@ -1,588 +0,0 @@
|
||||||
from . import Singleton, mailConfig
|
|
||||||
import geruecht.controller.databaseController as dc
|
|
||||||
import geruecht.controller.ldapController as lc
|
|
||||||
import geruecht.controller.emailController as ec
|
|
||||||
import calendar
|
|
||||||
from geruecht.model.user import User
|
|
||||||
from geruecht.exceptions import PermissionDenied
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion, DayLocked, TansactJobIsAnswerdException
|
|
||||||
from geruecht.logger import getDebugLogger
|
|
||||||
|
|
||||||
db = dc.DatabaseController()
|
|
||||||
ldap = lc.LDAPController()
|
|
||||||
emailController = ec.EmailController(
|
|
||||||
mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email'])
|
|
||||||
|
|
||||||
debug = getDebugLogger()
|
|
||||||
|
|
||||||
|
|
||||||
class UserController(metaclass=Singleton):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
debug.debug("init UserController")
|
|
||||||
pass
|
|
||||||
|
|
||||||
def getAllJobKinds(self):
|
|
||||||
debug.info("get all jobkinds")
|
|
||||||
retVal = db.getAllJobKinds()
|
|
||||||
debug.debug("jobkinds are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getJobKind(self, name):
|
|
||||||
debug.info("get jobkinds {{ {} }}".format(name))
|
|
||||||
retVal = db.getJobKind(name)
|
|
||||||
debug.debug("jobkind is {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def setJobKind(self, name, workgroup=None):
|
|
||||||
debug.info("set jobkind {{ {} }} ".format(name))
|
|
||||||
retVal = db.setJobKind(name, workgroup)
|
|
||||||
debug.debug(
|
|
||||||
"seted jobkind {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteJobKind(self, jobkind):
|
|
||||||
debug.info("delete jobkind {{ {} }}".format(jobkind))
|
|
||||||
db.deleteJobKind(jobkind)
|
|
||||||
|
|
||||||
def updateJobKind(self, jobkind):
|
|
||||||
debug.info("update workgroup {{ {} }}".format(jobkind))
|
|
||||||
retVal = db.updateJobKind(jobkind)
|
|
||||||
debug.debug("updated jobkind is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def updateWorkgroupsOfUser(self, user, workgroups):
|
|
||||||
debug.info("update workgroups {{ {} }} of user {{ {} }}".format(workgroups, user))
|
|
||||||
db.deleteWorkgroupsOfUser(user)
|
|
||||||
for workgroup in workgroups:
|
|
||||||
db.setUserWorkgroup(user, workgroup)
|
|
||||||
return db.getWorkgroupsOfUser(user['id'])
|
|
||||||
|
|
||||||
def getAllWorkgroups(self):
|
|
||||||
debug.info("get all workgroups")
|
|
||||||
retVal = db.getAllWorkgroups()
|
|
||||||
debug.debug("workgroups are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getWorkgroups(self, name):
|
|
||||||
debug.info("get Workgroup {{ {} }}".format(name))
|
|
||||||
retVal = db.getWorkgroup(name)
|
|
||||||
debug.debug("workgroup is {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def setWorkgroup(self, name, boss):
|
|
||||||
debug.info("set workgroup {{ {} }} with boss {{ {} }}".format(name, boss))
|
|
||||||
retVal = db.setWorkgroup(name, boss)
|
|
||||||
debug.debug(
|
|
||||||
"seted workgroup {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteWorkgroup(self, workgroup):
|
|
||||||
debug.info("delete workgroup {{ {} }}".format(workgroup))
|
|
||||||
db.deleteWorkgroup(workgroup)
|
|
||||||
|
|
||||||
def updateWorkgroup(self, workgroup):
|
|
||||||
debug.info("update workgroup {{ {} }}".format(workgroup))
|
|
||||||
retVal = db.updateWorkgroup(workgroup)
|
|
||||||
debug.debug("updated workgroup is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getAllStatus(self):
|
|
||||||
debug.info("get all status for user")
|
|
||||||
retVal = db.getAllStatus()
|
|
||||||
debug.debug("status are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getStatus(self, name):
|
|
||||||
debug.info("get status of user {{ {} }}".format(name))
|
|
||||||
retVal = db.getStatus(name)
|
|
||||||
debug.debug("status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def setStatus(self, name):
|
|
||||||
debug.info("set status of user {{ {} }}".format(name))
|
|
||||||
retVal = db.setStatus(name)
|
|
||||||
debug.debug(
|
|
||||||
"settet status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteStatus(self, status):
|
|
||||||
debug.info("delete status {{ {} }}".format(status))
|
|
||||||
db.deleteStatus(status)
|
|
||||||
|
|
||||||
def updateStatus(self, status):
|
|
||||||
debug.info("update status {{ {} }}".format(status))
|
|
||||||
retVal = db.updateStatus(status)
|
|
||||||
debug.debug("updated status is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def updateStatusOfUser(self, username, status):
|
|
||||||
debug.info("update status {{ {} }} of user {{ {} }}".format(
|
|
||||||
status, username))
|
|
||||||
retVal = db.updateStatusOfUser(username, status)
|
|
||||||
debug.debug(
|
|
||||||
"updatet status of user {{ {} }} is {{ {} }}".format(username, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def updateVotingOfUser(self, username, voting):
|
|
||||||
debug.info("update voting {{ {} }} of user {{ {} }}".format(
|
|
||||||
voting, username))
|
|
||||||
retVal = db.updateVotingOfUser(username, voting)
|
|
||||||
debug.debug(
|
|
||||||
"updatet voting of user {{ {} }} is {{ {} }}".format(username, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteDrinkType(self, type):
|
|
||||||
debug.info("delete drink type {{ {} }}".format(type))
|
|
||||||
db.deleteDrinkType(type)
|
|
||||||
|
|
||||||
def updateDrinkType(self, type):
|
|
||||||
debug.info("update drink type {{ {} }}".format(type))
|
|
||||||
retVal = db.updateDrinkType(type)
|
|
||||||
debug.debug("updated drink type is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def setDrinkType(self, type):
|
|
||||||
debug.info("set drink type {{ {} }}".format(type))
|
|
||||||
retVal = db.setDrinkType(type)
|
|
||||||
debug.debug("seted drink type is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deletDrinkPrice(self, drink):
|
|
||||||
debug.info("delete drink {{ {} }}".format(drink))
|
|
||||||
db.deleteDrink(drink)
|
|
||||||
|
|
||||||
def setDrinkPrice(self, drink):
|
|
||||||
debug.info("set drink {{ {} }}".format(drink))
|
|
||||||
retVal = db.setDrinkPrice(drink)
|
|
||||||
debug.debug("seted drink is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def updateDrinkPrice(self, drink):
|
|
||||||
debug.info("update drink {{ {} }}".format(drink))
|
|
||||||
retVal = db.updateDrinkPrice(drink)
|
|
||||||
debug.debug("updated drink is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getAllDrinkTypes(self):
|
|
||||||
debug.info("get all drink types")
|
|
||||||
retVal = db.getAllDrinkTypes()
|
|
||||||
debug.debug("all drink types are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getPricelist(self):
|
|
||||||
debug.info("get all drinks")
|
|
||||||
list = db.getPriceList()
|
|
||||||
debug.debug("all drinks are {{ {} }}".format(list))
|
|
||||||
return list
|
|
||||||
|
|
||||||
def setTransactJob(self, from_user, to_user, date):
|
|
||||||
debug.info("set transact job from {{ {} }} to {{ {} }} on {{ {} }}".format(
|
|
||||||
from_user, to_user, date))
|
|
||||||
jobtransact = db.setTransactJob(from_user, to_user, date.date())
|
|
||||||
debug.debug("transact job is {{ {} }}".format(jobtransact))
|
|
||||||
debug.info("send mail with transact job to user")
|
|
||||||
emailController.sendMail(
|
|
||||||
jobtransact['to_user'], 'jobtransact', jobtransact)
|
|
||||||
return jobtransact
|
|
||||||
|
|
||||||
def getTransactJobFromUser(self, user, date):
|
|
||||||
debug.info(
|
|
||||||
"get transact job from user {{ {} }} on {{ {} }}".format(user, date))
|
|
||||||
retVal = db.getTransactJobFromUser(user, date.date())
|
|
||||||
debug.debug(
|
|
||||||
"transact job from user {{ {} }} is {{ {} }}".format(user, retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getAllTransactJobFromUser(self, user, date):
|
|
||||||
debug.info(
|
|
||||||
"get all transact job from user {{ {} }} start on {{ {} }}".format(user, date))
|
|
||||||
retVal = db.getAllTransactJobFromUser(user, date.date())
|
|
||||||
debug.debug("all transact job are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getAllTransactJobToUser(self, user, date):
|
|
||||||
debug.info(
|
|
||||||
"get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date))
|
|
||||||
retVal = db.getAllTransactJobToUser(user, date.date())
|
|
||||||
debug.debug("all transact job are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getTransactJob(self, from_user, to_user, date):
|
|
||||||
debug.info("get transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
|
||||||
from_user, to_user, date))
|
|
||||||
retVal = db.getTransactJob(from_user, to_user, date.date())
|
|
||||||
debug.debug("transact job is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteTransactJob(self, from_user, to_user, date):
|
|
||||||
debug.info("delete transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
|
||||||
from_user, to_user, date))
|
|
||||||
transactJob = self.getTransactJob(from_user, to_user, date)
|
|
||||||
debug.debug("transact job is {{ {} }}".format(transactJob))
|
|
||||||
if transactJob['answerd']:
|
|
||||||
debug.warning(
|
|
||||||
"transactjob {{ {} }} can not delete because is answerd")
|
|
||||||
raise TansactJobIsAnswerdException(
|
|
||||||
"TransactJob is already answerd")
|
|
||||||
db.deleteTransactJob(from_user, to_user, date.date())
|
|
||||||
|
|
||||||
def answerdTransactJob(self, from_user, to_user, date, answer):
|
|
||||||
debug.info("answer transact job from user {{ {} }} to user {{ {} }} on {{ {} }} with answer {{ {} }}".format(
|
|
||||||
from_user, to_user, date, answer))
|
|
||||||
transactJob = db.updateTransactJob(
|
|
||||||
from_user, to_user, date.date(), answer)
|
|
||||||
debug.debug("transactjob is {{ {} }}".format(transactJob))
|
|
||||||
if answer:
|
|
||||||
debug.info("add worker on date {{ {} }}".format(date))
|
|
||||||
self.addWorker(to_user.uid, date)
|
|
||||||
return transactJob
|
|
||||||
|
|
||||||
def setLockedDay(self, date, locked, hard=False):
|
|
||||||
debug.info(
|
|
||||||
"set day locked on {{ {} }} with state {{ {} }}".format(date, locked))
|
|
||||||
retVal = db.setLockedDay(date.date(), locked, hard)
|
|
||||||
debug.debug("seted day locked is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getLockedDays(self, from_date, to_date):
|
|
||||||
debug.info("get locked days from {{ {} }} to {{ {} }}".format(
|
|
||||||
from_date.date(), to_date.date()))
|
|
||||||
oneDay = timedelta(1)
|
|
||||||
delta = to_date.date() - from_date.date()
|
|
||||||
retVal = []
|
|
||||||
startdate = from_date - oneDay
|
|
||||||
for _ in range(delta.days + 1):
|
|
||||||
startdate += oneDay
|
|
||||||
lockday = self.getLockedDay(startdate)
|
|
||||||
retVal.append(lockday)
|
|
||||||
debug.debug("lock days are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getLockedDay(self, date):
|
|
||||||
debug.info("get locked day on {{ {} }}".format(date))
|
|
||||||
now = datetime.now()
|
|
||||||
debug.debug("now is {{ {} }}".format(now))
|
|
||||||
oldMonth = False
|
|
||||||
debug.debug("check if date old month or current month")
|
|
||||||
for i in range(1, 8):
|
|
||||||
if datetime(now.year, now.month, i).weekday() == 2:
|
|
||||||
if now.day < i:
|
|
||||||
oldMonth = True
|
|
||||||
break
|
|
||||||
debug.debug("oldMonth is {{ {} }}".format(oldMonth))
|
|
||||||
lockedYear = now.year
|
|
||||||
lockedMonth = now.month if now.month < now.month else now.month - \
|
|
||||||
1 if oldMonth else now.month
|
|
||||||
endDay = 1
|
|
||||||
debug.debug("calculate end day of month")
|
|
||||||
lockedYear = lockedYear if lockedMonth != 12 else (lockedYear + 1)
|
|
||||||
lockedMonth = (lockedMonth + 1) if lockedMonth != 12 else 1
|
|
||||||
for i in range(1, 8):
|
|
||||||
nextMonth = datetime(lockedYear, lockedMonth, i)
|
|
||||||
if nextMonth.weekday() == 2:
|
|
||||||
endDay = i
|
|
||||||
break
|
|
||||||
|
|
||||||
monthLockedEndDate = datetime(
|
|
||||||
lockedYear, lockedMonth, endDay) - timedelta(1)
|
|
||||||
debug.debug("get lock day from database")
|
|
||||||
retVal = db.getLockedDay(date.date())
|
|
||||||
if not retVal:
|
|
||||||
debug.debug(
|
|
||||||
"lock day not exists, retVal is {{ {} }}".format(retVal))
|
|
||||||
if date.date() <= monthLockedEndDate.date():
|
|
||||||
debug.debug("lock day {{ {} }}".format(date.date()))
|
|
||||||
self.setLockedDay(date, True)
|
|
||||||
retVal = db.getLockedDay(date.date())
|
|
||||||
else:
|
|
||||||
retVal = {"daydate": date.date(), "locked": False}
|
|
||||||
debug.debug("locked day is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getWorker(self, date, username=None):
|
|
||||||
debug.info("get worker {{ {} }} on {{ {} }}".format(username, date))
|
|
||||||
if (username):
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
retVal = [db.getWorker(user, date)]
|
|
||||||
debug.debug("worker is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
retVal = db.getWorkers(date)
|
|
||||||
debug.debug("workers are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def addWorker(self, username, date, userExc=False):
|
|
||||||
debug.info("add job user {{ {} }} on {{ {} }}".format(username, date))
|
|
||||||
if (userExc):
|
|
||||||
debug.debug("this is a user execution, check if day is locked")
|
|
||||||
lockedDay = self.getLockedDay(date)
|
|
||||||
if lockedDay:
|
|
||||||
if lockedDay['locked']:
|
|
||||||
debug.debug("day is lockey. user cant get job")
|
|
||||||
raise DayLocked("Day is locked. You can't get the Job")
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
debug.debug("check if user has job on date")
|
|
||||||
if (not db.getWorker(user, date)):
|
|
||||||
debug.debug("set job to user")
|
|
||||||
db.setWorker(user, date)
|
|
||||||
retVal = self.getWorker(date, username=username)
|
|
||||||
debug.debug("worker on date is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def deleteWorker(self, username, date, userExc=False):
|
|
||||||
debug.info(
|
|
||||||
"delete worker {{ {} }} on date {{ {} }}".format(username, date))
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
if userExc:
|
|
||||||
debug.debug("is user execution, check if day locked")
|
|
||||||
lockedDay = self.getLockedDay(date)
|
|
||||||
if lockedDay:
|
|
||||||
if lockedDay['locked']:
|
|
||||||
debug.debug(
|
|
||||||
"day is locked, check if accepted transact job exists")
|
|
||||||
transactJobs = self.getTransactJobFromUser(user, date)
|
|
||||||
debug.debug(
|
|
||||||
"transact job is {{ {} }}".format(transactJobs))
|
|
||||||
found = False
|
|
||||||
for job in transactJobs:
|
|
||||||
if job['accepted'] and job['answerd']:
|
|
||||||
debug.debug("accepted transact job exists")
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
debug.debug("no accepted transact job found")
|
|
||||||
raise DayLocked(
|
|
||||||
"Day is locked. You can't delete the Job")
|
|
||||||
db.deleteWorker(user, date)
|
|
||||||
|
|
||||||
def lockUser(self, username, locked):
|
|
||||||
debug.info("lock user {{ {} }} for credit with status {{ {} }}".format(
|
|
||||||
username, locked))
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
user.updateData({'locked': locked})
|
|
||||||
db.updateUser(user)
|
|
||||||
retVal = self.getUser(username)
|
|
||||||
debug.debug("locked user is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def updateConfig(self, username, data):
|
|
||||||
debug.info(
|
|
||||||
"update config of user {{ {} }} with config {{ {} }}".format(username, data))
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
user.updateData(data)
|
|
||||||
db.updateUser(user)
|
|
||||||
retVal = self.getUser(username)
|
|
||||||
debug.debug("updated config of user is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def __updateDataFromLDAP(self, user):
|
|
||||||
debug.info("update data from ldap for user {{ {} }}".format(user))
|
|
||||||
groups = ldap.getGroup(user.uid)
|
|
||||||
debug.debug("ldap gorups are {{ {} }}".format(groups))
|
|
||||||
user_data = ldap.getUserData(user.uid)
|
|
||||||
debug.debug("ldap data is {{ {} }}".format(user_data))
|
|
||||||
user_data['gruppe'] = groups
|
|
||||||
user_data['group'] = groups
|
|
||||||
user.updateData(user_data)
|
|
||||||
db.updateUser(user)
|
|
||||||
|
|
||||||
def autoLock(self, user):
|
|
||||||
debug.info("start autolock of user {{ {} }}".format(user))
|
|
||||||
if user.autoLock:
|
|
||||||
debug.debug("autolock is active")
|
|
||||||
credit = user.getGeruecht(year=datetime.now().year).getSchulden()
|
|
||||||
limit = -1*user.limit
|
|
||||||
if credit <= limit:
|
|
||||||
debug.debug(
|
|
||||||
"credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit))
|
|
||||||
debug.debug("lock user")
|
|
||||||
user.updateData({'locked': True})
|
|
||||||
debug.debug("send mail to user")
|
|
||||||
emailController.sendMail(user)
|
|
||||||
else:
|
|
||||||
debug.debug(
|
|
||||||
"cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit))
|
|
||||||
debug.debug("unlock user")
|
|
||||||
user.updateData({'locked': False})
|
|
||||||
db.updateUser(user)
|
|
||||||
|
|
||||||
def addAmount(self, username, amount, year, month, finanzer=False):
|
|
||||||
debug.info("add amount {{ {} }} to user {{ {} }} no month {{ {} }}, year {{ {} }}".format(
|
|
||||||
amount, username, month, year))
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
if user.uid == 'extern':
|
|
||||||
debug.debug("user is extern user, so exit add amount")
|
|
||||||
return
|
|
||||||
if not user.locked or finanzer:
|
|
||||||
debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format(
|
|
||||||
user.locked, finanzer))
|
|
||||||
user.addAmount(amount, year=year, month=month)
|
|
||||||
creditLists = user.updateGeruecht()
|
|
||||||
debug.debug("creditList is {{ {} }}".format(creditLists))
|
|
||||||
for creditList in creditLists:
|
|
||||||
debug.debug("update creditlist {{ {} }}".format(creditList))
|
|
||||||
db.updateCreditList(creditList)
|
|
||||||
debug.debug("do autolock")
|
|
||||||
self.autoLock(user)
|
|
||||||
retVal = user.getGeruecht(year)
|
|
||||||
debug.debug("updated creditlists is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def addCredit(self, username, credit, year, month):
|
|
||||||
debug.info("add credit {{ {} }} to user {{ {} }} on month {{ {} }}, year {{ {} }}".format(
|
|
||||||
credit, username, month, year))
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
if user.uid == 'extern':
|
|
||||||
debug.debug("user is extern user, so exit add credit")
|
|
||||||
return
|
|
||||||
user.addCredit(credit, year=year, month=month)
|
|
||||||
creditLists = user.updateGeruecht()
|
|
||||||
debug.debug("creditlists are {{ {} }}".format(creditLists))
|
|
||||||
for creditList in creditLists:
|
|
||||||
debug.debug("update creditlist {{ {} }}".format(creditList))
|
|
||||||
db.updateCreditList(creditList)
|
|
||||||
debug.debug("do autolock")
|
|
||||||
self.autoLock(user)
|
|
||||||
retVal = user.getGeruecht(year)
|
|
||||||
debug.debug("updated creditlists are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def getAllUsersfromDB(self):
|
|
||||||
debug.info("get all users from database")
|
|
||||||
users = db.getAllUser()
|
|
||||||
debug.debug("users are {{ {} }}".format(users))
|
|
||||||
for user in users:
|
|
||||||
try:
|
|
||||||
debug.debug("update data from ldap")
|
|
||||||
self.__updateDataFromLDAP(user)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
debug.debug("update creditlists")
|
|
||||||
self.__updateGeruechte(user)
|
|
||||||
retVal = db.getAllUser(extern=True)
|
|
||||||
debug.debug("all users are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def checkBarUser(self, user):
|
|
||||||
debug.info("check if user {{ {} }} is baruser")
|
|
||||||
date = datetime.now()
|
|
||||||
zero = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
||||||
end = zero + timedelta(hours=12)
|
|
||||||
startdatetime = date.replace(
|
|
||||||
hour=12, minute=0, second=0, microsecond=0)
|
|
||||||
if date > zero and end > date:
|
|
||||||
startdatetime = startdatetime - timedelta(days=1)
|
|
||||||
enddatetime = startdatetime + timedelta(days=1)
|
|
||||||
debug.debug("startdatetime is {{ {} }} and enddatetime is {{ {} }}".format(
|
|
||||||
startdatetime, end))
|
|
||||||
result = False
|
|
||||||
if date >= startdatetime and date < enddatetime:
|
|
||||||
result = db.getWorker(user, startdatetime)
|
|
||||||
debug.debug("worker is {{ {} }}".format(result))
|
|
||||||
return True if result else False
|
|
||||||
|
|
||||||
def getUser(self, username):
|
|
||||||
debug.info("get user {{ {} }}".format(username))
|
|
||||||
user = db.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
groups = ldap.getGroup(username)
|
|
||||||
debug.debug("groups are {{ {} }}".format(groups))
|
|
||||||
user_data = ldap.getUserData(username)
|
|
||||||
debug.debug("user data from ldap is {{ {} }}".format(user_data))
|
|
||||||
user_data['gruppe'] = groups
|
|
||||||
user_data['group'] = groups
|
|
||||||
if user is None:
|
|
||||||
debug.debug("user not exists in database -> insert into database")
|
|
||||||
user = User(user_data)
|
|
||||||
db.insertUser(user)
|
|
||||||
else:
|
|
||||||
debug.debug("update database with user")
|
|
||||||
user.updateData(user_data)
|
|
||||||
db.updateUser(user)
|
|
||||||
user = db.getUser(username)
|
|
||||||
self.__updateGeruechte(user)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
return user
|
|
||||||
|
|
||||||
def __updateGeruechte(self, user):
|
|
||||||
debug.debug("update creditlists")
|
|
||||||
user.getGeruecht(datetime.now().year)
|
|
||||||
creditLists = user.updateGeruecht()
|
|
||||||
debug.debug("creditlists are {{ {} }}".format(creditLists))
|
|
||||||
if user.getGeruecht(datetime.now().year).getSchulden() != 0:
|
|
||||||
for creditList in creditLists:
|
|
||||||
debug.debug("update creditlist {{ {} }}".format(creditList))
|
|
||||||
db.updateCreditList(creditList)
|
|
||||||
|
|
||||||
def sendMail(self, username):
|
|
||||||
debug.info("send mail to user {{ {} }}".format(username))
|
|
||||||
if type(username) == User:
|
|
||||||
user = username
|
|
||||||
if type(username) == str:
|
|
||||||
user = db.getUser(username)
|
|
||||||
retVal = emailController.sendMail(user)
|
|
||||||
debug.debug("send mail is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def sendAllMail(self):
|
|
||||||
debug.info("send mail to all user")
|
|
||||||
retVal = []
|
|
||||||
users = db.getAllUser()
|
|
||||||
debug.debug("users are {{ {} }}".format(users))
|
|
||||||
for user in users:
|
|
||||||
retVal.append(self.sendMail(user))
|
|
||||||
debug.debug("send mails are {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
|
|
||||||
def modifyUser(self, user, ldap_conn, attributes):
|
|
||||||
debug.info("modify user {{ {} }} with attributes {{ {} }} with ldap_conn {{ {} }}".format(
|
|
||||||
user, attributes, ldap_conn))
|
|
||||||
try:
|
|
||||||
if 'username' in attributes:
|
|
||||||
debug.debug("change username, so change first in database")
|
|
||||||
db.changeUsername(user, attributes['username'])
|
|
||||||
ldap.modifyUser(user, ldap_conn, attributes)
|
|
||||||
if 'username' in attributes:
|
|
||||||
retVal = self.getUser(attributes['username'])
|
|
||||||
debug.debug("user is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
else:
|
|
||||||
retVal = self.getUser(user.uid)
|
|
||||||
debug.debug("user is {{ {} }}".format(retVal))
|
|
||||||
return retVal
|
|
||||||
except UsernameExistLDAP as err:
|
|
||||||
debug.debug(
|
|
||||||
"username exists on ldap, rechange username on database", exc_info=True)
|
|
||||||
db.changeUsername(user, user.uid)
|
|
||||||
raise Exception(err)
|
|
||||||
except LDAPExcetpion as err:
|
|
||||||
if 'username' in attributes:
|
|
||||||
db.changeUsername(user, user.uid)
|
|
||||||
raise Exception(err)
|
|
||||||
except Exception as err:
|
|
||||||
raise Exception(err)
|
|
||||||
|
|
||||||
def validateUser(self, username, password):
|
|
||||||
debug.info("validate user {{ {} }}".format(username))
|
|
||||||
ldap.login(username, password)
|
|
||||||
|
|
||||||
def loginUser(self, username, password):
|
|
||||||
debug.info("login user {{ {} }}".format(username))
|
|
||||||
try:
|
|
||||||
user = self.getUser(username)
|
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
|
||||||
user.password = password
|
|
||||||
ldap.login(username, password)
|
|
||||||
ldap_conn = ldap.bind(user, password)
|
|
||||||
return user, ldap_conn
|
|
||||||
except PermissionDenied as err:
|
|
||||||
debug.debug("permission is denied", exc_info=True)
|
|
||||||
raise err
|
|
|
@ -1,6 +1,6 @@
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from geruecht.model import MONEY
|
from geruecht.model import MONEY
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
from geruecht.logger import getDebugLogger, getCreditLogger
|
from geruecht.logger import getDebugLogger, getCreditLogger
|
||||||
|
@ -10,7 +10,7 @@ creditL = getCreditLogger()
|
||||||
|
|
||||||
finanzer = Blueprint("finanzer", __name__)
|
finanzer = Blueprint("finanzer", __name__)
|
||||||
|
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
|
|
||||||
@finanzer.route("/getFinanzerMain")
|
@finanzer.route("/getFinanzerMain")
|
||||||
|
@ -26,7 +26,7 @@ def _getFinanzer(**kwargs):
|
||||||
"""
|
"""
|
||||||
debug.info("/getFinanzerMain")
|
debug.info("/getFinanzerMain")
|
||||||
try:
|
try:
|
||||||
users = userController.getAllUsersfromDB()
|
users = mainController.getAllUsersfromDB()
|
||||||
dic = {}
|
dic = {}
|
||||||
for user in users:
|
for user in users:
|
||||||
dic[user.uid] = user.toJSON()
|
dic[user.uid] = user.toJSON()
|
||||||
|
@ -65,9 +65,9 @@ def _addAmount(**kwargs):
|
||||||
month = int(data['month'])
|
month = int(data['month'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
month = datetime.now().month
|
month = datetime.now().month
|
||||||
userController.addAmount(
|
mainController.addAmount(
|
||||||
userID, amount, year=year, month=month, finanzer=True)
|
userID, amount, year=year, month=month, finanzer=True)
|
||||||
user = userController.getUser(userID)
|
user = mainController.getUser(userID)
|
||||||
retVal = {str(geruecht.year): geruecht.toJSON()
|
retVal = {str(geruecht.year): geruecht.toJSON()
|
||||||
for geruecht in user.geruechte}
|
for geruecht in user.geruechte}
|
||||||
retVal['locked'] = user.locked
|
retVal['locked'] = user.locked
|
||||||
|
@ -108,9 +108,9 @@ def _addCredit(**kwargs):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
month = datetime.now().month
|
month = datetime.now().month
|
||||||
|
|
||||||
userController.addCredit(
|
mainController.addCredit(
|
||||||
userID, credit, year=year, month=month).toJSON()
|
userID, credit, year=year, month=month).toJSON()
|
||||||
user = userController.getUser(userID)
|
user = mainController.getUser(userID)
|
||||||
retVal = {str(geruecht.year): geruecht.toJSON()
|
retVal = {str(geruecht.year): geruecht.toJSON()
|
||||||
for geruecht in user.geruechte}
|
for geruecht in user.geruechte}
|
||||||
retVal['locked'] = user.locked
|
retVal['locked'] = user.locked
|
||||||
|
@ -131,7 +131,7 @@ def _finanzerLock(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['userId']
|
username = data['userId']
|
||||||
locked = bool(data['locked'])
|
locked = bool(data['locked'])
|
||||||
retVal = userController.lockUser(username, locked).toJSON()
|
retVal = mainController.lockUser(username, locked).toJSON()
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -148,7 +148,7 @@ def _finanzerSetConfig(**kwargs):
|
||||||
username = data['userId']
|
username = data['userId']
|
||||||
autoLock = bool(data['autoLock'])
|
autoLock = bool(data['autoLock'])
|
||||||
limit = int(data['limit'])
|
limit = int(data['limit'])
|
||||||
retVal = userController.updateConfig(
|
retVal = mainController.updateConfig(
|
||||||
username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON()
|
username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON()
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -164,8 +164,8 @@ def _finanzerAddUser(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['userId']
|
username = data['userId']
|
||||||
userController.getUser(username)
|
mainController.getUser(username)
|
||||||
users = userController.getAllUsersfromDB()
|
users = mainController.getAllUsersfromDB()
|
||||||
dic = {}
|
dic = {}
|
||||||
for user in users:
|
for user in users:
|
||||||
dic[user.uid] = user.toJSON()
|
dic[user.uid] = user.toJSON()
|
||||||
|
@ -185,7 +185,7 @@ def _finanzerSendOneMail(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['userId']
|
username = data['userId']
|
||||||
retVal = userController.sendMail(username)
|
retVal = mainController.sendMail(username)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -198,7 +198,7 @@ def _finanzerSendOneMail(**kwargs):
|
||||||
def _finanzerSendAllMail(**kwargs):
|
def _finanzerSendAllMail(**kwargs):
|
||||||
debug.info("/finanzerSendAllMail")
|
debug.info("/finanzerSendAllMail")
|
||||||
try:
|
try:
|
||||||
retVal = userController.sendAllMail()
|
retVal = mainController.sendAllMail()
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from flask import request, jsonify, Blueprint
|
from flask import request, jsonify, Blueprint
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from geruecht.model import GASTRO
|
from geruecht.model import GASTRO
|
||||||
from geruecht.logger import getCreditLogger, getDebugLogger
|
from geruecht.logger import getCreditLogger, getDebugLogger
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ debug = getDebugLogger()
|
||||||
|
|
||||||
gastrouser = Blueprint('gastrouser', __name__)
|
gastrouser = Blueprint('gastrouser', __name__)
|
||||||
|
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
|
|
||||||
@gastrouser.route('/gastro/setDrink', methods=['POST'])
|
@gastrouser.route('/gastro/setDrink', methods=['POST'])
|
||||||
|
@ -17,7 +17,7 @@ def setDrink(**kwargs):
|
||||||
debug.info("/gastro/setDrink")
|
debug.info("/gastro/setDrink")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.setDrinkPrice(data)
|
retVal = mainController.setDrinkPrice(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -31,7 +31,7 @@ def updateDrink(**kwargs):
|
||||||
debug.info("/gastro/updateDrink")
|
debug.info("/gastro/updateDrink")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateDrinkPrice(data)
|
retVal = mainController.updateDrinkPrice(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -46,7 +46,7 @@ def deleteDrink(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
id = data['id']
|
id = data['id']
|
||||||
userController.deletDrinkPrice({"id": id})
|
mainController.deletDrinkPrice({"id": id})
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -61,7 +61,7 @@ def setType(**kwark):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data['name']
|
name = data['name']
|
||||||
retVal = userController.setDrinkType(name)
|
retVal = mainController.setDrinkType(name)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -75,7 +75,7 @@ def updateType(**kwargs):
|
||||||
debug.info("/gastro/updateDrinkType")
|
debug.info("/gastro/updateDrinkType")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateDrinkType(data)
|
retVal = mainController.updateDrinkType(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -89,7 +89,7 @@ def deleteType(**kwargs):
|
||||||
debug.info("/gastro/deleteDrinkType")
|
debug.info("/gastro/deleteDrinkType")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userController.deleteDrinkType(data)
|
mainController.deleteDrinkType(data)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
|
@ -3,12 +3,12 @@ from geruecht.logger import getDebugLogger
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
from geruecht.exceptions import PermissionDenied
|
from geruecht.exceptions import PermissionDenied
|
||||||
import geruecht.controller.accesTokenController as ac
|
import geruecht.controller.accesTokenController as ac
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from geruecht.model import MONEY, BAR, USER, GASTRO, VORSTAND, EXTERN
|
from geruecht.model import MONEY, BAR, USER, GASTRO, VORSTAND, EXTERN
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
|
|
||||||
accesTokenController = ac.AccesTokenController()
|
accesTokenController = ac.AccesTokenController()
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
debug = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ def _valid(**kwargs):
|
||||||
try:
|
try:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userController.validateUser(accToken.user.uid, data['password'])
|
mainController.validateUser(accToken.user.uid, data['password'])
|
||||||
debug.debug('return {{ "ok": "ok" }}')
|
debug.debug('return {{ "ok": "ok" }}')
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -30,7 +30,7 @@ def _valid(**kwargs):
|
||||||
def _getPricelist():
|
def _getPricelist():
|
||||||
try:
|
try:
|
||||||
debug.info("get pricelist")
|
debug.info("get pricelist")
|
||||||
retVal = userController.getPricelist()
|
retVal = mainController.getPricelist()
|
||||||
debug.info("return pricelist {{ {} }}".format(retVal))
|
debug.info("return pricelist {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -42,7 +42,7 @@ def _getPricelist():
|
||||||
def getTypes():
|
def getTypes():
|
||||||
try:
|
try:
|
||||||
debug.info("get drinktypes")
|
debug.info("get drinktypes")
|
||||||
retVal = userController.getAllDrinkTypes()
|
retVal = mainController.getAllDrinkTypes()
|
||||||
debug.info("return drinktypes {{ {} }}".format(retVal))
|
debug.info("return drinktypes {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -55,7 +55,7 @@ def getTypes():
|
||||||
def _getAllStatus(**kwargs):
|
def _getAllStatus(**kwargs):
|
||||||
try:
|
try:
|
||||||
debug.info("get all status for users")
|
debug.info("get all status for users")
|
||||||
retVal = userController.getAllStatus()
|
retVal = mainController.getAllStatus()
|
||||||
debug.info("return all status for users {{ {} }}".format(retVal))
|
debug.info("return all status for users {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -71,7 +71,7 @@ def _getStatus(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data['name']
|
name = data['name']
|
||||||
debug.info("get status from user {{ {} }}".format(name))
|
debug.info("get status from user {{ {} }}".format(name))
|
||||||
retVal = userController.getStatus(name)
|
retVal = mainController.getStatus(name)
|
||||||
debug.info(
|
debug.info(
|
||||||
"return status from user {{ {} }} : {{ {} }}".format(name, retVal))
|
"return status from user {{ {} }} : {{ {} }}".format(name, retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -84,8 +84,11 @@ def _getStatus(**kwargs):
|
||||||
@login_required(groups=[MONEY, GASTRO, VORSTAND], bar=True)
|
@login_required(groups=[MONEY, GASTRO, VORSTAND], bar=True)
|
||||||
def _getUsers(**kwargs):
|
def _getUsers(**kwargs):
|
||||||
try:
|
try:
|
||||||
|
extern = True
|
||||||
|
if 'extern' in request.args:
|
||||||
|
extern = not bool(int(request.args['extern']))
|
||||||
debug.info("get all users from database")
|
debug.info("get all users from database")
|
||||||
users = userController.getAllUsersfromDB()
|
users = mainController.getAllUsersfromDB(extern=extern)
|
||||||
debug.debug("users are {{ {} }}".format(users))
|
debug.debug("users are {{ {} }}".format(users))
|
||||||
retVal = [user.toJSON() for user in users]
|
retVal = [user.toJSON() for user in users]
|
||||||
debug.info("return all users from database {{ {} }}".format(retVal))
|
debug.info("return all users from database {{ {} }}".format(retVal))
|
||||||
|
@ -173,7 +176,7 @@ def _login():
|
||||||
debug.debug("username is {{ {} }}".format(username))
|
debug.debug("username is {{ {} }}".format(username))
|
||||||
try:
|
try:
|
||||||
debug.info("search {{ {} }} in database".format(username))
|
debug.info("search {{ {} }} in database".format(username))
|
||||||
user, ldap_conn = userController.loginUser(username, password)
|
user, ldap_conn = mainController.loginUser(username, password)
|
||||||
debug.debug("user is {{ {} }}".format(user))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
user.password = password
|
user.password = password
|
||||||
token = accesTokenController.createAccesToken(user, ldap_conn)
|
token = accesTokenController.createAccesToken(user, ldap_conn)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
from geruecht.model import USER
|
from geruecht.model import USER
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
from geruecht.exceptions import DayLocked
|
from geruecht.exceptions import DayLocked
|
||||||
|
@ -8,7 +8,7 @@ from geruecht.logger import getDebugLogger, getCreditLogger, getJobsLogger
|
||||||
|
|
||||||
user = Blueprint("user", __name__)
|
user = Blueprint("user", __name__)
|
||||||
|
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
|
|
||||||
debug = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
creditL = getCreditLogger()
|
creditL = getCreditLogger()
|
||||||
|
@ -22,7 +22,7 @@ def _main(**kwargs):
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
accToken.user = userController.getUser(accToken.user.uid)
|
accToken.user = mainController.getUser(accToken.user.uid)
|
||||||
retVal = accToken.user.toJSON()
|
retVal = accToken.user.toJSON()
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||||
for credit in accToken.user.geruechte}
|
for credit in accToken.user.geruechte}
|
||||||
|
@ -43,9 +43,9 @@ def _addAmount(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addAmount(
|
mainController.addAmount(
|
||||||
accToken.user.uid, amount, year=date.year, month=date.month)
|
accToken.user.uid, amount, year=date.year, month=date.month)
|
||||||
accToken.user = userController.getUser(accToken.user.uid)
|
accToken.user = mainController.getUser(accToken.user.uid)
|
||||||
retVal = accToken.user.toJSON()
|
retVal = accToken.user.toJSON()
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||||
for credit in accToken.user.geruechte}
|
for credit in accToken.user.geruechte}
|
||||||
|
@ -66,7 +66,7 @@ def _saveConfig(**kwargs):
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
accToken.user = userController.modifyUser(
|
accToken.user = mainController.modifyUser(
|
||||||
accToken.user, accToken.ldap_conn, data)
|
accToken.user, accToken.ldap_conn, data)
|
||||||
retVal = accToken.user.toJSON()
|
retVal = accToken.user.toJSON()
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||||
|
@ -89,12 +89,12 @@ def _getUsers(**kwrags):
|
||||||
from_date = datetime(
|
from_date = datetime(
|
||||||
from_date['year'], from_date['month'], from_date['day'])
|
from_date['year'], from_date['month'], from_date['day'])
|
||||||
to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
|
to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
|
||||||
lockedDays = userController.getLockedDays(from_date, to_date)
|
lockedDays = mainController.getLockedDays(from_date, to_date)
|
||||||
retVal = []
|
retVal = []
|
||||||
for lockedDay in lockedDays:
|
for lockedDay in lockedDays:
|
||||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
day = datetime.combine(lockedDay['daydate'], time(12))
|
||||||
retDay = {
|
retDay = {
|
||||||
"worker": userController.getWorker(day),
|
"worker": mainController.getWorker(day),
|
||||||
"day": {
|
"day": {
|
||||||
"date": {
|
"date": {
|
||||||
"year": day.year,
|
"year": day.year,
|
||||||
|
@ -102,7 +102,8 @@ def _getUsers(**kwrags):
|
||||||
"day": day.day
|
"day": day.day
|
||||||
},
|
},
|
||||||
"locked": lockedDay['locked']
|
"locked": lockedDay['locked']
|
||||||
}
|
},
|
||||||
|
"jobkinddate": mainController.getJobKindDates(day.date())
|
||||||
}
|
}
|
||||||
retVal.append(retDay)
|
retVal.append(retDay)
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ def _getUser(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
lockedDay = userController.getLockedDay(date)
|
lockedDay = mainController.getLockedDay(date)
|
||||||
if not lockedDay:
|
if not lockedDay:
|
||||||
lockedDay = {
|
lockedDay = {
|
||||||
'date': {
|
'date': {
|
||||||
|
@ -143,7 +144,7 @@ def _getUser(**kwargs):
|
||||||
'locked': lockedDay['locked']
|
'locked': lockedDay['locked']
|
||||||
}
|
}
|
||||||
retVal = {
|
retVal = {
|
||||||
'worker': userController.getWorker(date),
|
'worker': mainController.getWorker(date),
|
||||||
'day': lockedDay
|
'day': lockedDay
|
||||||
}
|
}
|
||||||
debug.debug("retrun {{ {} }}".format(retVal))
|
debug.debug("retrun {{ {} }}".format(retVal))
|
||||||
|
@ -166,7 +167,7 @@ def _addUser(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
retVal = userController.addWorker(user.uid, date, userExc=True)
|
retVal = mainController.addWorker(user.uid, date, userExc=True)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(
|
jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(
|
||||||
user.firstname, user.lastname, date.date()))
|
user.firstname, user.lastname, date.date()))
|
||||||
|
@ -192,7 +193,7 @@ def _deletJob(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
userController.deleteWorker(user.uid, date, True)
|
mainController.deleteWorker(user.uid, date, True)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
||||||
user.firstname, user.lastname, date.date()))
|
user.firstname, user.lastname, date.date()))
|
||||||
|
@ -219,8 +220,8 @@ def _transactJob(**kwargs):
|
||||||
day = data['day']
|
day = data['day']
|
||||||
username = data['user']
|
username = data['user']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
to_user = userController.getUser(username)
|
to_user = mainController.getUser(username)
|
||||||
retVal = userController.setTransactJob(user, to_user, date)
|
retVal = mainController.setTransactJob(user, to_user, date)
|
||||||
from_userl = retVal['from_user']
|
from_userl = retVal['from_user']
|
||||||
to_userl = retVal['to_user']
|
to_userl = retVal['to_user']
|
||||||
retVal['from_user'] = retVal['from_user'].toJSON()
|
retVal['from_user'] = retVal['from_user'].toJSON()
|
||||||
|
@ -250,8 +251,8 @@ def _answer(**kwargs):
|
||||||
answer = data['answer']
|
answer = data['answer']
|
||||||
username = data['username']
|
username = data['username']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
from_user = userController.getUser(username)
|
from_user = mainController.getUser(username)
|
||||||
retVal = userController.answerdTransactJob(
|
retVal = mainController.answerdTransactJob(
|
||||||
from_user, user, date, answer)
|
from_user, user, date, answer)
|
||||||
from_userl = retVal['from_user']
|
from_userl = retVal['from_user']
|
||||||
to_userl = retVal['to_user']
|
to_userl = retVal['to_user']
|
||||||
|
@ -280,7 +281,7 @@ def _requests(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
day = data['day']
|
day = data['day']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
retVal = userController.getAllTransactJobToUser(user, date)
|
retVal = mainController.getAllTransactJobToUser(user, date)
|
||||||
for data in retVal:
|
for data in retVal:
|
||||||
data['from_user'] = data['from_user'].toJSON()
|
data['from_user'] = data['from_user'].toJSON()
|
||||||
data['to_user'] = data['to_user'].toJSON()
|
data['to_user'] = data['to_user'].toJSON()
|
||||||
|
@ -307,7 +308,7 @@ def _getTransactJobs(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
day = data['day']
|
day = data['day']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
retVal = userController.getAllTransactJobFromUser(user, date)
|
retVal = mainController.getAllTransactJobFromUser(user, date)
|
||||||
for data in retVal:
|
for data in retVal:
|
||||||
data['from_user'] = data['from_user'].toJSON()
|
data['from_user'] = data['from_user'].toJSON()
|
||||||
data['to_user'] = data['to_user'].toJSON()
|
data['to_user'] = data['to_user'].toJSON()
|
||||||
|
@ -335,8 +336,8 @@ def _deleteTransactJob(**kwargs):
|
||||||
day = data['day']
|
day = data['day']
|
||||||
username = data['username']
|
username = data['username']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
to_user = userController.getUser(username)
|
to_user = mainController.getUser(username)
|
||||||
userController.deleteTransactJob(from_user, to_user, date)
|
mainController.deleteTransactJob(from_user, to_user, date)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(
|
jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(
|
||||||
from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date()))
|
from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date()))
|
||||||
|
@ -367,9 +368,9 @@ def _storno(**kwargs):
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
|
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addCredit(
|
mainController.addCredit(
|
||||||
user.uid, amount, year=date.year, month=date.month)
|
user.uid, amount, year=date.year, month=date.month)
|
||||||
accToken.user = userController.getUser(accToken.user.uid)
|
accToken.user = mainController.getUser(accToken.user.uid)
|
||||||
retVal = accToken.user.toJSON()
|
retVal = accToken.user.toJSON()
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||||
for credit in accToken.user.geruechte}
|
for credit in accToken.user.geruechte}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time, date
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.mainController as mc
|
||||||
import geruecht.controller.ldapController as lc
|
import geruecht.controller.ldapController as lc
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
from geruecht.model import MONEY, GASTRO, VORSTAND
|
from geruecht.model import MONEY, GASTRO, VORSTAND
|
||||||
|
@ -10,7 +10,7 @@ debug = getDebugLogger()
|
||||||
jobL = getJobsLogger()
|
jobL = getJobsLogger()
|
||||||
|
|
||||||
vorstand = Blueprint("vorstand", __name__)
|
vorstand = Blueprint("vorstand", __name__)
|
||||||
userController = uc.UserController()
|
mainController = mc.MainController()
|
||||||
ldap = lc.LDAPController()
|
ldap = lc.LDAPController()
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ def _setStatus(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data['name']
|
name = data['name']
|
||||||
retVal = userController.setStatus(name)
|
retVal = mainController.setStatus(name)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -35,7 +35,7 @@ def _updateStatus(**kwargs):
|
||||||
debug.info("/um/updateStatus")
|
debug.info("/um/updateStatus")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateStatus(data)
|
retVal = mainController.updateStatus(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -49,7 +49,7 @@ def _deleteStatus(**kwargs):
|
||||||
debug.info("/um/deleteStatus")
|
debug.info("/um/deleteStatus")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userController.deleteStatus(data)
|
mainController.deleteStatus(data)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -65,7 +65,7 @@ def _updateStatusUser(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['username']
|
username = data['username']
|
||||||
status = data['status']
|
status = data['status']
|
||||||
retVal = userController.updateStatusOfUser(username, status).toJSON()
|
retVal = mainController.updateStatusOfUser(username, status).toJSON()
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -81,7 +81,7 @@ def _updateVoting(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
username = data['username']
|
username = data['username']
|
||||||
voting = data['voting']
|
voting = data['voting']
|
||||||
retVal = userController.updateVotingOfUser(username, voting).toJSON()
|
retVal = mainController.updateVotingOfUser(username, voting).toJSON()
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -94,7 +94,7 @@ def _updateWorkgroups(**kwargs):
|
||||||
debug.info("/um/updateWorkgroups")
|
debug.info("/um/updateWorkgroups")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateWorkgroupsOfUser({"id": data['id']}, data['workgroups'])
|
retVal = mainController.updateWorkgroupsOfUser({"id": data['id']}, data['workgroups'])
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal), 200
|
return jsonify(retVal), 200
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -112,9 +112,12 @@ def _addUser(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
retVal = userController.addWorker(user['username'], date)
|
job_kind = None
|
||||||
|
if 'job_kind' in data:
|
||||||
|
job_kind = data['job_kind']
|
||||||
|
retVal = mainController.addWorker(user['username'], date, job_kind=job_kind)
|
||||||
debug.debug("retrun {{ {} }}".format(retVal))
|
debug.debug("retrun {{ {} }}".format(retVal))
|
||||||
userl = userController.getUser(user['username'])
|
userl = mainController.getUser(user['username'])
|
||||||
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
|
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
|
||||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
|
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -123,41 +126,6 @@ def _addUser(**kwargs):
|
||||||
return jsonify({"error": str(err)}), 500
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
||||||
@vorstand.route("/sm/getUsers", methods=['POST'])
|
|
||||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
|
||||||
def _getUsers(**kwrags):
|
|
||||||
debug.info("/sm/getUsers")
|
|
||||||
try:
|
|
||||||
data = request.get_json()
|
|
||||||
from_date = data['from_date']
|
|
||||||
to_date = data['to_date']
|
|
||||||
from_date = datetime(
|
|
||||||
from_date['year'], from_date['month'], from_date['day'])
|
|
||||||
to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
|
|
||||||
lockedDays = userController.getLockedDays(from_date, to_date)
|
|
||||||
retVal = []
|
|
||||||
for lockedDay in lockedDays:
|
|
||||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
|
||||||
retDay = {
|
|
||||||
"worker": userController.getWorker(day),
|
|
||||||
"day": {
|
|
||||||
"date": {
|
|
||||||
"year": day.year,
|
|
||||||
"month": day.month,
|
|
||||||
"day": day.day
|
|
||||||
},
|
|
||||||
"locked": lockedDay['locked']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@vorstand.route("/sm/getUser", methods=['POST'])
|
@vorstand.route("/sm/getUser", methods=['POST'])
|
||||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||||
def _getUser(**kwargs):
|
def _getUser(**kwargs):
|
||||||
|
@ -168,7 +136,7 @@ def _getUser(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
lockedDay = userController.getLockedDay(date)
|
lockedDay = mainController.getLockedDay(date)
|
||||||
lockedDay = {
|
lockedDay = {
|
||||||
'date': {
|
'date': {
|
||||||
'year': year,
|
'year': year,
|
||||||
|
@ -178,7 +146,7 @@ def _getUser(**kwargs):
|
||||||
'locked': lockedDay['locked']
|
'locked': lockedDay['locked']
|
||||||
}
|
}
|
||||||
retVal = {
|
retVal = {
|
||||||
'worker': userController.getWorker(date),
|
'worker': mainController.getWorker(date),
|
||||||
'day': lockedDay
|
'day': lockedDay
|
||||||
}
|
}
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
@ -199,9 +167,9 @@ def _deletUser(**kwargs):
|
||||||
month = data['month']
|
month = data['month']
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
userController.deleteWorker(user['username'], date)
|
mainController.deleteWorker(user['username'], date)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
user = userController.getUser(user['username'])
|
user = mainController.getUser(user['username'])
|
||||||
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
|
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
|
||||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
|
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
|
@ -214,7 +182,7 @@ def _deletUser(**kwargs):
|
||||||
def _getAllWorkgroups(**kwargs):
|
def _getAllWorkgroups(**kwargs):
|
||||||
try:
|
try:
|
||||||
debug.info("get all workgroups")
|
debug.info("get all workgroups")
|
||||||
retVal = userController.getAllWorkgroups()
|
retVal = mainController.getAllWorkgroups()
|
||||||
debug.info("return all workgroups {{ {} }}".format(retVal))
|
debug.info("return all workgroups {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -229,7 +197,7 @@ def _getWorkgroup(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data['name']
|
name = data['name']
|
||||||
debug.info("get workgroup {{ {} }}".format(name))
|
debug.info("get workgroup {{ {} }}".format(name))
|
||||||
retVal = userController.getWorkgroups(name)
|
retVal = mainController.getWorkgroups(name)
|
||||||
debug.info(
|
debug.info(
|
||||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -248,10 +216,10 @@ def _workgroup(**kwargs):
|
||||||
boss = None
|
boss = None
|
||||||
if 'boss' in data:
|
if 'boss' in data:
|
||||||
boss = data['boss']
|
boss = data['boss']
|
||||||
retVal = userController.setWorkgroup(name, boss)
|
retVal = mainController.setWorkgroup(name, boss)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
retVal = userController.updateWorkgroup(data)
|
retVal = mainController.updateWorkgroup(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -264,7 +232,7 @@ def _deleteWorkgroup(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
debug.info("/wgm/deleteWorkgroup")
|
debug.info("/wgm/deleteWorkgroup")
|
||||||
userController.deleteWorkgroup(data)
|
mainController.deleteWorkgroup(data)
|
||||||
retVal = {"ok": "ok"}
|
retVal = {"ok": "ok"}
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -277,7 +245,7 @@ def _deleteWorkgroup(**kwargs):
|
||||||
def _getAllJobKinds(**kwargs):
|
def _getAllJobKinds(**kwargs):
|
||||||
try:
|
try:
|
||||||
debug.info("get all jobkinds")
|
debug.info("get all jobkinds")
|
||||||
retVal = userController.getAllJobKinds()
|
retVal = mainController.getAllJobKinds()
|
||||||
debug.info("return all jobkinds {{ {} }}".format(retVal))
|
debug.info("return all jobkinds {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -292,7 +260,7 @@ def _getJobKinds(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
name = data['name']
|
name = data['name']
|
||||||
debug.info("get jobkind {{ {} }}".format(name))
|
debug.info("get jobkind {{ {} }}".format(name))
|
||||||
retVal = userController.getJobKind(name)
|
retVal = mainController.getJobKind(name)
|
||||||
debug.info(
|
debug.info(
|
||||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -311,10 +279,10 @@ def _JobKinds(**kwargs):
|
||||||
workgroup = None
|
workgroup = None
|
||||||
if 'workgroup' in data:
|
if 'workgroup' in data:
|
||||||
workgroup = data['workgroup']
|
workgroup = data['workgroup']
|
||||||
retVal = userController.setJobKind(name, workgroup)
|
retVal = mainController.setJobKind(name, workgroup)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
retVal = userController.updateJobKind(data)
|
retVal = mainController.updateJobKind(data)
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -327,7 +295,7 @@ def _deleteJobKind(**kwargs):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
debug.info("/sm/deleteJobKind")
|
debug.info("/sm/deleteJobKind")
|
||||||
userController.deleteJobKind(data)
|
mainController.deleteJobKind(data)
|
||||||
retVal = {"ok": "ok"}
|
retVal = {"ok": "ok"}
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -335,6 +303,33 @@ def _deleteJobKind(**kwargs):
|
||||||
debug.debug("exception", exc_info=True)
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 500
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
@vorstand.route("/jk/getJobKindDates", methods=['POST'])
|
||||||
|
@login_required()
|
||||||
|
def _getJobKindDates(**kwargs):
|
||||||
|
try:
|
||||||
|
debug.info("/jk/getJobKindDates")
|
||||||
|
data = request.get_json()
|
||||||
|
datum = date(data['year'], data['month'], data['day'])
|
||||||
|
retVal = mainController.getJobKindDates(datum)
|
||||||
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
@vorstand.route("/jk/JobKindDate", methods=['POST'])
|
||||||
|
@login_required(groups=[VORSTAND])
|
||||||
|
def _jobKindDates(**kwargs):
|
||||||
|
try:
|
||||||
|
debug.info("/jk/JobKindDate")
|
||||||
|
data = request.get_json()
|
||||||
|
retVal = mainController.controllJobKindDates(data)
|
||||||
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
@vorstand.route("/sm/lockDay", methods=['POST'])
|
@vorstand.route("/sm/lockDay", methods=['POST'])
|
||||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||||
def _lockDay(**kwargs):
|
def _lockDay(**kwargs):
|
||||||
|
@ -346,7 +341,7 @@ def _lockDay(**kwargs):
|
||||||
day = data['day']
|
day = data['day']
|
||||||
locked = data['locked']
|
locked = data['locked']
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
lockedDay = userController.setLockedDay(date, locked, True)
|
lockedDay = mainController.setLockedDay(date, locked, True)
|
||||||
if not lockedDay:
|
if not lockedDay:
|
||||||
retVal = {
|
retVal = {
|
||||||
'date': {
|
'date': {
|
||||||
|
|
Loading…
Reference in New Issue