Praktikum 2 Progress

This commit is contained in:
darthsandmann 2016-11-06 23:38:59 +01:00
parent 1e6d80235e
commit 948f0658da
23 changed files with 498 additions and 91 deletions

Binary file not shown.

View File

@ -6,13 +6,51 @@ from .view import View_cl
class Application_cl(object):
#----------------------------------------------------------
#-------------------------------------------------------
# Request Processing
#-------------------------------------------------------
#-------------------------------------------------------
def __init__(self):
#-------------------------------------------------------
# spezielle Initialisierung können hier eingetragen werden
self.db_o = Database_cl()
self.view_o = View_cl()
self.liste = 0
self.db = Database_cl()
self.view = View_cl()
@cherrypy.expose
#-------------------------------------------------------
def index(self):
#-------------------------------------------------------
print("Index\n")
return self.GenerateIndex()
@cherrypy.expose
#-------------------------------------------------------
def category(self, cat=None):
#-------------------------------------------------------
print("Category: ", cat, "\n")
if(cat==None):
return self.GenerateIndex()
else:
return self.GenerateList(cat)
@cherrypy.expose
#-------------------------------------------------------
def detail(self, cat=None, id=None):
#-------------------------------------------------------
print("Add: ", cat)
if(cat!=None):
return self.GenerateDetail(cat)
else:
return self.GenerateIndex()
@cherrypy.expose
#-------------------------------------------------------
def save(self, cat=None, **data):
#-------------------------------------------------------
print("Save: ", cat)
dataTmp = data
return self.GenerateSave(dataTmp, cat)
@cherrypy.expose
#-------------------------------------------------------
@ -24,7 +62,6 @@ class Application_cl(object):
return self.createList_p(form)
@cherrypy.expose
#-------------------------------------------------------
def default(self, *arguments, **kwargs):
#-------------------------------------------------------
@ -34,3 +71,53 @@ class Application_cl(object):
str(kwargs)
raise cherrypy.HTTPError(404, msg_s)
default.exposed= True
#-------------------------------------------------------
# Functions
#-------------------------------------------------------
#-------------------------------------------------------
def GenerateIndex(self):
#-------------------------------------------------------
return self.view.CreateIndex()
#-------------------------------------------------------
def GenerateList(self, category):
#-------------------------------------------------------
data = {}
data['content'] = {}
data['headings'] = {}
data['category'] = category
data['content'] = self.db.data[category]
print(data, "\n")
if(len(data['content']) != 0):
print(len(data['content']))
contentFirst = list(data['content'].keys())[0]
data['headings'] = list(data['content'][contentFirst].keys())
print(data, "\n")
return self.view.CreateList(data)
#-------------------------------------------------------
def GenerateDetail(self, category, id=None):
#-------------------------------------------------------
data = {}
if(id != None):
data['content'] = self.db.ReadEntry(category, id)
else:
data['id'] = None
data['category'] = category
data['content'] = self.db.GetDefault(category)
print(data, "\n")
return self.view.CreateDetail(data)
#-------------------------------------------------------
def GenerateSave(self, dataTmp, category):
#-------------------------------------------------------
if(category == None):
return self.view.CreateIndex()
else:
self.db.Save(dataTmp, category)
return self.GenerateList(category)
#EOF

View File

