120 lines
3.5 KiB
Python
120 lines
3.5 KiB
Python
|
# coding: utf-8
|
||
|
|
||
|
import json
|
||
|
|
||
|
import cherrypy
|
||
|
|
||
|
from app import database
|
||
|
|
||
|
# Method-Dispatching!
|
||
|
|
||
|
# Übersicht Anforderungen / Methoden
|
||
|
# (beachte: / relativ zu /discussion, siehe Konfiguration Server!)
|
||
|
|
||
|
"""
|
||
|
|
||
|
Anforderung GET PUT POST DELETE
|
||
|
-----------------------------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
/diskussion/{thema-id} alle disk. neue Diskussion - -
|
||
|
zum Thema zum Thema speichern
|
||
|
ausgeben diskussion-id zurück
|
||
|
|
||
|
/diskussion/{diskussion-id} eine - Diskussion mit ID Diskussion mit ID
|
||
|
Diskussion ändern löschen
|
||
|
anfordern
|
||
|
|
||
|
|
||
|
|
||
|
"""
|
||
|
|
||
|
#----------------------------------------------------------
|
||
|
class Discussion_cl(object):
|
||
|
#----------------------------------------------------------
|
||
|
|
||
|
exposed = True # gilt für alle Methoden
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def __init__(self):
|
||
|
#-------------------------------------------------------
|
||
|
# spezielle Initialisierung können hier eingetragen werden
|
||
|
self.db_o = database.db_o
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def GET(self, tId, dId = None):
|
||
|
#-------------------------------------------------------
|
||
|
retVal_o = {'data': None, 'id': None, 'tId': tId}
|
||
|
|
||
|
if dId == None:
|
||
|
# Anforderung der Liste
|
||
|
retVal_o['data'] = self.getList_p(tId)
|
||
|
else:
|
||
|
# Anforderung eines Dokuments
|
||
|
retVal_o['data'] = self.getDiscussion(tId, dId)
|
||
|
retVal_o['id'] = dId
|
||
|
|
||
|
if retVal_o['data'] == None:
|
||
|
cherrypy.response.status = 404
|
||
|
|
||
|
return json.dumps(retVal_o)
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def POST(self, tId, id_, **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_ = str(id_)
|
||
|
data_o = self.db_o.data_o['discussions'][id_]
|
||
|
data_o['name'] = data_opl['name']
|
||
|
|
||
|
# Update-Operation
|
||
|
retVal_o['id'] = id_
|
||
|
if self.db_o.updateDiscussion_px(id_, data_o):
|
||
|
pass
|
||
|
else:
|
||
|
cherrypy.response.status = 404
|
||
|
|
||
|
return json.dumps(retVal_o)
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def DELETE(self, id_):
|
||
|
#-------------------------------------------------------
|
||
|
# Eintrag löschen, nur noch Rückmeldung liefern
|
||
|
retVal_o = {
|
||
|
'id': id_
|
||
|
}
|
||
|
|
||
|
if self.db_o.deleteDiscussion_px(id_):
|
||
|
pass
|
||
|
else:
|
||
|
cherrypy.response.status = 404
|
||
|
|
||
|
return json.dumps(retVal_o)
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def getList_p(self, tId):
|
||
|
#-------------------------------------------------------
|
||
|
data_o = self.db_o.readDiscussion_px(tId)
|
||
|
|
||
|
return data_o
|
||
|
getList_p.exposed = False;
|
||
|
|
||
|
#-------------------------------------------------------
|
||
|
def getDiscussion(self, tId, dId):
|
||
|
#-------------------------------------------------------
|
||
|
data_o = self.db_o.readDiscussion_px(tId, dId)
|
||
|
|
||
|
return data_o
|
||
|
getDiscussion.exposed = False;
|
||
|
|
||
|
# EOF
|