2016-12-12 22:20:21 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
import json
|
|
|
|
import cherrypy
|
|
|
|
from app import database
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
class Category(object):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.db = database.Database()
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2016-12-14 12:45:42 +01:00
|
|
|
def GET(self, cat, view, id=None):
|
2016-12-12 22:20:21 +01:00
|
|
|
#-------------------------------------------------------
|
2016-12-15 13:52:05 +01:00
|
|
|
self.db.ReadAll()
|
2016-12-12 22:20:21 +01:00
|
|
|
data = {}
|
2016-12-14 12:45:42 +01:00
|
|
|
if(cat != "Index"):
|
|
|
|
if(view == "List"):
|
|
|
|
data['content'] = {}
|
|
|
|
data['headings'] = {}
|
|
|
|
data['category'] = cat
|
|
|
|
data['content'] = self.db.data[cat]
|
|
|
|
if(len(data['content']) != 0):
|
|
|
|
print(len(data['content']))
|
|
|
|
contentFirst = list(data['content'].keys())[0]
|
|
|
|
data['headings'] = list(data['content'][contentFirst].keys())
|
|
|
|
elif(view == "Detail"):
|
|
|
|
data['category'] = cat
|
|
|
|
if(id != None):
|
|
|
|
data['id'] = id
|
|
|
|
data['content'] = self.db.ReadEntry(cat, id)
|
|
|
|
else:
|
|
|
|
data['id'] = None
|
|
|
|
data['content'] = self.db.GetDefault(cat)
|
|
|
|
if(cat == 'Angebote'):
|
|
|
|
data['Firmen'] = self.db.data['Firmen']
|
2016-12-12 22:20:21 +01:00
|
|
|
print(data)
|
|
|
|
return json.dumps(data)
|
2016-12-14 12:45:42 +01:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def POST(self, cat, **data):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.db.Save(data, cat)
|
|
|
|
print(data)
|
|
|
|
return self.GET(cat, "List")
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def DELETE(self, cat, id):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
print("Delete",cat,id)
|
|
|
|
self.db.Delete(cat, id)
|
|
|
|
return self.GET(cat, "List")
|