WEB/Praktikum1_Kai/webteams/app/application.py

125 lines
3.5 KiB
Python
Raw Normal View History

2016-10-11 19:01:39 +02:00
# coding: utf-8
import cherrypy
from .database import Database_cl
from .view import View_cl
#----------------------------------------------------------
class Application_cl(object):
#----------------------------------------------------------
#-------------------------------------------------------
def __init__(self):
#-------------------------------------------------------
# spezielle Initialisierung können hier eingetragen werden
self.db_o = Database_cl()
self.view_o = View_cl()
2016-10-17 18:04:28 +02:00
self.liste = 0
2016-10-11 19:01:39 +02:00
@cherrypy.expose
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def index(self, form=None):
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
2016-10-17 18:04:28 +02:00
if(form == "0"):
2016-10-21 12:54:01 +02:00
return self.createList_p(form)
2016-10-17 18:04:28 +02:00
elif(form == "1"):
2016-10-21 12:54:01 +02:00
return self.createList_p(form)
elif(form == None):
if (self.liste == 0):
self.liste = 1;
return self.createList_p("0")
else:
return self.createList_p("1")
2016-10-11 19:01:39 +02:00
@cherrypy.expose
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def add(self, form=None):
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
return self.createForm_p(form)
2016-10-11 19:01:39 +02:00
@cherrypy.expose
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def edit(self, id, form=None):
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
return self.createForm_p(form, id)
2016-10-11 19:01:39 +02:00
@cherrypy.expose
#-------------------------------------------------------
def save(self, **data_opl):
#-------------------------------------------------------
# Sichern der Daten: aufgrund der Formularbearbeitung muss
# eine vollständige HTML-Seite zurückgeliefert werden!
# data_opl: Dictionary mit den gelieferten key-value-Paaren
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
# HIER müssen Sie die Semesterzahl(en) ergänzen
id_s = data_opl["id_s"]
data_a = [ data_opl["name1_s"]
, data_opl["vorname1_s"]
, data_opl["matrnr1_s"]
2016-10-17 18:04:28 +02:00
, data_opl["semesteranzahl1_s"]
2016-10-11 19:01:39 +02:00
, data_opl["name2_s"]
, data_opl["vorname2_s"]
, data_opl["matrnr2_s"]
2016-10-17 18:04:28 +02:00
, data_opl["semesteranzahl2_s"]
2016-10-11 19:01:39 +02:00
]
if id_s != "None":
# Update-Operation
self.db_o.update_px(id_s, data_a)
else:
# Create-Operation
id_s = self.db_o.create_px(data_a)
return self.createForm_p(id_s)
@cherrypy.expose
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def delete(self, id, form=None):
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
# Eintrag löschen, dann Liste neu anzeigen
2016-10-21 12:54:01 +02:00
self.db_o.delete_px(id)
print("Delete",form)
return self.createList_p(form)
2016-10-11 19:01:39 +02:00
@cherrypy.expose
#-------------------------------------------------------
def default(self, *arguments, **kwargs):
#-------------------------------------------------------
msg_s = "unbekannte Anforderung: " + \
str(arguments) + \
''+ \
str(kwargs)
raise cherrypy.HTTPError(404, msg_s)
default.exposed= True
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def createList_p(self, form):
2016-10-17 18:04:28 +02:00
#-------------------------------------------------------
data_o = self.db_o.read_px()
# mit diesen Daten Markup erzeugen
2016-10-21 12:54:01 +02:00
print("List: ", form)
2016-10-17 18:04:28 +02:00
2016-10-21 12:54:01 +02:00
return self.view_o.createList_px(data_o, form)
2016-10-17 18:04:28 +02:00
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
2016-10-21 12:54:01 +02:00
def createForm_p(self, form, id_spl = None):
2016-10-11 19:01:39 +02:00
#-------------------------------------------------------
if id_spl != None:
data_o = self.db_o.read_px(id_spl)
else:
data_o = self.db_o.getDefault_px()
# mit diesen Daten Markup erzeugen
2016-10-21 12:54:01 +02:00
return self.view_o.createForm_px(id_spl, data_o, form)
2016-10-11 19:01:39 +02:00
# EOF