Sammlung
This commit is contained in:
3
Sammlung/Praktikum/4/app/__init__.py
Normal file
3
Sammlung/Praktikum/4/app/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
# coding: utf-8
|
||||
|
||||
# hier können Paket-Initialisierungen eingetragen werden
|
BIN
Sammlung/Praktikum/4/app/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/__init__.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/__init__.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/application.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/application.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/database.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/database.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/database.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/database.cpython-35.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/discussion.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/discussion.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/discussion.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/discussion.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/login.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/login.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/login.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/login.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/mytime.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/mytime.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/post.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/post.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/post.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/post.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/template.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/template.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/template.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/template.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/topic.cpython-34.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/topic.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/topic.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/topic.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/Praktikum/4/app/__pycache__/view.cpython-35.pyc
Normal file
BIN
Sammlung/Praktikum/4/app/__pycache__/view.cpython-35.pyc
Normal file
Binary file not shown.
25
Sammlung/Praktikum/4/app/application.py
Normal file
25
Sammlung/Praktikum/4/app/application.py
Normal file
@ -0,0 +1,25 @@
|
||||
# coding: utf-8
|
||||
|
||||
import cherrypy
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Application_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------
|
||||
def default(self, *arguments, **kwargs):
|
||||
#-------------------------------------------------------
|
||||
msg_s = "unbekannte Anforderung: " + \
|
||||
str(arguments) + \
|
||||
' ' + \
|
||||
str(kwargs)
|
||||
raise cherrypy.HTTPError(404, msg_s)
|
||||
|
||||
# EOF
|
340
Sammlung/Praktikum/4/app/database.py
Normal file
340
Sammlung/Praktikum/4/app/database.py
Normal file
@ -0,0 +1,340 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import codecs
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Database_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
# alle Elemente werden zur Laufzeit des Servers zur Vereinfachung auch im
|
||||
# Hauptspeicher abgelegt
|
||||
|
||||
# die nächste zu vergebende Id wird ebenfalls dauerhaft gespeichert
|
||||
|
||||
# zur Vereinfachung wird hier fest vorgegebenen, dass sich die Daten
|
||||
# im Unterverzeichnis "data" befinden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
self.data_o = {}
|
||||
self.readData_p()
|
||||
|
||||
#-------------------------------------------------------
|
||||
def createTopic_px(self, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
id_ = self.nextTopicId_p()
|
||||
self.data_o['topics'][str(id_)] = data_opl
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'topics.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['topics']))
|
||||
file_o.close()
|
||||
|
||||
return id_
|
||||
|
||||
#-------------------------------------------------------
|
||||
def createDiscussion_px(self, tId, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
id_ = self.nextDiscussionId_p()
|
||||
self.data_o['discussions'][id_] = data_opl
|
||||
self.data_o['topics'][tId]['discs'].append(id_)
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'discussions.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['discussions']))
|
||||
file_o.close()
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'topics.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['topics']))
|
||||
file_o.close()
|
||||
|
||||
return id_
|
||||
|
||||
#-------------------------------------------------------
|
||||
def createPost_px(self, dId, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
|
||||
id_ = self.nextPostId_p()
|
||||
self.data_o['posts'][id_] = data_opl
|
||||
self.data_o['discussions'][dId]['posts'].append(id_)
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'posts.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['posts']))
|
||||
file_o.close()
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'discussions.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['discussions']))
|
||||
file_o.close()
|
||||
|
||||
return id_
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def readTopic_px(self, id_ = None):
|
||||
#-------------------------------------------------------
|
||||
# hier zur Vereinfachung:
|
||||
# Aufruf ohne id: alle Einträge liefern
|
||||
data_o = None
|
||||
if id_ == None:
|
||||
data_o = self.data_o['topics']
|
||||
elif str(id_) == '0':
|
||||
data_o = self.getDefaultTopic_px()
|
||||
else:
|
||||
if str(id_) in self.data_o['topics']:
|
||||
data_o = self.data_o['topics'][str(id_)]
|
||||
|
||||
return data_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def readDiscussion_px(self, tId, dId = None):
|
||||
#-------------------------------------------------------
|
||||
# hier zur Vereinfachung:
|
||||
# Aufruf ohne id: alle Einträge liefern
|
||||
data_o = None
|
||||
if dId == None:
|
||||
data_o = {}
|
||||
discs = self.data_o['discussions']
|
||||
indices = self.data_o['topics'][str(tId)]['discs']
|
||||
for index in indices:
|
||||
data_o[index] = discs[index]
|
||||
elif str(dId) == '0':
|
||||
data_o = self.getDefaultDiscussion_px()
|
||||
else:
|
||||
if str(dId) in self.data_o['discussions']:
|
||||
data_o = self.data_o['discussions'][str(dId)]
|
||||
|
||||
return data_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def readPost_px(self, dId, pId = None):
|
||||
#-------------------------------------------------------
|
||||
# hier zur Vereinfachung:
|
||||
# Aufruf ohne id: alle Einträge liefern
|
||||
data_o = None
|
||||
if pId == None:
|
||||
data_o = {}
|
||||
posts = self.data_o['posts']
|
||||
indices = self.data_o['discussions'][str(dId)]['posts']
|
||||
for index in indices:
|
||||
data_o[index] = posts[index]
|
||||
elif str(pId) == '0':
|
||||
data_o = self.getDefaultPost_px()
|
||||
else:
|
||||
if str(pId) in self.data_o['posts']:
|
||||
data_o = self.data_o['posts'][str(pId)]
|
||||
|
||||
return data_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def updateTopic_px(self, id_, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
updated = False
|
||||
if id_ in self.data_o['topics']:
|
||||
for key in data_opl:
|
||||
self.data_o['topics'][id_][key] = data_opl[key]
|
||||
|
||||
# Datei aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'topics.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['topics']))
|
||||
file_o.close()
|
||||
|
||||
updated = True
|
||||
|
||||
return updated
|
||||
|
||||
#-------------------------------------------------------
|
||||
def updateDiscussion_px(self, id_, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
updated = False
|
||||
if id_ in self.data_o['discussions']:
|
||||
for key in data_opl:
|
||||
self.data_o['discussions'][id_][key] = data_opl[key]
|
||||
|
||||
# Datei aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'discussions.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['discussions']))
|
||||
file_o.close()
|
||||
|
||||
updated = True
|
||||
|
||||
return updated
|
||||
|
||||
#-------------------------------------------------------
|
||||
def updatePost_px(self, id_, data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Überprüfung der Daten müsste ergänzt werden!
|
||||
updated = False
|
||||
if id_ in self.data_o['posts']:
|
||||
for key in data_opl:
|
||||
self.data_o['posts'][id_][key] = data_opl[key]
|
||||
|
||||
# Datei aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'posts.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['posts']))
|
||||
file_o.close()
|
||||
|
||||
updated = True
|
||||
|
||||
return updated
|
||||
|
||||
#-------------------------------------------------------
|
||||
def deleteTopic_px(self, id_):
|
||||
#-------------------------------------------------------
|
||||
deleted = False
|
||||
if id_ in self.data_o['topics']:
|
||||
self.data_o['topics'][id_]['deleted'] = True
|
||||
for key in self.data_o['topics'][id_]['discs']:
|
||||
del self.data_o['discussions'][key]
|
||||
self.data_o['topics'][id_]['discs'] = []
|
||||
|
||||
# Dateien aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'topics.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['topics']))
|
||||
file_o.close()
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'discussions.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['discussions']))
|
||||
file_o.close()
|
||||
|
||||
deleted = True
|
||||
|
||||
return deleted
|
||||
|
||||
#-------------------------------------------------------
|
||||
def deleteDiscussion_px(self, id_):
|
||||
#-------------------------------------------------------
|
||||
deleted = False
|
||||
if id_ in self.data_o['discussions']:
|
||||
self.data_o['discussions'][id_]['deleted'] = True
|
||||
for key in self.data_o['discussions'][id_]['posts']:
|
||||
del self.data_o['posts'][key]
|
||||
self.data_o['discussions'][id_]['posts'] = []
|
||||
|
||||
# Dateien aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'discussions.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['discussions']))
|
||||
file_o.close()
|
||||
|
||||
file_o = codecs.open(os.path.join('data', 'posts.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['posts']))
|
||||
file_o.close()
|
||||
|
||||
deleted = True
|
||||
|
||||
return deleted
|
||||
|
||||
#-------------------------------------------------------
|
||||
def deletePost_px(self, id_):
|
||||
#-------------------------------------------------------
|
||||
deleted = False
|
||||
if id_ in self.data_o['posts']:
|
||||
self.data_o['posts'][id_]['deleted'] = True
|
||||
|
||||
# Datei aktualisieren
|
||||
file_o = codecs.open(os.path.join('data', 'posts.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['posts']))
|
||||
file_o.close()
|
||||
|
||||
deleted = True
|
||||
|
||||
return deleted
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getDefaultTopic_px(self):
|
||||
#-------------------------------------------------------
|
||||
|
||||
return {
|
||||
'name' : '',
|
||||
'owner': '',
|
||||
'deleted': False,
|
||||
'discs': []
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getDefaultDiscussion_px(self):
|
||||
#-------------------------------------------------------
|
||||
|
||||
return {
|
||||
'name' : '',
|
||||
'owner': '',
|
||||
'deleted': False,
|
||||
'posts': []
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getDefaultPost_px(self):
|
||||
#-------------------------------------------------------
|
||||
return {
|
||||
'title' : '',
|
||||
'text' : '',
|
||||
'owner': '',
|
||||
'time': time.localtime(),
|
||||
'deleted': False,
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getUsers_px(self):
|
||||
#-------------------------------------------------------
|
||||
|
||||
return self.data_o['users']
|
||||
|
||||
#-------------------------------------------------------
|
||||
def saveUsers_px(self, data_o):
|
||||
#-------------------------------------------------------
|
||||
file_o = codecs.open(os.path.join('data', 'users.dat'), 'w', 'utf-8')
|
||||
file_o.write(json.dumps(self.data_o['users']))
|
||||
file_o.close()
|
||||
|
||||
#-------------------------------------------------------
|
||||
def readData_p(self):
|
||||
#-------------------------------------------------------
|
||||
|
||||
files_a = os.listdir('data')
|
||||
for fileName_s in files_a:
|
||||
if fileName_s.endswith('.dat'):
|
||||
file_o = codecs.open(os.path.join('data', fileName_s), 'rU', 'utf-8')
|
||||
content_s = file_o.read()
|
||||
file_o.close()
|
||||
id_s = fileName_s[:-4]
|
||||
self.data_o[id_s] = json.loads(content_s)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def nextTopicId_p(self):
|
||||
#-------------------------------------------------------
|
||||
id_ = str(self.data_o['topics']['nextID'])
|
||||
nextID = int(self.data_o['topics']['nextID'])
|
||||
self.data_o['topics']['nextID'] = str(nextID + 1)
|
||||
|
||||
return id_
|
||||
|
||||
#-------------------------------------------------------
|
||||
def nextDiscussionId_p(self):
|
||||
#-------------------------------------------------------
|
||||
id_ = str(self.data_o['discussions']['nextID'])
|
||||
nextID = int(self.data_o['discussions']['nextID'])
|
||||
self.data_o['discussions']['nextID'] = str(nextID + 1)
|
||||
|
||||
return id_
|
||||
|
||||
#-------------------------------------------------------
|
||||
def nextPostId_p(self):
|
||||
#-------------------------------------------------------
|
||||
id_ = str(self.data_o['posts']['nextID'])
|
||||
nextID = int(self.data_o['posts']['nextID'])
|
||||
self.data_o['posts']['nextID'] = str(nextID + 1)
|
||||
|
||||
return id_
|
||||
|
||||
db_o = Database_cl()
|
||||
# EOF
|
120
Sammlung/Praktikum/4/app/discussion.py
Normal file
120
Sammlung/Praktikum/4/app/discussion.py
Normal file
@ -0,0 +1,120 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
|
||||
import cherrypy
|
||||
|
||||
from app import database
|
||||
|
||||
# Method-Dispatching!
|
||||
|
||||
# Übersicht Anforderungen / Methoden
|
||||
# (beachte: / relativ zu /discussion, siehe Konfiguration Server!)
|
||||
|
||||
"""
|
||||
|
||||
Anforderung GET PUT POST DELETE
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/diskussion/{thema-id} alle disk. neue Diskussion - -
|
||||
zum Thema zum Thema speichern
|
||||
ausgeben diskussion-id zurück
|
||||
|
||||
/diskussion/{diskussion-id} eine - Diskussion mit ID Diskussion mit ID
|
||||
Diskussion ändern löschen
|
||||
anfordern
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Discussion_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
# spezielle Initialisierung können hier eingetragen werden
|
||||
self.db_o = database.db_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def GET(self, tId, dId = None):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {'data': None, 'id': None, 'tId': tId}
|
||||
|
||||
if dId == None:
|
||||
# Anforderung der Liste
|
||||
retVal_o['data'] = self.getList_p(tId)
|
||||
else:
|
||||
# Anforderung eines Dokuments
|
||||
retVal_o['data'] = self.getDiscussion(tId, dId)
|
||||
retVal_o['id'] = dId
|
||||
|
||||
if retVal_o['data'] == None:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def POST(self, tId, id_, **data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Sichern der Daten: jetzt wird keine vollständige Seite
|
||||
# zurückgeliefert, sondern nur noch die Information, ob das
|
||||
# Speichern erfolgreich war
|
||||
|
||||
retVal_o = {
|
||||
'id': None
|
||||
}
|
||||
|
||||
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
||||
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
||||
id_ = str(id_)
|
||||
data_o = self.db_o.data_o['discussions'][id_]
|
||||
data_o['name'] = data_opl['name']
|
||||
|
||||
# Update-Operation
|
||||
retVal_o['id'] = id_
|
||||
if self.db_o.updateDiscussion_px(id_, data_o):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def DELETE(self, id_):
|
||||
#-------------------------------------------------------
|
||||
# Eintrag löschen, nur noch Rückmeldung liefern
|
||||
retVal_o = {
|
||||
'id': id_
|
||||
}
|
||||
|
||||
if self.db_o.deleteDiscussion_px(id_):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getList_p(self, tId):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readDiscussion_px(tId)
|
||||
|
||||
return data_o
|
||||
getList_p.exposed = False;
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getDiscussion(self, tId, dId):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readDiscussion_px(tId, dId)
|
||||
|
||||
return data_o
|
||||
getDiscussion.exposed = False;
|
||||
|
||||
# EOF
|
54
Sammlung/Praktikum/4/app/login.py
Normal file
54
Sammlung/Praktikum/4/app/login.py
Normal file
@ -0,0 +1,54 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
import cherrypy
|
||||
|
||||
from app import database
|
||||
# Method-Dispatching!
|
||||
|
||||
# (beachte: / relativ zu /login, siehe Konfiguration Server!)
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Login_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
self.db_o = database.Database_cl()
|
||||
|
||||
|
||||
|
||||
#**********************REST ANSATZ**********************
|
||||
#-------------------------------------------------------
|
||||
def GET(self, **data_o):
|
||||
#-------------------------------------------------------
|
||||
authenticated = False
|
||||
|
||||
users = self.db_o.getUsers_px();
|
||||
if data_o['username'] in users and data_o['password'] == users[data_o['username']]:
|
||||
authenticated = True
|
||||
|
||||
return json.dumps(authenticated)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def PUT(self, **data_o):
|
||||
#-------------------------------------------------------
|
||||
success = False
|
||||
|
||||
users = self.db_o.getUsers_px();
|
||||
if data_o['username'] not in users:
|
||||
users[data_o['username']] = data_o['password']
|
||||
self.db_o.saveUsers_px(users);
|
||||
success = True
|
||||
|
||||
return json.dumps(success)
|
||||
#*******************************************************
|
||||
|
||||
# EOF
|
46
Sammlung/Praktikum/4/app/mytime.py
Normal file
46
Sammlung/Praktikum/4/app/mytime.py
Normal file
@ -0,0 +1,46 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
import cherrypy
|
||||
import time
|
||||
|
||||
from app import database
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Time_cl(object):
|
||||
#----------------------------------------------------------
|
||||
exposed=True
|
||||
#----------------------------------------------------------
|
||||
def __init__(self):
|
||||
#----------------------------------------------------------
|
||||
t = time.localtime()
|
||||
self.date_o = {
|
||||
"day":"",
|
||||
"month":"",
|
||||
"year":"",
|
||||
"hour":"",
|
||||
"minute":""
|
||||
}
|
||||
self.date_o['day'] = t[2]
|
||||
self.date_o['month']=t[1]
|
||||
self.date_o['year']=t[0]
|
||||
self.date_o['hour']=t[3]
|
||||
self.date_o['minute']=t[4]
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
def getDateAsString_px(self):
|
||||
#----------------------------------------------------------
|
||||
return str(self.date_o['hour'])+':'+str(self.date_o['minute'])+' | '+str(self.date_o['day'])+'.'+str(self.date_o['month'])+'.'+str(self.date_o['year'] )
|
||||
|
||||
#----------------------------------------------------------
|
||||
def getDate_px(self):
|
||||
#----------------------------------------------------------
|
||||
return self.date_o
|
||||
|
||||
# EOF
|
150
Sammlung/Praktikum/4/app/post.py
Normal file
150
Sammlung/Praktikum/4/app/post.py
Normal file
@ -0,0 +1,150 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import cherrypy
|
||||
|
||||
from app import database
|
||||
|
||||
# Method-Dispatching!
|
||||
|
||||
# Übersicht Anforderungen / Methoden
|
||||
# (beachte: / relativ zu /discussion, siehe Konfiguration Server!)
|
||||
|
||||
"""
|
||||
|
||||
Anforderung GET PUT POST DELETE
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
||||
/beitrag/{diskussion-id} alle Beiträge neuen Beitrag - -
|
||||
zur Diskussion zur Diskussion speichern
|
||||
anfordern beitrag-id zurück
|
||||
|
||||
/beitrag/{beitrag-id} einen Beitrag - Beitrag mit ID Beitrag mit ID
|
||||
anfordern ändern löschen
|
||||
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Post_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
# spezielle Initialisierung können hier eingetragen werden
|
||||
self.db_o = database.db_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def GET(self, tId, dId, pId = None):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {'data': None, 'id': pId, 'tId':tId, 'dId': dId}
|
||||
|
||||
if dId == None:
|
||||
# Anforderung der Liste
|
||||
retVal_o['data'] = self.getList_p(dId)
|
||||
else:
|
||||
# Anforderung eines Dokuments
|
||||
retVal_o['data'] = self.getPost(dId, pId)
|
||||
|
||||
if retVal_o['data'] == None:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def PUT(self, tId, dId, **data_opl):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {
|
||||
'id': None,
|
||||
'dId': dId
|
||||
}
|
||||
|
||||
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
||||
if dId == 0 or dId == "0":
|
||||
discData_o = self.db_o.getDefaultDiscussion_px()
|
||||
discData_o['name'] = data_opl['title']
|
||||
discData_o['owner'] = data_opl['owner']
|
||||
dId = self.db_o.createDiscussion_px(tId, discData_o)
|
||||
retVal_o['dId'] = dId
|
||||
|
||||
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
||||
data_o = self.db_o.getDefaultPost_px()
|
||||
data_o['title'] = data_opl['title']
|
||||
data_o['text'] = data_opl['text']
|
||||
data_o['owner'] = data_opl['owner']
|
||||
|
||||
# Create-Operation
|
||||
id_s = self.db_o.createPost_px(dId, data_o)
|
||||
retVal_o['id'] = id_s
|
||||
if retVal_o['id'] == None:
|
||||
cherrypy.response.status = 409
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def POST(self, tId, dId, id_, **data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Sichern der Daten: jetzt wird keine vollständige Seite
|
||||
# zurückgeliefert, sondern nur noch die Information, ob das
|
||||
# Speichern erfolgreich war
|
||||
|
||||
retVal_o = {
|
||||
'id': None,
|
||||
'tId': tId,
|
||||
'dId': dId
|
||||
}
|
||||
|
||||
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
||||
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
||||
id_ = str(id_)
|
||||
data_o = self.db_o.data_o['posts'][id_]
|
||||
data_o['text'] = data_opl['text']
|
||||
data_o['title'] = data_opl['title']
|
||||
|
||||
# Update-Operation
|
||||
retVal_o['id'] = id_
|
||||
if self.db_o.updatePost_px(id_, data_o):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def DELETE(self, id_):
|
||||
#-------------------------------------------------------
|
||||
# Eintrag löschen, nur noch Rückmeldung liefern
|
||||
retVal_o = {
|
||||
'id': id_
|
||||
}
|
||||
|
||||
if self.db_o.deletePost_px(id_):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getList_p(self, tId):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readPost_px(tId)
|
||||
|
||||
return data_o
|
||||
getList_p.exposed = False;
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getPost(self, tId, dId):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readPost_px(tId, dId)
|
||||
|
||||
return data_o
|
||||
getPost.exposed = False;
|
||||
|
||||
# EOF
|
52
Sammlung/Praktikum/4/app/template.py
Normal file
52
Sammlung/Praktikum/4/app/template.py
Normal file
@ -0,0 +1,52 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
import cherrypy
|
||||
|
||||
# Method-Dispatching!
|
||||
|
||||
# Übersicht Anforderungen / Methoden
|
||||
# (beachte: / relativ zu /template, siehe Konfiguration Server!)
|
||||
|
||||
"""
|
||||
|
||||
Anforderung GET PUT POST DELETE
|
||||
----------------------------------------------------------------
|
||||
/ Alle - - -
|
||||
Templates
|
||||
liefern
|
||||
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Template_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------
|
||||
def GET(self):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {
|
||||
'templates': {}
|
||||
}
|
||||
|
||||
files_a = os.listdir('templates')
|
||||
for fileName_s in files_a:
|
||||
file_o = codecs.open(os.path.join('templates', fileName_s), 'rU', 'utf-8')
|
||||
content_s = file_o.read()
|
||||
file_o.close()
|
||||
retVal_o["templates"][fileName_s] = content_s
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
# EOF
|
149
Sammlung/Praktikum/4/app/topic.py
Normal file
149
Sammlung/Praktikum/4/app/topic.py
Normal file
@ -0,0 +1,149 @@
|
||||
# coding: utf-8
|
||||
|
||||
import json
|
||||
|
||||
import cherrypy
|
||||
|
||||
from app import database
|
||||
|
||||
# Method-Dispatching!
|
||||
|
||||
# Übersicht Anforderungen / Methoden
|
||||
# (beachte: / relativ zu /topic, siehe Konfiguration Server!)
|
||||
|
||||
"""
|
||||
|
||||
Anforderung GET PUT POST DELETE
|
||||
----------------------------------------------------------------
|
||||
/ Liste - - -
|
||||
Themen
|
||||
liefern
|
||||
|
||||
/0 Thema Thema - -
|
||||
mit id=0 anlegen
|
||||
liefern
|
||||
(Vorgabe-Werte)
|
||||
|
||||
/{id} Thema - Thema Thema
|
||||
mit {id} ändern löschen
|
||||
liefern
|
||||
|
||||
id > 0 !
|
||||
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Topic_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
# spezielle Initialisierung können hier eingetragen werden
|
||||
self.db_o = database.db_o
|
||||
|
||||
#-------------------------------------------------------
|
||||
def GET(self, id_ = None):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {'data': None, 'id': None}
|
||||
|
||||
if id == None:
|
||||
# Anforderung der Liste
|
||||
retVal_o['data'] = self.getList_p()
|
||||
else:
|
||||
# Anforderung eines Dokuments
|
||||
retVal_o['data'] = self.getTopic(id_)
|
||||
retVal_o['id'] = id_
|
||||
|
||||
if retVal_o['data'] == None:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def PUT(self, **data_opl):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {
|
||||
'id': None
|
||||
}
|
||||
|
||||
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
||||
|
||||
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
||||
|
||||
print(data_opl)
|
||||
data_o = {
|
||||
'name' : data_opl['name'],
|
||||
'owner': data_opl['owner'],
|
||||
'deleted': False,
|
||||
'discs': []
|
||||
}
|
||||
|
||||
# Create-Operation
|
||||
id_s = self.db_o.createTopic_px(data_o)
|
||||
retVal_o['id'] = id_s
|
||||
if retVal_o['id'] == None:
|
||||
cherrypy.response.status = 409
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def POST(self, id_, **data_opl):
|
||||
#-------------------------------------------------------
|
||||
# Sichern der Daten: jetzt wird keine vollständige Seite
|
||||
# zurückgeliefert, sondern nur noch die Information, ob das
|
||||
# Speichern erfolgreich war
|
||||
|
||||
retVal_o = {
|
||||
'id': None
|
||||
}
|
||||
|
||||
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
||||
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
||||
id_ = str(id_)
|
||||
data_o = self.db_o.data_o['topics'][id_]
|
||||
data_o['name'] = data_opl['name']
|
||||
|
||||
# Update-Operation
|
||||
retVal_o['id'] = id_
|
||||
if self.db_o.updateTopic_px(id_, data_o):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def DELETE(self, id_):
|
||||
#-------------------------------------------------------
|
||||
# Eintrag löschen, nur noch Rückmeldung liefern
|
||||
retVal_o = {
|
||||
'id': id_
|
||||
}
|
||||
|
||||
if self.db_o.deleteTopic_px(id_):
|
||||
pass
|
||||
else:
|
||||
cherrypy.response.status = 404
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getList_p(self):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readTopic_px()
|
||||
|
||||
return data_o
|
||||
getList_p.exposed = False;
|
||||
|
||||
#-------------------------------------------------------
|
||||
def getTopic(self, id_spl):
|
||||
#-------------------------------------------------------
|
||||
data_o = self.db_o.readTopic_px(id_spl)
|
||||
|
||||
return data_o
|
||||
getTopic.exposed = False;
|
||||
|
||||
# EOF
|
Reference in New Issue
Block a user