Merge branch 'feature/jobkind' into develop
This commit is contained in:
commit
5835cec4a4
|
@ -1,6 +1,6 @@
|
|||
from flask import Blueprint, request, jsonify
|
||||
import geruecht.controller.ldapController as lc
|
||||
import geruecht.controller.userController as uc
|
||||
import geruecht.controller.mainController as mc
|
||||
from datetime import datetime
|
||||
from geruecht.model import BAR, MONEY, USER, VORSTAND
|
||||
from geruecht.decorator import login_required
|
||||
|
@ -12,7 +12,7 @@ creditL = getCreditLogger()
|
|||
baruser = Blueprint("baruser", __name__)
|
||||
|
||||
ldap = lc.LDAPController()
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
|
||||
@baruser.route("/bar")
|
||||
|
@ -29,7 +29,7 @@ def _bar(**kwargs):
|
|||
debug.info("/bar")
|
||||
try:
|
||||
dic = {}
|
||||
users = userController.getAllUsersfromDB()
|
||||
users = mainController.getAllUsersfromDB()
|
||||
for user in users:
|
||||
geruecht = None
|
||||
geruecht = user.getGeruecht(datetime.now().year)
|
||||
|
@ -72,9 +72,9 @@ def _baradd(**kwargs):
|
|||
amount = int(data['amount'])
|
||||
amountl = amount
|
||||
date = datetime.now()
|
||||
userController.addAmount(
|
||||
mainController.addAmount(
|
||||
userID, amount, year=date.year, month=date.month)
|
||||
user = userController.getUser(userID)
|
||||
user = mainController.getUser(userID)
|
||||
geruecht = user.getGeruecht(year=date.year)
|
||||
month = geruecht.getMonth(month=date.month)
|
||||
amount = abs(month[0] - month[1])
|
||||
|
@ -135,9 +135,9 @@ def _storno(**kwargs):
|
|||
amount = int(data['amount'])
|
||||
amountl = amount
|
||||
date = datetime.now()
|
||||
userController.addCredit(
|
||||
mainController.addCredit(
|
||||
userID, amount, year=date.year, month=date.month)
|
||||
user = userController.getUser(userID)
|
||||
user = mainController.getUser(userID)
|
||||
geruecht = user.getGeruecht(year=date.year)
|
||||
month = geruecht.getMonth(month=date.month)
|
||||
amount = abs(month[0] - month[1])
|
||||
|
@ -165,7 +165,7 @@ def _getUser(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
username = data['userId']
|
||||
user = userController.getUser(username)
|
||||
user = mainController.getUser(username)
|
||||
amount = user.getGeruecht(datetime.now().year).getSchulden()
|
||||
if amount >= 0:
|
||||
type = 'credit'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from geruecht.model.accessToken import AccessToken
|
||||
import geruecht.controller as gc
|
||||
import geruecht.controller.userController as uc
|
||||
import geruecht.controller.mainController as mc
|
||||
from geruecht.model import BAR
|
||||
from datetime import datetime, timedelta
|
||||
import hashlib
|
||||
|
@ -9,7 +9,7 @@ from geruecht.logger import getDebugLogger
|
|||
|
||||
debug = getDebugLogger()
|
||||
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
class AccesTokenController(metaclass=Singleton):
|
||||
""" Control all createt AccesToken
|
||||
|
@ -34,7 +34,7 @@ class AccesTokenController(metaclass=Singleton):
|
|||
|
||||
def checkBar(self, user):
|
||||
debug.info("check if user {{ {} }} is baruser".format(user))
|
||||
if (userController.checkBarUser(user)):
|
||||
if (mainController.checkBarUser(user)):
|
||||
if BAR not in user.group:
|
||||
debug.debug("append bar to user {{ {} }}".format(user))
|
||||
user.group.append(BAR)
|
||||
|
|
|
@ -1,706 +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))
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = DatabaseController()
|
||||
user = db.getUser('jhille')
|
||||
db.getCreditListFromUser(user, year=2018)
|
|
@ -0,0 +1,69 @@
|
|||
from ..mainController import Singleton
|
||||
from geruecht import db
|
||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
import traceback
|
||||
from MySQLdb._exceptions import IntegrityError
|
||||
|
||||
class DatabaseController(dbUserController.Base,
|
||||
dbCreditListController.Base,
|
||||
dbWorkerController.Base,
|
||||
dbWorkgroupController.Base,
|
||||
dbPricelistController.Base,
|
||||
dbJobKindController.Base,
|
||||
dbJobInviteController.Base,
|
||||
dbJobRequesController.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,84 @@
|
|||
import traceback
|
||||
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
|
||||
|
||||
class Base:
|
||||
def getJobInvite(self, from_user, to_user, date, id=None):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
if id:
|
||||
cursor.execute("select * from job_invites where id={}".format(id))
|
||||
else:
|
||||
cursor.execute("select * from job_invites where from_user={} and to_user={} and on_date='{}'".format(from_user['id'], to_user['id'], date))
|
||||
retVal = cursor.fetchone()
|
||||
retVal['to_user'] = self.getUserById(retVal['to_user']).toJSON()
|
||||
retVal['from_user'] = self.getUserById(retVal['from_user']).toJSON()
|
||||
retVal['on_date'] = {'year': retVal['on_date'].year, 'month': retVal['on_date'].month, 'day': retVal['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobInvitesFromUser(self, from_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_invites where from_user={} and on_date>='{}'".format(from_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = from_user
|
||||
item['to_user'] = self.getUserById(item['to_user']).toJSON()
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobInvitesToUser(self, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_invites where to_user={} and on_date>='{}'".format(to_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = self.getUserById(item['from_user']).toJSON()
|
||||
item['to_user'] = to_user
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def setJobInvite(self, from_user, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("insert into job_invites (from_user, to_user, on_date) values ({}, {}, '{}')".format(from_user['id'], to_user['id'], date))
|
||||
self.db.connection.commit()
|
||||
return self.getJobInvite(from_user, to_user, date)
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def updateJobInvite(self, jobinvite):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update job_invites set watched={} where id={}".format(jobinvite['watched'], jobinvite['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getJobInvite(None, None, None, jobinvite['id'])
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def deleteJobInvite(self, jobinvite):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("delete from job_invites where id={}".format(jobinvite['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))
|
|
@ -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,97 @@
|
|||
import traceback
|
||||
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
|
||||
|
||||
class Base:
|
||||
def getJobRequest(self, from_user, to_user, date, id=None):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
if id:
|
||||
cursor.execute("select * from job_request where id={}".format(id))
|
||||
else:
|
||||
cursor.execute("select * from job_request where from_user={} and to_user={} and on_date='{}'".format(from_user['id'], to_user['id'], date))
|
||||
retVal = cursor.fetchone()
|
||||
retVal['to_user'] = self.getUserById(retVal['to_user']).toJSON()
|
||||
retVal['from_user'] = self.getUserById(retVal['from_user']).toJSON()
|
||||
retVal['on_date'] = {'year': retVal['on_date'].year, 'month': retVal['on_date'].month, 'day': retVal['on_date'].day}
|
||||
retVal['job_kind'] = self.getJobKind(retVal['job_kind'])
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobRequestsFromUser(self, from_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_request where from_user={} and on_date>='{}'".format(from_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = from_user
|
||||
item['to_user'] = self.getUserById(item['to_user']).toJSON()
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
item['job_kind'] = self.getJobKind(item['job_kind'])
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobRequestsToUser(self, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_request where to_user={} and on_date>='{}'".format(to_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = self.getUserById(item['from_user']).toJSON()
|
||||
item['to_user'] = to_user
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
item['job_kind'] = self.getJobKind(item['job_kind'])
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def setJobRequest(self, from_user, to_user, date, job_kind):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("insert into job_request (from_user, to_user, on_date, job_kind) values ({}, {}, '{}', {})".format(from_user['id'], to_user['id'], date, job_kind['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getJobRequest(from_user, to_user, date)
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def updateJobRequest(self, jobrequest):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update job_request set watched={}, answered={}, accepted={} where id={}".format(jobrequest['watched'], jobrequest['answered'], jobrequest['accepted'], jobrequest['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getJobRequest(None, None, None, jobrequest['id'])
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def updateAllJobRequest(self, jobrequest):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update job_request set answered={} where from_user={} and on_date='{}'".format(jobrequest['answered'], jobrequest['from_user']['id'], jobrequest['on_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 deleteJobRequest(self, jobrequest):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("delete from job_request where id={}".format(jobrequest['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))
|
|
@ -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,77 @@
|
|||
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 changeWorker(self, from_user, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update bardienste set user_id={} where user_id={} and startdatetime='{}'".format(to_user['id'], from_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 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.header import Header
|
||||
from geruecht.logger import getDebugLogger
|
||||
from . import mailConfig
|
||||
|
||||
debug = getDebugLogger()
|
||||
|
||||
class EmailController():
|
||||
|
||||
def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""):
|
||||
def __init__(self):
|
||||
debug.info("init email controller")
|
||||
self.smtpServer = smtpServer
|
||||
self.port = port
|
||||
self.user = user
|
||||
self.passwd = passwd
|
||||
self.crypt = crypt
|
||||
if email:
|
||||
self.email = email
|
||||
else:
|
||||
self.email = user
|
||||
debug.debug("smtpServer is {{ {} }}, port is {{ {} }}, user is {{ {} }}, crypt is {{ {} }}, email is {{ {} }}".format(smtpServer, port, user, crypt, self.email))
|
||||
self.smtpServer = mailConfig['URL']
|
||||
self.port = mailConfig['port']
|
||||
self.user = mailConfig['user']
|
||||
self.passwd = mailConfig['passwd']
|
||||
self.crypt = mailConfig['crypt']
|
||||
self.email = mailConfig['email']
|
||||
|
||||
debug.debug("smtpServer is {{ {} }}, port is {{ {} }}, user is {{ {} }}, crypt is {{ {} }}, email is {{ {} }}".format(self.smtpServer, self.port, self.user, self.crypt, self.email))
|
||||
|
||||
def __connect__(self):
|
||||
debug.info('connect to email server')
|
||||
|
|
|
@ -71,6 +71,8 @@ class LDAPController(metaclass=Singleton):
|
|||
main_group_number = self.ldap.connection.response[0]['attributes']['gidNumber']
|
||||
debug.debug("main group number is {{ {} }}".format(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'])
|
||||
group_name = self.ldap.connection.response[0]['attributes']['cn'][0]
|
||||
debug.debug("group name is {{ {} }}".format(group_name))
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
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, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController
|
||||
|
||||
db = dc.DatabaseController()
|
||||
ldap = lc.LDAPController()
|
||||
emailController = ec.EmailController()
|
||||
|
||||
debug = getDebugLogger()
|
||||
|
||||
|
||||
class MainController(mainJobKindController.Base,
|
||||
mainCreditListController.Base,
|
||||
mainPricelistController.Base,
|
||||
mainUserController.Base,
|
||||
mainWorkerController.Base,
|
||||
mainWorkgroupController.Base,
|
||||
mainJobInviteController.Base,
|
||||
mainJobRequestController.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 getLockedDaysFromList(self, date_list):
|
||||
debug.info("get locked days from list {{ {} }}".format(date_list))
|
||||
retVal = []
|
||||
for on_date in date_list:
|
||||
day = datetime(on_date['on_date']['year'], on_date['on_date']['month'], on_date['on_date']['day'], 12)
|
||||
retVal.append(self.getLockedDay(day))
|
||||
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,38 @@
|
|||
from datetime import date
|
||||
|
||||
import geruecht.controller.databaseController as dc
|
||||
from geruecht import getDebugLogger
|
||||
|
||||
db = dc.DatabaseController()
|
||||
debug = getDebugLogger()
|
||||
|
||||
class Base:
|
||||
def getJobInvites(self, from_user, to_user, date):
|
||||
debug.info("get JobInvites from_user {{ {} }} to_user {{ {} }} on date {{ {} }}".format(from_user, to_user, date))
|
||||
if from_user is None:
|
||||
retVal = db.getJobInvitesToUser(to_user, date)
|
||||
elif to_user is None:
|
||||
retVal = db.getJobInvitesFromUser(from_user, date)
|
||||
else:
|
||||
raise Exception("from_user {{ {} }} and to_user {{ {} }} are None".format(from_user, to_user))
|
||||
return retVal
|
||||
|
||||
def setJobInvites(self, data):
|
||||
debug.info("set new JobInvites data {{ {} }}".format(data))
|
||||
retVal = []
|
||||
for jobInvite in data:
|
||||
from_user = jobInvite['from_user']
|
||||
to_user = jobInvite['to_user']
|
||||
on_date = date(jobInvite['date']['year'], jobInvite['date']['month'], jobInvite['date']['day'])
|
||||
debug.info("set new JobInvite from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}")
|
||||
retVal.append(db.setJobInvite(from_user, to_user, on_date))
|
||||
debug.debug("seted JobInvites are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def updateJobInvites(self, data):
|
||||
debug.info("update JobInvites data {{ {} }}".format(data))
|
||||
return db.updateJobInvite(data)
|
||||
|
||||
def deleteJobInvite(self, jobInvite):
|
||||
debug.info("delete JobInvite {{ {} }}".format(jobInvite))
|
||||
db.deleteJobInvite(jobInvite)
|
|
@ -0,0 +1,90 @@
|
|||
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:
|
||||
if jobkinddate['job_kind']:
|
||||
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,42 @@
|
|||
from datetime import date, time, datetime
|
||||
|
||||
import geruecht.controller.databaseController as dc
|
||||
from geruecht import getDebugLogger
|
||||
|
||||
db = dc.DatabaseController()
|
||||
debug = getDebugLogger()
|
||||
|
||||
class Base:
|
||||
def getJobRequests(self, from_user, to_user, date):
|
||||
debug.info("get JobRequests from_user {{ {} }} to_user {{ {} }} on date {{ {} }}".format(from_user, to_user, date))
|
||||
if from_user is None:
|
||||
retVal = db.getJobRequestsToUser(to_user, date)
|
||||
elif to_user is None:
|
||||
retVal = db.getJobRequestsFromUser(from_user, date)
|
||||
else:
|
||||
raise Exception("from_user {{ {} }} and to_user {{ {} }} are None".format(from_user, to_user))
|
||||
return retVal
|
||||
|
||||
def setJobRequests(self, data):
|
||||
debug.info("set new JobRequests data {{ {} }}".format(data))
|
||||
retVal = []
|
||||
for jobRequest in data:
|
||||
from_user = jobRequest['from_user']
|
||||
to_user = jobRequest['to_user']
|
||||
on_date = date(jobRequest['date']['year'], jobRequest['date']['month'], jobRequest['date']['day'])
|
||||
job_kind = jobRequest['job_kind']
|
||||
debug.info("set new JobRequest from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}")
|
||||
retVal.append(db.setJobRequest(from_user, to_user, on_date, job_kind))
|
||||
debug.debug("seted JobRequests are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def updateJobRequests(self, data):
|
||||
debug.info("update JobRequest data {{ {} }}".format(data))
|
||||
if data['accepted']:
|
||||
self.changeWorker(data['from_user'], data['to_user'], datetime.combine(data['on_date'], time(12)))
|
||||
db.updateAllJobRequest(data)
|
||||
return db.updateJobRequest(data)
|
||||
|
||||
def deleteJobRequest(self, jobRequest):
|
||||
debug.info("delete JobRequest {{ {} }}".format(jobRequest))
|
||||
db.deleteJobRequest(jobRequest)
|
|
@ -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,58 @@
|
|||
from datetime import time, datetime
|
||||
|
||||
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 changeWorker(self, from_user, to_user, date):
|
||||
debug.info("change worker from {{ {} }} to {{ {} }} on {{ {} }}".format(from_user, to_user, date))
|
||||
db.changeWorker(from_user, to_user, date)
|
||||
|
||||
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']:
|
||||
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,559 +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 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 datetime import datetime
|
||||
import geruecht.controller.userController as uc
|
||||
import geruecht.controller.mainController as mc
|
||||
from geruecht.model import MONEY
|
||||
from geruecht.decorator import login_required
|
||||
from geruecht.logger import getDebugLogger, getCreditLogger
|
||||
|
@ -10,7 +10,7 @@ creditL = getCreditLogger()
|
|||
|
||||
finanzer = Blueprint("finanzer", __name__)
|
||||
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
|
||||
@finanzer.route("/getFinanzerMain")
|
||||
|
@ -26,7 +26,7 @@ def _getFinanzer(**kwargs):
|
|||
"""
|
||||
debug.info("/getFinanzerMain")
|
||||
try:
|
||||
users = userController.getAllUsersfromDB()
|
||||
users = mainController.getAllUsersfromDB()
|
||||
dic = {}
|
||||
for user in users:
|
||||
dic[user.uid] = user.toJSON()
|
||||
|
@ -65,9 +65,9 @@ def _addAmount(**kwargs):
|
|||
month = int(data['month'])
|
||||
except KeyError:
|
||||
month = datetime.now().month
|
||||
userController.addAmount(
|
||||
mainController.addAmount(
|
||||
userID, amount, year=year, month=month, finanzer=True)
|
||||
user = userController.getUser(userID)
|
||||
user = mainController.getUser(userID)
|
||||
retVal = {str(geruecht.year): geruecht.toJSON()
|
||||
for geruecht in user.geruechte}
|
||||
retVal['locked'] = user.locked
|
||||
|
@ -108,9 +108,9 @@ def _addCredit(**kwargs):
|
|||
except KeyError:
|
||||
month = datetime.now().month
|
||||
|
||||
userController.addCredit(
|
||||
mainController.addCredit(
|
||||
userID, credit, year=year, month=month).toJSON()
|
||||
user = userController.getUser(userID)
|
||||
user = mainController.getUser(userID)
|
||||
retVal = {str(geruecht.year): geruecht.toJSON()
|
||||
for geruecht in user.geruechte}
|
||||
retVal['locked'] = user.locked
|
||||
|
@ -131,7 +131,7 @@ def _finanzerLock(**kwargs):
|
|||
data = request.get_json()
|
||||
username = data['userId']
|
||||
locked = bool(data['locked'])
|
||||
retVal = userController.lockUser(username, locked).toJSON()
|
||||
retVal = mainController.lockUser(username, locked).toJSON()
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -148,7 +148,7 @@ def _finanzerSetConfig(**kwargs):
|
|||
username = data['userId']
|
||||
autoLock = bool(data['autoLock'])
|
||||
limit = int(data['limit'])
|
||||
retVal = userController.updateConfig(
|
||||
retVal = mainController.updateConfig(
|
||||
username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON()
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
|
@ -164,8 +164,8 @@ def _finanzerAddUser(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
username = data['userId']
|
||||
userController.getUser(username)
|
||||
users = userController.getAllUsersfromDB()
|
||||
mainController.getUser(username)
|
||||
users = mainController.getAllUsersfromDB()
|
||||
dic = {}
|
||||
for user in users:
|
||||
dic[user.uid] = user.toJSON()
|
||||
|
@ -185,7 +185,7 @@ def _finanzerSendOneMail(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
username = data['userId']
|
||||
retVal = userController.sendMail(username)
|
||||
retVal = mainController.sendMail(username)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -198,7 +198,7 @@ def _finanzerSendOneMail(**kwargs):
|
|||
def _finanzerSendAllMail(**kwargs):
|
||||
debug.info("/finanzerSendAllMail")
|
||||
try:
|
||||
retVal = userController.sendAllMail()
|
||||
retVal = mainController.sendAllMail()
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from flask import request, jsonify, Blueprint
|
||||
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.logger import getCreditLogger, getDebugLogger
|
||||
|
||||
|
@ -8,7 +8,7 @@ debug = getDebugLogger()
|
|||
|
||||
gastrouser = Blueprint('gastrouser', __name__)
|
||||
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
|
||||
@gastrouser.route('/gastro/setDrink', methods=['POST'])
|
||||
|
@ -17,7 +17,7 @@ def setDrink(**kwargs):
|
|||
debug.info("/gastro/setDrink")
|
||||
try:
|
||||
data = request.get_json()
|
||||
retVal = userController.setDrinkPrice(data)
|
||||
retVal = mainController.setDrinkPrice(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -31,7 +31,7 @@ def updateDrink(**kwargs):
|
|||
debug.info("/gastro/updateDrink")
|
||||
try:
|
||||
data = request.get_json()
|
||||
retVal = userController.updateDrinkPrice(data)
|
||||
retVal = mainController.updateDrinkPrice(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -46,7 +46,7 @@ def deleteDrink(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
id = data['id']
|
||||
userController.deletDrinkPrice({"id": id})
|
||||
mainController.deletDrinkPrice({"id": id})
|
||||
debug.debug("return ok")
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
|
@ -61,7 +61,7 @@ def setType(**kwark):
|
|||
try:
|
||||
data = request.get_json()
|
||||
name = data['name']
|
||||
retVal = userController.setDrinkType(name)
|
||||
retVal = mainController.setDrinkType(name)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -75,7 +75,7 @@ def updateType(**kwargs):
|
|||
debug.info("/gastro/updateDrinkType")
|
||||
try:
|
||||
data = request.get_json()
|
||||
retVal = userController.updateDrinkType(data)
|
||||
retVal = mainController.updateDrinkType(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -89,7 +89,7 @@ def deleteType(**kwargs):
|
|||
debug.info("/gastro/deleteDrinkType")
|
||||
try:
|
||||
data = request.get_json()
|
||||
userController.deleteDrinkType(data)
|
||||
mainController.deleteDrinkType(data)
|
||||
debug.debug("return ok")
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
|
|
|
@ -3,12 +3,12 @@ from geruecht.logger import getDebugLogger
|
|||
from geruecht.decorator import login_required
|
||||
from geruecht.exceptions import PermissionDenied
|
||||
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 flask import request, jsonify
|
||||
|
||||
accesTokenController = ac.AccesTokenController()
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
debug = getDebugLogger()
|
||||
|
||||
|
@ -19,7 +19,7 @@ def _valid(**kwargs):
|
|||
try:
|
||||
accToken = kwargs['accToken']
|
||||
data = request.get_json()
|
||||
userController.validateUser(accToken.user.uid, data['password'])
|
||||
mainController.validateUser(accToken.user.uid, data['password'])
|
||||
debug.debug('return {{ "ok": "ok" }}')
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
|
@ -30,7 +30,7 @@ def _valid(**kwargs):
|
|||
def _getPricelist():
|
||||
try:
|
||||
debug.info("get pricelist")
|
||||
retVal = userController.getPricelist()
|
||||
retVal = mainController.getPricelist()
|
||||
debug.info("return pricelist {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -42,7 +42,7 @@ def _getPricelist():
|
|||
def getTypes():
|
||||
try:
|
||||
debug.info("get drinktypes")
|
||||
retVal = userController.getAllDrinkTypes()
|
||||
retVal = mainController.getAllDrinkTypes()
|
||||
debug.info("return drinktypes {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -55,7 +55,7 @@ def getTypes():
|
|||
def _getAllStatus(**kwargs):
|
||||
try:
|
||||
debug.info("get all status for users")
|
||||
retVal = userController.getAllStatus()
|
||||
retVal = mainController.getAllStatus()
|
||||
debug.info("return all status for users {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -71,7 +71,7 @@ def _getStatus(**kwargs):
|
|||
data = request.get_json()
|
||||
name = data['name']
|
||||
debug.info("get status from user {{ {} }}".format(name))
|
||||
retVal = userController.getStatus(name)
|
||||
retVal = mainController.getStatus(name)
|
||||
debug.info(
|
||||
"return status from user {{ {} }} : {{ {} }}".format(name, retVal))
|
||||
return jsonify(retVal)
|
||||
|
@ -81,11 +81,14 @@ def _getStatus(**kwargs):
|
|||
|
||||
|
||||
@app.route('/getUsers', methods=['GET'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND], bar=True)
|
||||
@login_required(groups=[USER], bar=True)
|
||||
def _getUsers(**kwargs):
|
||||
try:
|
||||
extern = True
|
||||
if 'extern' in request.args:
|
||||
extern = not bool(int(request.args['extern']))
|
||||
debug.info("get all users from database")
|
||||
users = userController.getAllUsersfromDB()
|
||||
users = mainController.getAllUsersfromDB(extern=extern)
|
||||
debug.debug("users are {{ {} }}".format(users))
|
||||
retVal = [user.toJSON() for user in users]
|
||||
debug.info("return all users from database {{ {} }}".format(retVal))
|
||||
|
@ -173,7 +176,7 @@ def _login():
|
|||
debug.debug("username is {{ {} }}".format(username))
|
||||
try:
|
||||
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))
|
||||
user.password = password
|
||||
token = accesTokenController.createAccesToken(user, ldap_conn)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
from flask import Blueprint, request, jsonify
|
||||
from geruecht.decorator import login_required
|
||||
import geruecht.controller.userController as uc
|
||||
import geruecht.controller.mainController as mc
|
||||
from geruecht.model import USER
|
||||
from datetime import datetime, time
|
||||
from datetime import datetime, time, date
|
||||
from geruecht.exceptions import DayLocked
|
||||
from geruecht.logger import getDebugLogger, getCreditLogger, getJobsLogger
|
||||
|
||||
user = Blueprint("user", __name__)
|
||||
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
|
||||
debug = getDebugLogger()
|
||||
creditL = getCreditLogger()
|
||||
|
@ -22,7 +22,7 @@ def _main(**kwargs):
|
|||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
accToken.user = userController.getUser(accToken.user.uid)
|
||||
accToken.user = mainController.getUser(accToken.user.uid)
|
||||
retVal = accToken.user.toJSON()
|
||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||
for credit in accToken.user.geruechte}
|
||||
|
@ -43,9 +43,9 @@ def _addAmount(**kwargs):
|
|||
data = request.get_json()
|
||||
amount = int(data['amount'])
|
||||
date = datetime.now()
|
||||
userController.addAmount(
|
||||
mainController.addAmount(
|
||||
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['creditList'] = {credit.year: credit.toJSON()
|
||||
for credit in accToken.user.geruechte}
|
||||
|
@ -66,7 +66,7 @@ def _saveConfig(**kwargs):
|
|||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
data = request.get_json()
|
||||
accToken.user = userController.modifyUser(
|
||||
accToken.user = mainController.modifyUser(
|
||||
accToken.user, accToken.ldap_conn, data)
|
||||
retVal = accToken.user.toJSON()
|
||||
retVal['creditList'] = {credit.year: credit.toJSON()
|
||||
|
@ -89,12 +89,12 @@ def _getUsers(**kwrags):
|
|||
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)
|
||||
lockedDays = mainController.getLockedDays(from_date, to_date)
|
||||
retVal = []
|
||||
for lockedDay in lockedDays:
|
||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
||||
retDay = {
|
||||
"worker": userController.getWorker(day),
|
||||
"worker": mainController.getWorker(day),
|
||||
"day": {
|
||||
"date": {
|
||||
"year": day.year,
|
||||
|
@ -102,7 +102,8 @@ def _getUsers(**kwrags):
|
|||
"day": day.day
|
||||
},
|
||||
"locked": lockedDay['locked']
|
||||
}
|
||||
},
|
||||
"jobkinddate": mainController.getJobKindDates(day.date())
|
||||
}
|
||||
retVal.append(retDay)
|
||||
|
||||
|
@ -112,6 +113,35 @@ def _getUsers(**kwrags):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/jobsOnDates", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getJobsOnDates(**kwargs):
|
||||
debug.info("/user/jobsOnDates")
|
||||
try:
|
||||
data = request.get_json()
|
||||
lockedDays = mainController.getLockedDaysFromList(data)
|
||||
retVal = []
|
||||
for lockedDay in lockedDays:
|
||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
||||
retDay = {
|
||||
"worker": mainController.getWorker(day),
|
||||
"day": {
|
||||
"date": {
|
||||
"year": day.year,
|
||||
"month": day.month,
|
||||
"day": day.day
|
||||
},
|
||||
"locked": lockedDay['locked']
|
||||
},
|
||||
"jobkinddate": mainController.getJobKindDates(day.date())
|
||||
}
|
||||
retVal.append(retDay)
|
||||
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/job", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
|
@ -123,7 +153,7 @@ def _getUser(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
lockedDay = userController.getLockedDay(date)
|
||||
lockedDay = mainController.getLockedDay(date)
|
||||
if not lockedDay:
|
||||
lockedDay = {
|
||||
'date': {
|
||||
|
@ -143,7 +173,7 @@ def _getUser(**kwargs):
|
|||
'locked': lockedDay['locked']
|
||||
}
|
||||
retVal = {
|
||||
'worker': userController.getWorker(date),
|
||||
'worker': mainController.getWorker(date),
|
||||
'day': lockedDay
|
||||
}
|
||||
debug.debug("retrun {{ {} }}".format(retVal))
|
||||
|
@ -166,7 +196,11 @@ def _addUser(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
retVal = userController.addWorker(user.uid, date, userExc=True)
|
||||
job_kind = None
|
||||
if 'job_kind' in data:
|
||||
job_kind = data['job_kind']
|
||||
mainController.addWorker(user.uid, date, job_kind=job_kind, userExc=True)
|
||||
retVal = mainController.getWorker(date)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(
|
||||
user.firstname, user.lastname, date.date()))
|
||||
|
@ -192,11 +226,12 @@ def _deletJob(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
userController.deleteWorker(user.uid, date, True)
|
||||
mainController.deleteWorker(user.uid, date, True)
|
||||
retVal = mainController.getWorker(date)
|
||||
debug.debug("return ok")
|
||||
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
||||
user.firstname, user.lastname, date.date()))
|
||||
return jsonify({"ok": "ok"})
|
||||
return jsonify(retVal)
|
||||
except DayLocked as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 403
|
||||
|
@ -204,148 +239,6 @@ def _deletJob(**kwargs):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/transactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _transactJob(**kwargs):
|
||||
debug.info("/user/transactJob")
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
user = accToken.user
|
||||
data = request.get_json()
|
||||
year = data['year']
|
||||
month = data['month']
|
||||
day = data['day']
|
||||
username = data['user']
|
||||
date = datetime(year, month, day, 12)
|
||||
to_user = userController.getUser(username)
|
||||
retVal = userController.setTransactJob(user, to_user, date)
|
||||
from_userl = retVal['from_user']
|
||||
to_userl = retVal['to_user']
|
||||
retVal['from_user'] = retVal['from_user'].toJSON()
|
||||
retVal['to_user'] = retVal['to_user'].toJSON()
|
||||
retVal['date'] = {'year': year, 'month': month, 'day': day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
jobL.info("Mitglied {} {} sendet Dienstanfrage an Mitglied {} {} am {}".format(
|
||||
from_userl.firstname, from_userl.lastname, to_userl.firstname, to_userl.lastname, date.date()))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/answerTransactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _answer(**kwargs):
|
||||
debug.info("/user/answerTransactJob")
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
user = accToken.user
|
||||
data = request.get_json()
|
||||
year = data['year']
|
||||
month = data['month']
|
||||
day = data['day']
|
||||
answer = data['answer']
|
||||
username = data['username']
|
||||
date = datetime(year, month, day, 12)
|
||||
from_user = userController.getUser(username)
|
||||
retVal = userController.answerdTransactJob(
|
||||
from_user, user, date, answer)
|
||||
from_userl = retVal['from_user']
|
||||
to_userl = retVal['to_user']
|
||||
retVal['from_user'] = retVal['from_user'].toJSON()
|
||||
retVal['to_user'] = retVal['to_user'].toJSON()
|
||||
retVal['date'] = {'year': year, 'month': month, 'day': day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
jobL.info("Mitglied {} {} beantwortet Dienstanfrage von {} {} am {} mit {}".format(to_userl.firstname,
|
||||
to_userl.lastname, from_userl.firstname, from_userl.lastname, date.date(), 'JA' if answer else 'NEIN'))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/jobRequests", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _requests(**kwargs):
|
||||
debug.info("/user/jobRequests")
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
user = accToken.user
|
||||
data = request.get_json()
|
||||
year = data['year']
|
||||
month = data['month']
|
||||
day = data['day']
|
||||
date = datetime(year, month, day, 12)
|
||||
retVal = userController.getAllTransactJobToUser(user, date)
|
||||
for data in retVal:
|
||||
data['from_user'] = data['from_user'].toJSON()
|
||||
data['to_user'] = data['to_user'].toJSON()
|
||||
data_date = data['date']
|
||||
data['date'] = {'year': data_date.year,
|
||||
'month': data_date.month, 'day': data_date.day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/getTransactJobs", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getTransactJobs(**kwargs):
|
||||
debug.info("/user/getTransactJobs")
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
user = accToken.user
|
||||
data = request.get_json()
|
||||
year = data['year']
|
||||
month = data['month']
|
||||
day = data['day']
|
||||
date = datetime(year, month, day, 12)
|
||||
retVal = userController.getAllTransactJobFromUser(user, date)
|
||||
for data in retVal:
|
||||
data['from_user'] = data['from_user'].toJSON()
|
||||
data['to_user'] = data['to_user'].toJSON()
|
||||
data_date = data['date']
|
||||
data['date'] = {'year': data_date.year,
|
||||
'month': data_date.month, 'day': data_date.day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/deleteTransactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deleteTransactJob(**kwargs):
|
||||
debug.info("/user/deleteTransactJob")
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
from_user = accToken.user
|
||||
data = request.get_json()
|
||||
year = data['year']
|
||||
month = data['month']
|
||||
day = data['day']
|
||||
username = data['username']
|
||||
date = datetime(year, month, day, 12)
|
||||
to_user = userController.getUser(username)
|
||||
userController.deleteTransactJob(from_user, to_user, date)
|
||||
debug.debug("return ok")
|
||||
jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(
|
||||
from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date()))
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/storno", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _storno(**kwargs):
|
||||
|
@ -367,9 +260,9 @@ def _storno(**kwargs):
|
|||
amount = int(data['amount'])
|
||||
|
||||
date = datetime.now()
|
||||
userController.addCredit(
|
||||
mainController.addCredit(
|
||||
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['creditList'] = {credit.year: credit.toJSON()
|
||||
for credit in accToken.user.geruechte}
|
||||
|
@ -379,4 +272,117 @@ def _storno(**kwargs):
|
|||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
|
||||
@user.route("/user/getJobInvites", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getJobInvites(**kwargs):
|
||||
try:
|
||||
debug.info("/user/getJobInvites")
|
||||
from_user = None
|
||||
to_user = None
|
||||
on_date = None
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
if 'from_user' in data:
|
||||
from_user = data['from_user']
|
||||
if 'to_user' in data:
|
||||
to_user = data['to_user']
|
||||
on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
||||
retVal = mainController.getJobInvites(from_user, to_user, on_date)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/JobInvites", methods=['PUT', 'POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _JobInvites(**kwargs):
|
||||
try:
|
||||
debug.info("/user/JobInvites")
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
mainController.setJobInvites(data)
|
||||
retVal = mainController.getJobInvites(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = mainController.updateJobInvites(data)
|
||||
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/deleteJobInvite", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deleteJobInvite(**kwargs):
|
||||
try:
|
||||
debug.info("/user/deleteJobInvite")
|
||||
data = request.get_json()
|
||||
mainController.deleteJobInvite(data)
|
||||
retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
|
||||
@user.route("/user/getJobRequests", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getJobRequests(**kwargs):
|
||||
try:
|
||||
debug.info("/user/getJobRequests")
|
||||
from_user = None
|
||||
to_user = None
|
||||
on_date = None
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
if 'from_user' in data:
|
||||
from_user = data['from_user']
|
||||
if 'to_user' in data:
|
||||
to_user = data['to_user']
|
||||
on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
||||
retVal = mainController.getJobRequests(from_user, to_user, on_date)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/JobRequests", methods=['PUT', 'POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _JobRequests(**kwargs):
|
||||
try:
|
||||
debug.info("/user/JobRequests")
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
mainController.setJobRequests(data)
|
||||
retVal = mainController.getJobRequests(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
data['on_date'] = date(data['on_date']['year'], data['on_date']['month'], data['on_date']['day'])
|
||||
retVal = mainController.updateJobRequests(data)
|
||||
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/deleteJobRequest", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deleteJobRequest(**kwargs):
|
||||
try:
|
||||
debug.info("/user/deleteJobRequest")
|
||||
data = request.get_json()
|
||||
mainController.deleteJobRequest(data)
|
||||
retVal = mainController.getJobRequests(data['from_user'], None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
|
@ -1,6 +1,6 @@
|
|||
from flask import Blueprint, request, jsonify
|
||||
from datetime import datetime, time
|
||||
import geruecht.controller.userController as uc
|
||||
from datetime import datetime, time, date
|
||||
import geruecht.controller.mainController as mc
|
||||
import geruecht.controller.ldapController as lc
|
||||
from geruecht.decorator import login_required
|
||||
from geruecht.model import MONEY, GASTRO, VORSTAND
|
||||
|
@ -10,7 +10,7 @@ debug = getDebugLogger()
|
|||
jobL = getJobsLogger()
|
||||
|
||||
vorstand = Blueprint("vorstand", __name__)
|
||||
userController = uc.UserController()
|
||||
mainController = mc.MainController()
|
||||
ldap = lc.LDAPController()
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ def _setStatus(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
name = data['name']
|
||||
retVal = userController.setStatus(name)
|
||||
retVal = mainController.setStatus(name)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -35,7 +35,7 @@ def _updateStatus(**kwargs):
|
|||
debug.info("/um/updateStatus")
|
||||
try:
|
||||
data = request.get_json()
|
||||
retVal = userController.updateStatus(data)
|
||||
retVal = mainController.updateStatus(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -49,7 +49,7 @@ def _deleteStatus(**kwargs):
|
|||
debug.info("/um/deleteStatus")
|
||||
try:
|
||||
data = request.get_json()
|
||||
userController.deleteStatus(data)
|
||||
mainController.deleteStatus(data)
|
||||
debug.debug("return ok")
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
|
@ -65,7 +65,7 @@ def _updateStatusUser(**kwargs):
|
|||
data = request.get_json()
|
||||
username = data['username']
|
||||
status = data['status']
|
||||
retVal = userController.updateStatusOfUser(username, status).toJSON()
|
||||
retVal = mainController.updateStatusOfUser(username, status).toJSON()
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -81,7 +81,7 @@ def _updateVoting(**kwargs):
|
|||
data = request.get_json()
|
||||
username = data['username']
|
||||
voting = data['voting']
|
||||
retVal = userController.updateVotingOfUser(username, voting).toJSON()
|
||||
retVal = mainController.updateVotingOfUser(username, voting).toJSON()
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -94,7 +94,7 @@ def _updateWorkgroups(**kwargs):
|
|||
debug.info("/um/updateWorkgroups")
|
||||
try:
|
||||
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))
|
||||
return jsonify(retVal), 200
|
||||
except Exception as err:
|
||||
|
@ -112,9 +112,12 @@ def _addUser(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
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))
|
||||
userl = userController.getUser(user['username'])
|
||||
userl = mainController.getUser(user['username'])
|
||||
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
|
||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
|
||||
return jsonify(retVal)
|
||||
|
@ -123,41 +126,6 @@ def _addUser(**kwargs):
|
|||
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'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
def _getUser(**kwargs):
|
||||
|
@ -168,7 +136,7 @@ def _getUser(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
lockedDay = userController.getLockedDay(date)
|
||||
lockedDay = mainController.getLockedDay(date)
|
||||
lockedDay = {
|
||||
'date': {
|
||||
'year': year,
|
||||
|
@ -178,7 +146,7 @@ def _getUser(**kwargs):
|
|||
'locked': lockedDay['locked']
|
||||
}
|
||||
retVal = {
|
||||
'worker': userController.getWorker(date),
|
||||
'worker': mainController.getWorker(date),
|
||||
'day': lockedDay
|
||||
}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
|
@ -199,9 +167,9 @@ def _deletUser(**kwargs):
|
|||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
userController.deleteWorker(user['username'], date)
|
||||
mainController.deleteWorker(user['username'], date)
|
||||
debug.debug("return ok")
|
||||
user = userController.getUser(user['username'])
|
||||
user = mainController.getUser(user['username'])
|
||||
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
|
||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
|
||||
return jsonify({"ok": "ok"})
|
||||
|
@ -214,7 +182,7 @@ def _deletUser(**kwargs):
|
|||
def _getAllWorkgroups(**kwargs):
|
||||
try:
|
||||
debug.info("get all workgroups")
|
||||
retVal = userController.getAllWorkgroups()
|
||||
retVal = mainController.getAllWorkgroups()
|
||||
debug.info("return all workgroups {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -229,7 +197,7 @@ def _getWorkgroup(**kwargs):
|
|||
data = request.get_json()
|
||||
name = data['name']
|
||||
debug.info("get workgroup {{ {} }}".format(name))
|
||||
retVal = userController.getWorkgroups(name)
|
||||
retVal = mainController.getWorkgroups(name)
|
||||
debug.info(
|
||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||
return jsonify(retVal)
|
||||
|
@ -248,10 +216,10 @@ def _workgroup(**kwargs):
|
|||
boss = None
|
||||
if 'boss' in data:
|
||||
boss = data['boss']
|
||||
retVal = userController.setWorkgroup(name, boss)
|
||||
retVal = mainController.setWorkgroup(name, boss)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = userController.updateWorkgroup(data)
|
||||
retVal = mainController.updateWorkgroup(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
|
@ -264,7 +232,7 @@ def _deleteWorkgroup(**kwargs):
|
|||
try:
|
||||
data = request.get_json()
|
||||
debug.info("/wgm/deleteWorkgroup")
|
||||
userController.deleteWorkgroup(data)
|
||||
mainController.deleteWorkgroup(data)
|
||||
retVal = {"ok": "ok"}
|
||||
debug.debug("return ok")
|
||||
return jsonify(retVal)
|
||||
|
@ -272,6 +240,95 @@ def _deleteWorkgroup(**kwargs):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/getAllJobKinds", methods=['GET'])
|
||||
@login_required(bar=True)
|
||||
def _getAllJobKinds(**kwargs):
|
||||
try:
|
||||
debug.info("get all jobkinds")
|
||||
retVal = mainController.getAllJobKinds()
|
||||
debug.info("return all jobkinds {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get all workgroups.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/getJobKind", methods=['POST'])
|
||||
@login_required(bar=True)
|
||||
def _getJobKinds(**kwargs):
|
||||
try:
|
||||
debug.info("get jobkind")
|
||||
data = request.get_json()
|
||||
name = data['name']
|
||||
debug.info("get jobkind {{ {} }}".format(name))
|
||||
retVal = mainController.getJobKind(name)
|
||||
debug.info(
|
||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get workgroup.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/JobKind", methods=['POST', 'PUT', 'DELETE'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
def _JobKinds(**kwargs):
|
||||
debug.info("/sm/JobKind")
|
||||
try:
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
name = data['name']
|
||||
workgroup = None
|
||||
if 'workgroup' in data:
|
||||
workgroup = data['workgroup']
|
||||
retVal = mainController.setJobKind(name, workgroup)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = mainController.updateJobKind(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/deleteJobKind", methods=['POST'])
|
||||
@login_required(groups=[VORSTAND])
|
||||
def _deleteJobKind(**kwargs):
|
||||
try:
|
||||
data = request.get_json()
|
||||
debug.info("/sm/deleteJobKind")
|
||||
mainController.deleteJobKind(data)
|
||||
retVal = {"ok": "ok"}
|
||||
debug.debug("return ok")
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
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'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
|
@ -284,7 +341,7 @@ def _lockDay(**kwargs):
|
|||
day = data['day']
|
||||
locked = data['locked']
|
||||
date = datetime(year, month, day, 12)
|
||||
lockedDay = userController.setLockedDay(date, locked, True)
|
||||
lockedDay = mainController.setLockedDay(date, locked, True)
|
||||
if not lockedDay:
|
||||
retVal = {
|
||||
'date': {
|
||||
|
|
Loading…
Reference in New Issue