diff --git a/Praktikum2/ppm1/app/__pycache__/__init__.cpython-35.pyc b/Praktikum2/ppm1/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..245d099 Binary files /dev/null and b/Praktikum2/ppm1/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Praktikum2/ppm1/app/__pycache__/application.cpython-35.pyc b/Praktikum2/ppm1/app/__pycache__/application.cpython-35.pyc new file mode 100644 index 0000000..5346384 Binary files /dev/null and b/Praktikum2/ppm1/app/__pycache__/application.cpython-35.pyc differ diff --git a/Praktikum2/ppm1/app/__pycache__/database.cpython-35.pyc b/Praktikum2/ppm1/app/__pycache__/database.cpython-35.pyc new file mode 100644 index 0000000..f6548b9 Binary files /dev/null and b/Praktikum2/ppm1/app/__pycache__/database.cpython-35.pyc differ diff --git a/Praktikum2/ppm1/app/__pycache__/view.cpython-35.pyc b/Praktikum2/ppm1/app/__pycache__/view.cpython-35.pyc new file mode 100644 index 0000000..a9040be Binary files /dev/null and b/Praktikum2/ppm1/app/__pycache__/view.cpython-35.pyc differ diff --git a/Praktikum2/ppm1/app/application.py b/Praktikum2/ppm1/app/application.py index 751ea4b..37b5d4f 100644 --- a/Praktikum2/ppm1/app/application.py +++ b/Praktikum2/ppm1/app/application.py @@ -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): #------------------------------------------------------- @@ -33,4 +70,54 @@ class Application_cl(object): ''+ \ str(kwargs) raise cherrypy.HTTPError(404, msg_s) - default.exposed= True \ No newline at end of file + 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 \ No newline at end of file diff --git a/Praktikum2/ppm1/app/database.py b/Praktikum2/ppm1/app/database.py index 67a0100..70ff0e5 100644 --- a/Praktikum2/ppm1/app/database.py +++ b/Praktikum2/ppm1/app/database.py @@ -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 Read(self, category): + #------------------------------------------------------- + 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 create_px(self, data_opl): + def ReadEntry(self, category = None, id = None): #------------------------------------------------------- - # Ü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 + data = None + if id == None: + data = self.data else: - if id_spl in self.data_o: - data_o = self.data_o[id_spl] + if id in self.data[category]: + data = self.data[category][id] - return data_o - + 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 \ No newline at end of file diff --git a/Praktikum2/ppm1/app/view.py b/Praktikum2/ppm1/app/view.py index a1d90e6..7669c48 100644 --- a/Praktikum2/ppm1/app/view.py +++ b/Praktikum2/ppm1/app/view.py @@ -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) \ No newline at end of file + 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) \ No newline at end of file diff --git a/Praktikum2/ppm1/data/companies/0.json b/Praktikum2/ppm1/data/companies/0.json new file mode 100644 index 0000000..b043baf --- /dev/null +++ b/Praktikum2/ppm1/data/companies/0.json @@ -0,0 +1,8 @@ +{ + "anzahlMitarbeiter": "anzahlMitarbeiter", + "schwerpunkt": "schwerpunkt", + "id": "0", + "sitz": "sitz", + "branche": "branche", + "name": "name" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/companies/last.json b/Praktikum2/ppm1/data/companies/last.json new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/Praktikum2/ppm1/data/companies/last.json @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Praktikum2/ppm1/data/offerings/0.json b/Praktikum2/ppm1/data/offerings/0.json new file mode 100644 index 0000000..68841ca --- /dev/null +++ b/Praktikum2/ppm1/data/offerings/0.json @@ -0,0 +1,8 @@ +{ + "voraussetzungen": "voraussetzungen", + "beschreibung": "beschreibung", + "firmenbetreuer": "firmenbetreuer", + "company": "company", + "id": "0", + "name": "name" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/offerings/last.json b/Praktikum2/ppm1/data/offerings/last.json new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/Praktikum2/ppm1/data/offerings/last.json @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Praktikum2/ppm1/data/students/33.json b/Praktikum2/ppm1/data/students/33.json new file mode 100644 index 0000000..6aa4721 --- /dev/null +++ b/Praktikum2/ppm1/data/students/33.json @@ -0,0 +1,6 @@ +{ + "matrikelnummer": "matrikelnummer", + "vorname": "vorname", + "id": "33", + "name": "name" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/students/34.json b/Praktikum2/ppm1/data/students/34.json new file mode 100644 index 0000000..292d1fb --- /dev/null +++ b/Praktikum2/ppm1/data/students/34.json @@ -0,0 +1,6 @@ +{ + "matrikelnummer": "test", + "name": "test", + "vorname": "test", + "id": "34" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/students/35.json b/Praktikum2/ppm1/data/students/35.json new file mode 100644 index 0000000..610e7df --- /dev/null +++ b/Praktikum2/ppm1/data/students/35.json @@ -0,0 +1,6 @@ +{ + "id": "35", + "matrikelnummer": "1234", + "vorname": "test2", + "name": "test2" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/students/last.json b/Praktikum2/ppm1/data/students/last.json new file mode 100644 index 0000000..597975b --- /dev/null +++ b/Praktikum2/ppm1/data/students/last.json @@ -0,0 +1 @@ +35 \ No newline at end of file diff --git a/Praktikum2/ppm1/data/teachers/0.json b/Praktikum2/ppm1/data/teachers/0.json new file mode 100644 index 0000000..8f598bd --- /dev/null +++ b/Praktikum2/ppm1/data/teachers/0.json @@ -0,0 +1,7 @@ +{ + "titel": "titel", + "id": "0", + "lehrgebiet": "lehrgebiet", + "name": "name", + "vorname": "vorname" +} \ No newline at end of file diff --git a/Praktikum2/ppm1/data/teachers/last.json b/Praktikum2/ppm1/data/teachers/last.json new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/Praktikum2/ppm1/data/teachers/last.json @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Praktikum2/ppm1/server.py b/Praktikum2/ppm1/server.py new file mode 100644 index 0000000..4e64056 --- /dev/null +++ b/Praktikum2/ppm1/server.py @@ -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 \ No newline at end of file diff --git a/Praktikum2/ppm1/templates/detail.tpl b/Praktikum2/ppm1/templates/detail.tpl new file mode 100644 index 0000000..4bdf155 --- /dev/null +++ b/Praktikum2/ppm1/templates/detail.tpl @@ -0,0 +1,37 @@ + + + + + Praxisphasenmanager (PPM) + + + + + +