@ -19,104 +19,103 @@ class Database_cl(object):
#-------------------------------------------------------
def __init__(self):
#-------------------------------------------------------
self.data_o = None
self.readData_p()
self.data = {}
self.data['students'] = {}
self.data['teachers'] = {}
self.data['companies'] = {}
self.data['offerings'] = {}
self.Read('students')
self.Read('teachers')
self.Read('companies')
self.Read('offerings')
#-------------------------------------------------------
def create_px(self, data_opl):
def Read(self, category):
#-------------------------------------------------------
# Ü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
path = 'data/' + category
if not(os.path.exists(path)):
os.makedirs(path)
categoryDir = os.listdir(path)
for fileName in categoryDir:
if fileName.endswith('.json') and fileName != 'last.json':
file = codecs.open(os.path.join('data', category, fileName), 'rU', 'utf-8')
fileContent = file.read()
id = fileName[:-5]
self.data[category][id] = json.loads(fileContent)
#-------------------------------------------------------
def read_px(self, id_spl = None):
def ReadEntry(self, category = None, id = None):
#-------------------------------------------------------
# hier zur Vereinfachung:
# Aufruf ohne id: alle Einträge liefern
data_o = None
if id_spl == None:
data_o = self.data_o
data = None
if id == None:
data = self.data
else:
if id_spl in self.data_o:
data_o = self.data_o[id_spl]
return data_o
if id in self.data[category]:
data = self.data[category][id]
return data
#-------------------------------------------------------
def update_px(self, id_spl, data_opl):
def Save(self, data, category):
#-------------------------------------------------------
# Ü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()
id = data['id']
print("ID: ", id, "\n")
if(id != "None"):
if id in self.data[category]:
file = codecs.open(os.path.join('data', category, id+'.json'), 'w', 'utf-8')
file.write(json.dumps(data, indent=3, ensure_ascii=True))
file.close()
self.data[category][id] = data
status_b = True
else:
data['id'] = self.IdNext(category)
file = codecs.open(os.path.join('data', category, data['id']+'.json'), 'w', 'utf-8')
file.write(json.dumps(data, indent=3, ensure_ascii=True))
file.close()
self.data[category][id] = data
status_b = True
return status_b
#-------------------------------------------------------
def delete_px(self, id_spl):
def Delete(self, category, id):
#-------------------------------------------------------
#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()
if id in self.data[category]:
os.remove(os.path.join('data', category, id+'json'))
del self.data[category][id]
return status_b
#-------------------------------------------------------
def GetDefault(self, category):
#-------------------------------------------------------
if(category == 'students'):
return {'name':'name', 'vorname':'vorname', 'matrikelnummer':'matrikelnummer'}
elif(category == 'teachers'):
return {'titel':'titel', 'name':'name', 'vorname':'vorname', 'lehrgebiet':'lehrgebiet'}
elif(category == 'companies'):
return {'name':'name', 'branche':'branche', 'schwerpunkt':'schwerpunkt', 'sitz':'sitz', 'anzahlMitarbeiter':'anzahlMitarbeiter'}
elif(category == 'offerings'):
return {'name':'name', 'company':'company', 'beschreibung':'beschreibung', 'voraussetzungen':'voraussetzungen', 'firmenbetreuer':'firmenbetreuer'}
#-------------------------------------------------------
def getDefault_px(self):
def IdNext(self, category):
#-------------------------------------------------------
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()
path = 'data/' + category + '/last.json'
if(os.path.isfile(path)):
file = open(os.path.join('data', category, 'last.json'), 'r+')
last = file.read()
last = str(int(last)+1)
file.seek(0)
file.write(last)
file.close()
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)
file = open(os.path.join('data', category, 'last.json'), 'w+')
last = str(int(0))
file.write(last)
file.close()
return last
# EOF

View File

@ -7,21 +7,31 @@ class View_cl(object):
#----------------------------------------------------------
#-------------------------------------------------------
def __init__(self, path_spl):
def __init__(self):
#-------------------------------------------------------
# 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
self.path = 'templates'
self.lookup = TemplateLookup(directories=['/'])
#-------------------------------------------------------
def create_p(self, template_spl, data_opl):
def Create(self, template, data):
#-------------------------------------------------------
# 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
print("CreateView\n")
template = Template(filename=os.path.join(self.path, template), output_encoding='utf-8', lookup=self.lookup)
return template.render(data = data)
#-------------------------------------------------------
def createList_px(self, data_opl):
def CreateIndex(self):
#-------------------------------------------------------
return self.create_p('liste.tpl', data_opl)
print("CreateIndex\n")
data = None
return self.Create('index.tpl', data)
#-------------------------------------------------------
def CreateList(self, data):
#-------------------------------------------------------
return self.Create('list.tpl', data)
#-------------------------------------------------------
def CreateDetail(self, data):
#-------------------------------------------------------
return self.Create('detail.tpl', data)

