import cherrypy from .database import Database_cl from .view import View_cl #---------------------------------------------------------- class Application_cl(object): #---------------------------------------------------------- #------------------------------------------------------- # Request Processing #------------------------------------------------------- #------------------------------------------------------- def __init__(self): #------------------------------------------------------- # spezielle Initialisierung können hier eingetragen werden self.db = Database_cl() self.view = View_cl() @cherrypy.expose #------------------------------------------------------- def index(self): #------------------------------------------------------- print("Index\n") return self.GenerateIndex() @cherrypy.expose #------------------------------------------------------- def category(self, cat=None): #------------------------------------------------------- print("Category: ", cat, "\n") if(cat==None): return self.GenerateIndex() else: return self.GenerateList(cat) @cherrypy.expose #------------------------------------------------------- def detail(self, cat=None, id=None): #------------------------------------------------------- print("Add: ", cat) if(cat!=None): return self.GenerateDetail(cat) else: return self.GenerateIndex() @cherrypy.expose #------------------------------------------------------- def save(self, cat=None, **data): #------------------------------------------------------- print("Save: ", cat) dataTmp = data return self.GenerateSave(dataTmp, cat) @cherrypy.expose #------------------------------------------------------- def delete(self, id, form=None): #------------------------------------------------------- # Eintrag löschen, dann Liste neu anzeigen self.db_o.delete_px(id) print("Delete",form) return self.createList_p(form) @cherrypy.expose #------------------------------------------------------- def default(self, *arguments, **kwargs): #------------------------------------------------------- msg_s = "unbekannte Anforderung: " + \ str(arguments) + \ ''+ \ str(kwargs) raise cherrypy.HTTPError(404, msg_s) default.exposed= True #------------------------------------------------------- # Functions #------------------------------------------------------- #------------------------------------------------------- def GenerateIndex(self): #------------------------------------------------------- return self.view.CreateIndex() #------------------------------------------------------- def GenerateList(self, category): #------------------------------------------------------- data = {} data['content'] = {} data['headings'] = {} data['category'] = category data['content'] = self.db.data[category] print(data, "\n") if(len(data['content']) != 0): print(len(data['content'])) contentFirst = list(data['content'].keys())[0] data['headings'] = list(data['content'][contentFirst].keys()) print(data, "\n") return self.view.CreateList(data) #------------------------------------------------------- def GenerateDetail(self, category, id=None): #------------------------------------------------------- data = {} if(id != None): data['content'] = self.db.ReadEntry(category, id) else: data['id'] = None data['category'] = category data['content'] = self.db.GetDefault(category) print(data, "\n") return self.view.CreateDetail(data) #------------------------------------------------------- def GenerateSave(self, dataTmp, category): #------------------------------------------------------- if(category == None): return self.view.CreateIndex() else: self.db.Save(dataTmp, category) return self.GenerateList(category) #EOF