fixed ##279

wenn user noch nicht in der datenbank existiert, wird er hinzugefügt. wenn er noch kein gerücht besitzt, wird eins angelegt.
This commit is contained in:
Tim Gröger 2020-06-05 22:53:27 +02:00
parent a1098713ca
commit 93fcbe72ae
4 changed files with 16 additions and 11 deletions

View File

@ -210,3 +210,4 @@ def _lockbar(**kwargs):
accToken.lock_bar = data['value'] accToken.lock_bar = data['value']
debug.debug('return {{ "value": {} }}'.format(accToken.lock_bar)) debug.debug('return {{ "value": {} }}'.format(accToken.lock_bar))
return jsonify({'value': accToken.lock_bar}) return jsonify({'value': accToken.lock_bar})

View File

@ -3,6 +3,7 @@ from datetime import datetime
from geruecht.exceptions import DatabaseExecption from geruecht.exceptions import DatabaseExecption
from geruecht.model.creditList import CreditList from geruecht.model.creditList import CreditList
from geruecht.model.user import User
class Base: class Base:
@ -10,12 +11,14 @@ class Base:
try: try:
cursor = self.db.connection.cursor() cursor = self.db.connection.cursor()
if 'year' in kwargs: if 'year' in kwargs:
sql = "select * from creditList where user_id={} and year_date={}".format(user.id, kwargs['year']) sql = "select * from creditList where user_id={} and year_date={}".format(user.id if type(user) is User else user, kwargs['year'])
else: else:
sql = "select * from creditList where user_id={}".format(user.id) sql = "select * from creditList where user_id={}".format(user.id if type(user) is User else user)
cursor.execute(sql) cursor.execute(sql)
data = cursor.fetchall() data = cursor.fetchall()
if len(data) == 1: if len(data) == 0:
return self.createCreditList(user_id=user.id, year=datetime.now().year)
elif len(data) == 1:
return [CreditList(data[0])] return [CreditList(data[0])]
else: else:
return [CreditList(value) for value in data] return [CreditList(value) for value in data]
@ -30,6 +33,7 @@ class Base:
cursor = self.db.connection.cursor() cursor = self.db.connection.cursor()
cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id)) cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id))
self.db.connection.commit() self.db.connection.commit()
return self.getCreditListFromUser(user_id)
except Exception as err: except Exception as err:
traceback.print_exc() traceback.print_exc()
self.db.connection.rollback() self.db.connection.rollback()

View File

@ -4,6 +4,7 @@ from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion, PermissionDeni
import geruecht.controller.databaseController as dc import geruecht.controller.databaseController as dc
import geruecht.controller.ldapController as lc import geruecht.controller.ldapController as lc
from geruecht.logger import getDebugLogger from geruecht.logger import getDebugLogger
from geruecht.model.user import User
db = dc.DatabaseController() db = dc.DatabaseController()
ldap = lc.LDAPController() ldap = lc.LDAPController()

View File

@ -1,15 +1,14 @@
Click==7.0 click==7.1.2
Flask==1.1.1 Flask==1.1.2
Flask-Cors==3.0.8 Flask-Cors==3.0.8
Flask-LDAPConn==0.10.1 Flask-LDAPConn==0.10.1
Flask-MySQLdb==0.2.0 Flask-MySQLdb==0.2.0
itsdangerous==1.1.0 itsdangerous==1.1.0
Jinja2==2.11.0 Jinja2==2.11.2
ldap3==2.6.1 ldap3==2.7
MarkupSafe==1.1.1 MarkupSafe==1.1.1
mysqlclient==1.4.6 mysqlclient==1.4.6
pyasn1==0.4.8 pyasn1==0.4.8
PyMySQL==0.9.3 PyYAML==5.3.1
PyYAML==5.3 six==1.15.0
six==1.14.0 Werkzeug==1.0.1
Werkzeug==0.16.1