+ ${data['category']}: Ihre Daten +

+
+

+ Das Formular ausfüllen/korrigieren und auf "speichern" klicken: +

+
+ + + % for field in data['content']: +
+ + +
+ % endfor + +
+ Zurueck + +
+
+
+ + \ No newline at end of file diff --git a/Praktikum2/ppm1/templates/index.tpl b/Praktikum2/ppm1/templates/index.tpl new file mode 100644 index 0000000..f83d09d --- /dev/null +++ b/Praktikum2/ppm1/templates/index.tpl @@ -0,0 +1,32 @@ + + + + + Praxisphasenmanager (PPM) + + + + + + +

+ Praxisphasenmanager (PPM) +

+
+

+ Funktionen +

+
+ Datenpflege: Studenten + Datenpflege: Lehrende + Angebot Praxisphasen + Firmenverzeichnis +
+
+ Auswertungen +
+
+ + \ No newline at end of file diff --git a/Praktikum2/ppm1/templates/list.tpl b/Praktikum2/ppm1/templates/list.tpl new file mode 100644 index 0000000..de79f28 --- /dev/null +++ b/Praktikum2/ppm1/templates/list.tpl @@ -0,0 +1,68 @@ + + + + + Praxisphasenmanager (PPM) + + + + + + +

+ Praxisphasenmanager (PPM) +

+
+

+ Übersicht + % if data['category'] == 'students': + Studenten + % elif data['category'] == 'teachers': + Lehrende + % elif data['category'] == 'companies': + Firmen + % elif data['category'] == 'offerings': + Angebote + % endif +

+
+ + + + % if data['content']!= None: + % for heading in data['headings']: + % if heading!='id': + + % endif + % endfor + % else: + + % endif + + % if data['content']!= None: + + % for entries in data['content']: + + % for entry in data['content'][entries]: + % if entry!='id': + + % endif + % endfor + + % endfor + + % endif + + +
${heading}Bisher kein Inhalt
${data['content'][entries][entry]}
+
+ +
+ Neu + Startseite +
+
+ + \ No newline at end of file diff --git a/Praktikum2/ppm1/tmp/detail.html b/Praktikum2/ppm1/tmp/detail.html new file mode 100644 index 0000000..52034d6 --- /dev/null +++ b/Praktikum2/ppm1/tmp/detail.html @@ -0,0 +1,30 @@ + + + + + Registrierung + + + + + +

+ Ihre Daten +

+
+

+ Das Formular ausfüllen/korrigieren und auf "speichern" klicken: +

+
+ + + +
+ + +
+ + + \ No newline at end of file diff --git a/Praktikum2/ppm1/tmp/list.html b/Praktikum2/ppm1/tmp/list.html new file mode 100644 index 0000000..d236bdb --- /dev/null +++ b/Praktikum2/ppm1/tmp/list.html @@ -0,0 +1,54 @@ + + + + + Praxisphasenmanager (PPM) + + + + + + +

+ SiteHeader +

+
+

+ Übersicht +

+
+ + + + + + + + + + + +
th1th2th3th4th5th6
+
+ + +
+ + \ No newline at end of file