375 lines
12 KiB
Python
375 lines
12 KiB
Python
# coding: utf-8
|
|
|
|
import json
|
|
|
|
import cherrypy
|
|
|
|
import time
|
|
from datetime import datetime
|
|
from .database import KatfehlerDatabase_cl, KatursacheDatabase_cl, FehlerDatabase_cl, KomponenteDatabase_cl, QsMitarbeiterDatabase_cl, SwEntwicklerDatabase_cl
|
|
# Method-Dispatching!
|
|
|
|
# Übersicht Anforderungen / Methoden
|
|
# (beachte: / relativ zu /navigation, siehe Konfiguration Server!)
|
|
|
|
#-------------------------------------------------------
|
|
def adjustId_p(id_spl, data_opl):
|
|
#-------------------------------------------------------
|
|
|
|
if id_spl == None:
|
|
data_opl['id'] = ''
|
|
elif id_spl == '':
|
|
data_opl['id'] = ''
|
|
elif id_spl == '0':
|
|
data_opl['id'] = ''
|
|
else:
|
|
data_opl['id'] = id_spl
|
|
return data_opl
|
|
|
|
"""
|
|
Anforderung GET PUT POST DELETE
|
|
-----------------------------------------------------------------------------------------
|
|
/katfehler/ alle Fehlerkategorien
|
|
/katfehler/:katfehlerid
|
|
einzelne Fehlerkategorien Fehler löschen
|
|
/katfehler/+Daten neue FK speichern
|
|
/katfehler/:katfehlerid+Daten Fehler ändern
|
|
"""
|
|
|
|
#----------------------------------------------------------
|
|
class KatFehler_cl(object):
|
|
#----------------------------------------------------------
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
#-------------------------------------------------------
|
|
def __init__(self, database_o):
|
|
#-------------------------------------------------------
|
|
self.db_o = database_o
|
|
|
|
#-------------------------------------------------------
|
|
def GET(self, id=None):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'data': None
|
|
}
|
|
if id == None:
|
|
# Anforderung der Liste
|
|
retVal_o['data'] = self.db_o['katfehler'].read_px()
|
|
else:
|
|
# Anforderung eines Dokuments
|
|
data_o = self.db_o['katfehler'].read_px(id)
|
|
if data_o != None:
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def PUT(self, id=None):
|
|
#-------------------------------------------------------
|
|
# Sichern der Daten: jetzt wird keine vollständige Seite
|
|
# zurückgeliefert, sondern nur noch die Information, ob das
|
|
# Speichern erfolgreich war
|
|
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
id_s = data_opl["id_s"]
|
|
data_o = {
|
|
'name': data_opl["name_s"],
|
|
'id': data_opl["id_s"]
|
|
}
|
|
# Update-Operation
|
|
retVal_o['id'] = id_s
|
|
if self.db_o['katfehler'].update_px(id_s, data_o):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def POST(self, data_opl):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
data_o = {
|
|
'name': data_opl["name_s"]
|
|
}
|
|
# Create-Operation
|
|
id_s = self.db_o['katfehler'].create_px(data_o)
|
|
retVal_o['id'] = id_s
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def DELETE(self, id):
|
|
#-------------------------------------------------------
|
|
# Eintrag löschen, nur noch Rückmeldung liefern
|
|
retVal_o = {
|
|
'id': id
|
|
}
|
|
|
|
if self.db_o['katfehler'].delete_px(id):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
|
|
|
|
"""
|
|
Anforderung GET PUT POST DELETE
|
|
-----------------------------------------------------------------------------------------
|
|
/katursache/ alle Fehlerkategorien
|
|
/katursache/:katursacheid
|
|
einzelne Fehlerkategorien Fehler löschen
|
|
/katursache/+Daten neue FK speichern
|
|
/katursache/:katursacheid+Daten Fehler ändern
|
|
"""
|
|
|
|
#----------------------------------------------------------
|
|
class KatUrsache_cl(object):
|
|
#----------------------------------------------------------
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
#-------------------------------------------------------
|
|
def __init__(self, database_o):
|
|
#-------------------------------------------------------
|
|
self.db_o = database_o
|
|
|
|
#-------------------------------------------------------
|
|
def GET(self, id = None):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'data': None
|
|
}
|
|
if id == None:
|
|
# Anforderung der Liste
|
|
retVal_o['data'] = self.db_o['katursache'].read_px()
|
|
else:
|
|
# Anforderung eines Dokuments
|
|
data_o = self.db_o['katursache'].read_px(id)
|
|
if data_o != None:
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def PUT(self, data_opl):
|
|
#-------------------------------------------------------
|
|
# Sichern der Daten: jetzt wird keine vollständige Seite
|
|
# zurückgeliefert, sondern nur noch die Information, ob das
|
|
# Speichern erfolgreich war
|
|
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
id_s = data_opl["id_s"]
|
|
data_o = {
|
|
'name': data_opl["name_s"],
|
|
'id': data_opl["id_s"]
|
|
}
|
|
# Update-Operation
|
|
retVal_o['id'] = id_s
|
|
if self.db_o['katursache'].update_px(id_s, data_o):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def POST(self, data_opl):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
data_o = {
|
|
'name': data_opl["name_s"]
|
|
}
|
|
# Create-Operation
|
|
id_s = self.db_o['katursache'].create_px(data_o)
|
|
retVal_o['id'] = id_s
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def DELETE(self, id):
|
|
#-------------------------------------------------------
|
|
# Eintrag löschen, nur noch Rückmeldung liefern
|
|
retVal_o = {
|
|
'id': id
|
|
}
|
|
|
|
if self.db_o['katursache'].delete_px(id):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
|
|
|
|
"""
|
|
Anforderung GET PUT POST DELETE
|
|
-----------------------------------------------------------------------------------------
|
|
/fehler/ alle Fehler
|
|
/fehler/?type=erkannt alle erkannten Fehler
|
|
/fehler/?type=behoben alle behobenen Fehler
|
|
/fehler/:fehlerid einzelner Fehler
|
|
/fehler/+Daten Fehler speichern
|
|
Rückgabe Id
|
|
/fehler/:fehlerid+Daten Fehler ändern
|
|
|
|
"""
|
|
|
|
#----------------------------------------------------------
|
|
class Fehler_cl(object):
|
|
#----------------------------------------------------------
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
#-------------------------------------------------------
|
|
def __init__(self, database_o):
|
|
#-------------------------------------------------------
|
|
self.db_o = database_o
|
|
|
|
#-------------------------------------------------------
|
|
def GET(self, id=None, type=None):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'data': None
|
|
}
|
|
if id == None:
|
|
# Anforderung der Liste
|
|
print('true')
|
|
if type == 'erkannt':
|
|
retVal_o['data'] = self.db_o['fehler'].readErkannt_px()
|
|
elif type == 'behoben':
|
|
retVal_o['data'] = self.db_o['fehler'].readBehoben_px()
|
|
else:
|
|
retVal_o['data'] = self.db_o['fehler'].read_px()
|
|
else:
|
|
# Anforderung eines Dokuments
|
|
data_o = self.db_o['fehler'].read_px(id)
|
|
if data_o != None:
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
retVal_o['komponente'] = self.db_o['komponente'].read_px()
|
|
retVal_o['qsmitarbeiter'] = self.db_o['qsmitarbeiter'].read_px()
|
|
retVal_o['swentwickler'] = self.db_o['swentwickler'].read_px()
|
|
retVal_o['katfehler'] = self.db_o['katfehler'].read_px()
|
|
retVal_o['katursache'] = self.db_o['katursache'].read_px()
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def PUT(self, data_opl):
|
|
#-------------------------------------------------------
|
|
# Sichern der Daten: jetzt wird keine vollständige Seite
|
|
# zurückgeliefert, sondern nur noch die Information, ob das
|
|
# Speichern erfolgreich war
|
|
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
id_s = data_opl["id_s"]
|
|
data_o = {
|
|
'name': data_opl["name_s"],
|
|
'id': data_opl["id_s"],
|
|
'komponenteid': data_opl["komponenteid_s"],
|
|
'katfehlerid': data_opl["katfehlerid_s"],
|
|
'katursacheid': data_opl["katursacheid_s"],
|
|
'qsmitarbeiterid': data_opl["qsmitarbeiterid_s"],
|
|
'swentwicklerid': data_opl["swentwicklerid_s"],
|
|
'status': data_opl["status_s"],
|
|
'beschreibung': data_opl["beschreibung_s"],
|
|
'beschreibungursache': data_opl["beschreibungursache_s"],
|
|
'zeiterfasst': data_opl["zeiterfasst_s"],
|
|
'zeitbehoben': data_opl["zeitbehoben_s"]
|
|
}
|
|
if data_o['status'] == 'behoben' and data_o['zeitbehoben'] == "":
|
|
data_o['zeitbehoben'] = datetime.now().strftime("%d.%m.%Y-%H:%M")
|
|
# Update-Operation
|
|
retVal_o['id'] = id_s
|
|
if self.db_o['fehler'].update_px(id_s, data_o):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def POST(self, data_opl):
|
|
#-------------------------------------------------------
|
|
retVal_o = {
|
|
'id': None
|
|
}
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
data_o = {
|
|
'name': data_opl["name_s"],
|
|
'id': data_opl["id_s"],
|
|
'komponenteid': data_opl["komponenteid_s"],
|
|
'katfehlerid': data_opl["katfehlerid_s"],
|
|
'katursacheid': data_opl["katursacheid_s"],
|
|
'qsmitarbeiterid': data_opl["qsmitarbeiterid_s"],
|
|
'swentwicklerid': data_opl["swentwicklerid_s"],
|
|
'status': data_opl["status_s"],
|
|
'beschreibung': data_opl["beschreibung_s"],
|
|
'beschreibungursache': data_opl["beschreibungursache_s"],
|
|
'zeitbehoben': '',
|
|
'zeiterfasst': datetime.now().strftime("%d.%m.%Y-%H:%M")
|
|
}
|
|
|
|
# Create-Operation
|
|
id_s = self.db_o['fehler'].create_px(data_o)
|
|
retVal_o['id'] = id_s
|
|
|
|
return retVal_o
|
|
|
|
#-------------------------------------------------------
|
|
def DELETE(self, id):
|
|
#-------------------------------------------------------
|
|
# Eintrag löschen, nur noch Rückmeldung liefern
|
|
retVal_o = {
|
|
'id': id
|
|
}
|
|
|
|
if self.db_o['fehler'].delete_px(id):
|
|
pass
|
|
else:
|
|
retVal_o['id'] = None
|
|
|
|
return retVal_o
|
|
|
|
|
|
# EOF |