WEB/Praktikum2/ppm2/app/choice.py
2016-12-14 22:32:35 +01:00

49 lines
1.7 KiB
Python

# coding: utf-8
import json
import cherrypy
from app import database
#-------------------------------------------------------
class Choice(object):
#-------------------------------------------------------
exposed = True # gilt für alle Methoden
#-------------------------------------------------------
def __init__(self):
#-------------------------------------------------------
self.db = database.Database()
#-------------------------------------------------------
def GET(self, view, id=None):
#-------------------------------------------------------
self.db.ReadAll()
data = {}
if(view == "List"):
data['content'] = {}
offerings = self.db.data['Angebote']
for key, value in offerings.items():
for key2, value2 in value.items():
if(key2 == 'Status'):
if(value2 == 'Angebot'):
data['content'][key] = value
elif(view == "Detail"):
data['id'] = id
data = self.db.data['Angebote'][id]
data['Studenten'] = self.db.data['Studenten']
data['Lehrender'] = self.db.data['Lehrender']
print(data)
return json.dumps(data)
#-------------------------------------------------------
def POST(self, **data):
#-------------------------------------------------------
if(data['Student'] != ''):
angebote = self.db.CheckOfferings(data['Student'])
print(angebote)
if(angebote == 0):
print("Save")
self.db.Save(data, 'Angebote')
print(data)
return self.GET("List")