Commit bd6c0424 by CapsLock

[feature] form to add a picture to hostname moved to hostname page, boilerplate…

[feature] form to add a picture to hostname moved to hostname page, boilerplate form to create hostname alias
parent e9854582
from bottle import Bottle, route, run, template, request, static_file
from bottle import Bottle, route, run, template, request, static_file, redirect
import bottle_pgsql
import bottle
import datetime
......@@ -68,25 +68,26 @@ def default(db):
' and dn.name = %s', (get_host_name(),))
pictures = db.fetchall()
return template('default', pictures=pictures, domain_names=domain_names)
current_domain = get_host_name()
return template('default', pictures=pictures, domain_names=domain_names, current_domain=current_domain)
# create new alias
@app.route('/new')
def upload_form():
current_domain = get_host_name()
return template('newAlias', current_domain=current_domain)
# # create new alias
# @app.route('/new')
# def upload_form():
# current_domain = get_host_name()
# return template('newAlias', current_domain=current_domain)
# upload new pictures
@app.route('/new', method='POST')
def do_upload(db):
domain = request.forms.get('domain')
description = request.forms.get('domain')
description = request.forms.get('description')
upload = request.files.get('upload')
name, ext = os.path.splitext(upload.filename)
if ext not in ('.png', '.jpg', '.jpeg', 'gif'):
if ext not in ('.png', '.jpg', '.jpeg', '.gif'):
return 'File extension not allowed.'
destination_filename = os.path.join('uploads', '%s%s' %
......@@ -121,7 +122,7 @@ def do_upload(db):
save_path = os.path.join(PROJECT_PATH, destination_filename)
upload.save(save_path) # appends upload.filename automatically
return 'OK'
return redirect('/')
# serves static files
......
......@@ -12,4 +12,19 @@
<img src="{{p['filename']}}" style="max-width: 320px; max-height: 240px;"/>
<span>{{p['description']}}</span>
</p>
% end
\ No newline at end of file
% end
<h1>upload new photo:</h1>
<form action="/new" method="post" enctype="multipart/form-data">
<input type="hidden" name="domain" value="{{current_domain}}"/>
description: <input type="text" name="description" />
Select a file: <input type="file" name="upload" />
<input type="submit" value="Start upload" />
</form>
<h1>Create domain alias</h1>
<form action="/newAlias" method="post">
<input type="hidden" name="domain" value="{{current_domain}}"/>
description: <input type="text" name="description" />
<input type="submit" value="Create alias" />
</form>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment