# coding: utf-8 import json import cherrypy from .database import ProjektDatabase_cl, KomponenteDatabase_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 ----------------------------------------------------------------------------------------- /projekt/ alle Projekte (Liste) anfordern /projekt/:projekt-id einzelnes Projekt Projekt löschen anfordern /projekt/+Daten neues speichern Projekt-Id Rückgabe /projekt/:projekt-id+Daten Projekt ändern """ #---------------------------------------------------------- class Projekt_cl(object): #---------------------------------------------------------- exposed = True # gilt für alle Methoden #------------------------------------------------------- def __init__(self): #------------------------------------------------------- self.db_o = ProjektDatabase_cl() #------------------------------------------------------- def GET(self, id = None): #------------------------------------------------------- retVal_o = { 'data': None } if id == None: # Anforderung der Liste retVal_o['data'] = self.db_o.read_px() else: # Anforderung eines Dokuments data_o = self.db_o.read_px(id) if data_o != None: retVal_o['data'] = adjustId_p(id, data_o) return retVal_o #return json.dumps(retVal_o) #------------------------------------------------------- def PUT(self): #------------------------------------------------------- return json.dumps(retVal_o) #------------------------------------------------------- def POST(self): #------------------------------------------------------- return json.dumps(retVal_o) #------------------------------------------------------- def DELETE(self): #------------------------------------------------------- return json.dumps(retVal_o) """ Anforderung GET PUT POST DELETE ----------------------------------------------------------------------------------------- /projektkomponenten/:projekt-id Komponenten liefern """ #---------------------------------------------------------- class ProjektKomponenten_cl(object): #---------------------------------------------------------- exposed = True # gilt für alle Methoden #------------------------------------------------------- def __init__(self): #------------------------------------------------------- self.db_o = KomponenteDatabase_cl() #------------------------------------------------------- def GET(self): #------------------------------------------------------- retVal_o = { 'data': None } if id == None: # Anforderung der Liste retVal_o['data'] = self.db_o.read_px() else: # Anforderung eines Dokuments data_o = self.db_o.read_px(id) if data_o != None: retVal_o['data'] = adjustId_p(id, data_o) return retVal_o #return json.dumps(retVal_o) """ Anforderung GET PUT POST DELETE ----------------------------------------------------------------------------------------- /komponente/ alle Komponenten /komponente/:komponente-id einzelne Komponente Komponente löschen /komponente/:projekt-id+Daten neue Komponente speichern Id Rückgabe /komponente/:komponente-id+Daten Komponente ändern """ #---------------------------------------------------------- class Komponente_cl(object): #---------------------------------------------------------- exposed = True # gilt für alle Methoden #------------------------------------------------------- def __init__(self): #------------------------------------------------------- self.db_o = KomponenteDatabase_cl() #------------------------------------------------------- def GET(self): #------------------------------------------------------- retVal_o = { 'data': None } if id == None: # Anforderung der Liste retVal_o['data'] = self.db_o.read_px() else: # Anforderung eines Dokuments data_o = self.db_o.read_px(id) if data_o != None: retVal_o['data'] = adjustId_p(id, data_o) return retVal_o #return json.dumps(retVal_o) #------------------------------------------------------- def PUT(self): #------------------------------------------------------- return json.dumps(retVal_o) #------------------------------------------------------- def POST(self): #------------------------------------------------------- return json.dumps(retVal_o) #------------------------------------------------------- def DELETE(self): #------------------------------------------------------- return json.dumps(retVal_o) # EOF