Sammlung
This commit is contained in:
44
Sammlung/web_p4/app/Absolventenfeier.py
Normal file
44
Sammlung/web_p4/app/Absolventenfeier.py
Normal file
@ -0,0 +1,44 @@
|
||||
import cherrypy
|
||||
import json
|
||||
import os
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
from mako import exceptions
|
||||
from app import view
|
||||
from app import account
|
||||
|
||||
class Absolventenfeier_cl( object ):
|
||||
|
||||
def __init__( self ):
|
||||
self._view = view.view()
|
||||
self._account = account.Account()
|
||||
|
||||
@cherrypy.expose
|
||||
def index( self ):
|
||||
return self._view.index()
|
||||
|
||||
@cherrypy.expose
|
||||
def registration_form( self ):
|
||||
return self._view.registration_form()
|
||||
|
||||
@cherrypy.expose
|
||||
def edit_form( self, ident = -1 ):
|
||||
return self._view.edit_form( ident )
|
||||
|
||||
@cherrypy.expose
|
||||
def save( self, **form_input ):
|
||||
if( not form_input.get( 'ID' ) ):
|
||||
self._account.registration( **form_input )
|
||||
else:
|
||||
if( not self._account.edit( **form_input ) ):
|
||||
return self._view.error_page( "Die Eingabe war fehlerhaft!" )
|
||||
return self._view.index()
|
||||
|
||||
@cherrypy.expose
|
||||
def default(self, *arglist, **kwargs):
|
||||
msg_s = "unbekannte Anforderung: " + \
|
||||
str(arglist) + \
|
||||
' ' + \
|
||||
str(kwargs)
|
||||
raise cherrypy.HTTPError(404, msg_s)
|
||||
|
2
Sammlung/web_p4/app/__init__.py
Normal file
2
Sammlung/web_p4/app/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
# python package initialization
|
||||
|
BIN
Sammlung/web_p4/app/__pycache__/Absolventenfeier.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/Absolventenfeier.cpython-34.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/Absolventenfeier.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/Absolventenfeier.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/__init__.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/__init__.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/account.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/account.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/account.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/account.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/application.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/application.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/converter.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/converter.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/converter.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/converter.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/counter.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/counter.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/counter.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/counter.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/database.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/database.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/database.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/database.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/registration.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/registration.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/validator.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/validator.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/validator.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/validator.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/view.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/view.cpython-34.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/view.cpython-35.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/view.cpython-35.pyc
Normal file
Binary file not shown.
BIN
Sammlung/web_p4/app/__pycache__/welcomepage.cpython-34.pyc
Normal file
BIN
Sammlung/web_p4/app/__pycache__/welcomepage.cpython-34.pyc
Normal file
Binary file not shown.
33
Sammlung/web_p4/app/account.py
Normal file
33
Sammlung/web_p4/app/account.py
Normal file
@ -0,0 +1,33 @@
|
||||
import json
|
||||
from app import converter
|
||||
from app import counter
|
||||
from app import database
|
||||
from app import validator
|
||||
|
||||
class Account( object ):
|
||||
|
||||
def __init__( self ):
|
||||
self._path = "./data/"
|
||||
self._file_extension = ".json"
|
||||
self._counter = counter.Counter()
|
||||
self._converter = converter.Converter()
|
||||
self._database = database.Database( self._path, self._file_extension )
|
||||
self._validator = validator.Validator( self._database, self._counter )
|
||||
|
||||
def registration( self, **form_data ):
|
||||
new_ident = str( self._counter.read() )
|
||||
self._counter.increase( 1 )
|
||||
form_data.update( {'ID':new_ident} )
|
||||
json_data = self._converter.jsonify( **form_data )
|
||||
self._database.write( new_ident, form_data )
|
||||
|
||||
def edit( self, **form_data ):
|
||||
if( self._validator.validate( "vorname", "nachname", "passwort", **form_data ) ):
|
||||
if( form_data.get( 'loeschen' ) == "yes" ):
|
||||
self._database.erase( form_data.get( 'ID' ) )
|
||||
else:
|
||||
self._database.write( form_data.get( 'ID' ), form_data )
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
6
Sammlung/web_p4/app/converter.py
Normal file
6
Sammlung/web_p4/app/converter.py
Normal file
@ -0,0 +1,6 @@
|
||||
import json
|
||||
|
||||
class Converter( object ):
|
||||
|
||||
def jsonify( self, **form_input ):
|
||||
return json.dumps( form_input, separators=(',',':') )
|
29
Sammlung/web_p4/app/counter.py
Normal file
29
Sammlung/web_p4/app/counter.py
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
class Counter( object ):
|
||||
|
||||
#counter_file = open('./ID_File.txt', 'r+')
|
||||
|
||||
def read( self ):
|
||||
counter_file = open('./ID_File.txt', 'r')
|
||||
counter = counter_file.read()
|
||||
counter = int( counter )
|
||||
counter_file.close()
|
||||
return counter
|
||||
|
||||
def increase( self, n ):
|
||||
counter_file = open('./ID_File.txt', 'r')
|
||||
counter = counter_file.read()
|
||||
counter = int( counter )
|
||||
counter_file.close()
|
||||
counter += n
|
||||
counter_file = open( './ID_File.txt', 'w')
|
||||
counter_file.write( str( counter ) )
|
||||
counter_file.close()
|
||||
|
||||
def decrease( self, n ):
|
||||
counter_file = open('./ID_File.txt', 'w')
|
||||
counter = counter_file.read()
|
||||
counter = int( counter )
|
||||
counter -= n
|
||||
counter_file.write( str( counter ) )
|
||||
counter_file.close()
|
24
Sammlung/web_p4/app/database.py
Normal file
24
Sammlung/web_p4/app/database.py
Normal file
@ -0,0 +1,24 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
class Database( object ):
|
||||
|
||||
def __init__( self, path, file_extension ):
|
||||
self._path = path
|
||||
self._file_extension = file_extension
|
||||
|
||||
def write( self, filename, data ):
|
||||
with open( self._path + str(filename) + self._file_extension, 'w' ) as outfile:
|
||||
json.dump( data, outfile )
|
||||
|
||||
def read( self, filename ):
|
||||
json_data = open( self._path + str(filename) + self._file_extension, 'r' )
|
||||
data = json.load( json_data )
|
||||
json_data.close()
|
||||
return data
|
||||
|
||||
def erase( self, filename ):
|
||||
os.remove( self._path + str(filename) + self._file_extension )
|
||||
|
||||
def exists( self, filename ):
|
||||
return os.path.exists( self._path + str(filename) + self._file_extension )
|
28
Sammlung/web_p4/app/validator.py
Normal file
28
Sammlung/web_p4/app/validator.py
Normal file
@ -0,0 +1,28 @@
|
||||
from mako import exceptions
|
||||
import json
|
||||
from app import database
|
||||
from app import view
|
||||
|
||||
class Validator( object ):
|
||||
|
||||
def __init__( self, database, counter ):
|
||||
self._database = database
|
||||
self._counter = counter
|
||||
|
||||
def validate( self, *to_check, **form_input ):
|
||||
counter = 0
|
||||
fails = ""
|
||||
ident = form_input.get( 'ID' )
|
||||
data = self._database.read( ident )
|
||||
if( not self._database.exists( ident ) ):
|
||||
pass # Fehlerbehandlung
|
||||
return 0
|
||||
for key in to_check:
|
||||
if( form_input.get( key ) == data[key] ):
|
||||
counter += 1
|
||||
else:
|
||||
fails += key + ", "
|
||||
if( counter == len( to_check ) ):
|
||||
return 1
|
||||
else:
|
||||
return 0
|
39
Sammlung/web_p4/app/view.py
Normal file
39
Sammlung/web_p4/app/view.py
Normal file
@ -0,0 +1,39 @@
|
||||
from mako import exceptions
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
|
||||
class view( object ):
|
||||
def index( self ):
|
||||
try:
|
||||
index_template = Template(filename='./content/index.txt')
|
||||
return index_template.render()
|
||||
except:
|
||||
return exceptions.html_error_template().render()
|
||||
|
||||
def registration_form( self ):
|
||||
try:
|
||||
registration_form_template = Template(filename='./content/registration_form.txt')
|
||||
return registration_form_template.render()
|
||||
except:
|
||||
return exceptions.html_error_template().render()
|
||||
|
||||
def password_form( self, ident ):
|
||||
try:
|
||||
password_form_template = Template(filename='./content/password_form.txt')
|
||||
return password_form_template.render( ident )
|
||||
except:
|
||||
return exceptions.html_error_template().render()
|
||||
|
||||
def edit_form( self, ident ):
|
||||
try:
|
||||
edit_form_template = Template(filename='./content/edit_form.txt')
|
||||
return edit_form_template.render( ID=ident )
|
||||
except:
|
||||
return exceptions.html_error_template().render()
|
||||
|
||||
def error_page( self, msg ):
|
||||
try:
|
||||
error_page_template = Template(filename='./content/error_page.txt')
|
||||
return error_page_template.render( MSG=msg )
|
||||
except:
|
||||
return exceptions.html_error_template().render()
|
Reference in New Issue
Block a user