Praktikum2
This commit is contained in:
parent
f0db62320a
commit
1e6d80235e
BIN
Praktikum2/AufgabePrak2A.pdf
Normal file
BIN
Praktikum2/AufgabePrak2A.pdf
Normal file
Binary file not shown.
0
Praktikum2/ppm1/app/__init__.py
Normal file
0
Praktikum2/ppm1/app/__init__.py
Normal file
36
Praktikum2/ppm1/app/application.py
Normal file
36
Praktikum2/ppm1/app/application.py
Normal file
@ -0,0 +1,36 @@
|
||||
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()
|
||||
self.liste = 0
|
||||
@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
|
122
Praktikum2/ppm1/app/database.py
Normal file
122
Praktikum2/ppm1/app/database.py
Normal file
@ -0,0 +1,122 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import codecs
|
||||
import json
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Database_cl(object):
|
||||
#----------------------------------------------------------
|
||||
# da es hier nur darum geht, die Daten dauerhaft zu speichern,
|
||||
# wird ein sehr einfacher Ansatz verwendet:
|
||||
# - es können Daten zu genau 15 Teams gespeichert werden
|
||||
# - je Team werden 2 Teilnehmer mit Namen, Vornamen und Matrikelnummer
|
||||
# berücksichtigt
|
||||
# - die Daten werden als eine JSON-Datei abgelegt
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
self.data_o = None
|
||||
self.readData_p()
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def create_px(self, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
# 'freien' Platz suchen,
|
||||
# falls vorhanden: belegen und Nummer des Platzes als Id zurückgeben
|
||||
|
||||
id_s = None
|
||||
for loop_i in range(0,15):
|
||||
if self.data_o[str(loop_i)][0] == '':
|
||||
id_s = str(loop_i)
|
||||
self.data_o[id_s] = data_opl
|
||||
self.saveData_p()
|
||||
break
|
||||
|
||||
return id_s
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def read_px(self, id_spl = None):
|
||||
#-------------------------------------------------------
|
||||
# hier zur Vereinfachung:
|
||||
# Aufruf ohne id: alle Einträge liefern
|
||||
|
||||
data_o = None
|
||||
if id_spl == None:
|
||||
data_o = self.data_o
|
||||
else:
|
||||
if id_spl in self.data_o:
|
||||
data_o = self.data_o[id_spl]
|
||||
|
||||
return data_o
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def update_px(self, id_spl, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
status_b = False
|
||||
if id_spl in self.data_o:
|
||||
self.data_o[id_spl] = data_opl
|
||||
self.saveData_p()
|
||||
status_b = True
|
||||
|
||||
return status_b
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def delete_px(self, id_spl):
|
||||
#-------------------------------------------------------
|
||||
#print("\n---------------------- DELETE ---------------------")
|
||||
status_b = False
|
||||
if id_spl in self.data_o:
|
||||
pass
|
||||
# hier müssen Sie den Code ergänzen
|
||||
# Löschen als Zurücksetzen auf die Default-Werte implementieren
|
||||
# Ihre Ergänzung
|
||||
self.data_o[id_spl] = {}
|
||||
default_s = self.getDefault_px()
|
||||
self.data_o[id_spl] = default_s
|
||||
self.saveData_p()
|
||||
|
||||
return status_b
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getDefault_px(self):
|
||||
#-------------------------------------------------------
|
||||
return ['', '', '', '', '', '', '', ''] # HIER müssen Sie eine Ergänzung vornehmen
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def readData_p(self):
|
||||
#-------------------------------------------------------
|
||||
try:
|
||||
fp_o = codecs.open(os.path.join('data', 'webteams.json'), 'r', 'utf-8')
|
||||
except:
|
||||
# Datei neu anlegen self.data_o = {}
|
||||
self.data_o = {}
|
||||
for loop_i in range(0,15):
|
||||
self.data_o[str(loop_i)] = ['', '', '', '', '', '', '', '']
|
||||
self.saveData_p()
|
||||
else:
|
||||
with fp_o:
|
||||
self.data_o = json.load(fp_o)
|
||||
|
||||
return
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def saveData_p(self):
|
||||
#-------------------------------------------------------
|
||||
with codecs.open(os.path.join('data', 'webteams.json'), 'w', 'utf-8') as fp_o:
|
||||
json.dump(self.data_o, fp_o)
|
||||
|
||||
|
||||
# EOF
|
27
Praktikum2/ppm1/app/view.py
Normal file
27
Praktikum2/ppm1/app/view.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os.path
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
|
||||
#----------------------------------------------------------
|
||||
class View_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self, path_spl):
|
||||
#-------------------------------------------------------
|
||||
# Pfad hier zur Vereinfachung fest vorgeben
|
||||
self.path_s = os.path.join(path_spl, "template")
|
||||
self.lookup_o = TemplateLookup(directories=[self.path_s])
|
||||
# ... weitere Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def create_p(self, template_spl, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Auswertung mit templates
|
||||
template_o = self.lookup_o.get_template(template_spl)
|
||||
return template_o.render(data_o = data_opl) # hier wird da Template ausgeführt für die übergebenen Daten
|
||||
|
||||
#-------------------------------------------------------
|
||||
def createList_px(self, data_opl):
|
||||
#-------------------------------------------------------
|
||||
return self.create_p('liste.tpl', data_opl)
|
Loading…
x
Reference in New Issue
Block a user