View File

@ -0,0 +1,8 @@
{
"anzahlMitarbeiter": "anzahlMitarbeiter",
"schwerpunkt": "schwerpunkt",
"id": "0",
"sitz": "sitz",
"branche": "branche",
"name": "name"
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,8 @@
{
"voraussetzungen": "voraussetzungen",
"beschreibung": "beschreibung",
"firmenbetreuer": "firmenbetreuer",
"company": "company",
"id": "0",
"name": "name"
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,6 @@
{
"matrikelnummer": "matrikelnummer",
"vorname": "vorname",
"id": "33",
"name": "name"
}

View File

@ -0,0 +1,6 @@
{
"matrikelnummer": "test",
"name": "test",
"vorname": "test",
"id": "34"
}

View File

@ -0,0 +1,6 @@
{
"id": "35",
"matrikelnummer": "1234",
"vorname": "test2",
"name": "test2"
}

View File

@ -0,0 +1 @@
35

View File

@ -0,0 +1,7 @@
{
"titel": "titel",
"id": "0",
"lehrgebiet": "lehrgebiet",
"name": "name",
"vorname": "vorname"
}

View File

@ -0,0 +1 @@
0

45
Praktikum2/ppm1/server.py Normal file
View File

@ -0,0 +1,45 @@
#coding: utf-8
import os
import cherrypy
from app import application
#--------------------------------------
def main():
#--------------------------------------
# Get current directory
try:
current_dir = os.path.dirname(os.path.abspath(__file__))
except:
current_dir = os.path.dirname(os.path.abspath(sys.executable))
# disable autoreload and timeout_monitor
cherrypy.engine.autoreload.unsubscribe()
cherrypy.engine.timeout_monitor.unsubscribe()
# Static content config
static_config = {
'/': {
'tools.staticdir.root': current_dir,
'tools.staticdir.on': True,
'tools.staticdir.dir': './static'
}
}
# Mount static content handler
root_o = cherrypy.tree.mount(application.Application_cl(), '/', static_config)
# suppress traceback-info
cherrypy.config.update({'request.show_tracebacks': False})
# Start server
cherrypy.engine.start()
cherrypy.engine.block()
#--------------------------------------
if __name__ == '__main__':
#--------------------------------------
main()
# EOF

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>
Praxisphasenmanager (PPM)
</title>
<meta charset="UTF-8" />
<style type="text/css">
@import url("/template/template.css");
</style>
</head>
<body>
<h1 id="idSiteHeader" class="clSiteHeader">
${data['category']}: Ihre Daten
</h1>
<form id="idForm" class="clContent" action="/save/?cat=${data['category']}" method="POST">
<h2 id="idContentHeader" class="clContentHeader">
Das Formular ausf&uumlllen/korrigieren und auf "speichern" klicken:
</h2>
<div id="idContentArea" class="clContentArea">
<input type="hidden" value="${data['id']}" id="id" name="id" />
% for field in data['content']:
<div class="clFormRow">
<label for="${field}">${field}</label>
<input type="text" value="${field}" id="${field}" name="${field}" />
</div>
% endfor
<div id="idButtonArea" class="clButtonArea">
<a href="/index" title="Zurueck zur Startseite">Zurueck</a>
<input type="submit" value="Speichern" />
</div>
</div>
</form>
</body>
</html>

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>
Praxisphasenmanager (PPM)
</title>
<meta charset="UTF-8" />
<script type="text/javascript" src="/javascript/index.js"></script>
<style type="text/css">
@import url("/template/template.css");
</style>
</head>
<body>
<h1 id="idSiteHeader" class="clSiteHeader">
Praxisphasenmanager (PPM)
</h1>
<div id="idContent" class="clContent">
<h2 id="idContentHeader" class="clContentHeader">
Funktionen
</h2>
<div id="idButtonArea" class="clButtonArea">
<a href="/category/?cat=students" class="clButton">Datenpflege: Studenten</a>
<a href="/category/?cat=teachers" class="clButton">Datenpflege: Lehrende</a>
<a href="/category/?cat=offerings" class="clButton">Angebot Praxisphasen</a>
<a href="/category/?cat=companies" class="clButton">Firmenverzeichnis</a>
</div>
<div id="idButtonArea" class="clButtonArea">
<a href="/evaluations" class="clButton">Auswertungen</a>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<title>
Praxisphasenmanager (PPM)
</title>
<meta charset="UTF-8" />
<script type="text/javascript" src="/javascript/index.js"></script>
<style type="text/css">
@import url("/template/template.css");
</style>
</head>
<body>
<h1 id="idSiteHeader" class="clSiteHeader">
Praxisphasenmanager (PPM)
</h1>
<div id="idContent" class="clContent">
<h2 id="idContentHeader" class="clContentHeader">
&Uumlbersicht
% if data['category'] == 'students':
Studenten
% elif data['category'] == 'teachers':
Lehrende
% elif data['category'] == 'companies':
Firmen
% elif data['category'] == 'offerings':
Angebote
% endif
</h2>
<div id="idContentArea" class="clContentArea">
<table id="idList">
<tr>
% if data['content']!= None:
% for heading in data['headings']:
% if heading!='id':
<th>${heading}</th>
% endif
% endfor
% else:
<td>Bisher kein Inhalt</td>
% endif
</tr>
% if data['content']!= None:
% for entries in data['content']:
<tr>
% for entry in data['content'][entries]:
% if entry!='id':
<td>${data['content'][entries][entry]}</td>
% endif
% endfor
</tr>
% endfor
% endif
</table>
</div>
<div id="idButtonArea" class="clButtonArea">
<a href="/detail/?cat=${data['category']}" class="clButton">Neu</a>
<a href="/index" class="clButton">Startseite</a>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>
Registrierung
</title>
<meta charset="UTF-8" />
<style type="text/css">
@import url("/template/template.css");
</style>
</head>
<body>
<h1 id="idSiteHeader" class="clSiteHeader">
Ihre Daten
</h1>
<form id="idForm" class="clContent" action="/speichern_app" method="POST">
<h2 id="idContentHeader" class="clContentHeader">
Das Formular ausfüllen/korrigieren und auf "speichern" klicken:
</h2>
<div id="idContentArea" class="clContentArea">
<input type="hidden" value="${inhalt_alle['id']}" id="id_s" name="id_s" />
<div class="clFormRow">
<label for="vorname_s">Vorname</label>
<input type="text" value="${inhalt_alle['Vorname']}" id="Vorname_s" name="Vorname_s" />
</div>
</form>
</body>
</html>

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>
Praxisphasenmanager (PPM)
</title>
<meta charset="UTF-8" />
<script type="text/javascript" src="/javascript/index.js"></script>
<style type="text/css">
@import url("/template/template.css");
</style>
</head>
<body>
<h1 id="idSiteHeader" class="clSiteHeader">
SiteHeader
</h1>
<div id="idContent" class="clContent">
<h2 id="idContentHeader" class="clContentHeader">
Übersicht
</h2>
<div id="idContentArea" class="clContentArea">
<table id="idList">
<tr>
<th>th1</th>
<th>th2</th>
<th>th3</th>
<th>th4</th>
<th>th5</th>
<th>th6</th>
<!--
% for var in inhalt_alle:
<tr id=${var}>
<td>${inhalt_alle[var]['Vorname']}</td>
<td>${inhalt_alle[var]['Nachname']}</td>
<td>${inhalt_alle[var]['Gaeste']}</td>
<td>${inhalt_alle[var]['Studiengang']}</td>
<td>${inhalt_alle[var]['Betreuer']}</td>
<td>${inhalt_alle[var]['Matrikelnummer']}</td>
</tr>
% endfor-->
</table>
</div>
<div id="idButtonArea" class="clButtonArea">
<a href="/hinzufuegen_app" class="clButton">Button 1</a>
<a href="/ausschuss_app" class="clButton">Button 2</a>
<a href="./page.html" class="clButton">Button 3</a>
</div>
</div>
</body>
</html>