Code cleanup edit submit handler can be the same function
This commit is contained in:
@@ -113,12 +113,40 @@ def main_page():
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
@app.route("/edit", methods=['GET'])
|
@app.route("/edit", methods=['GET', 'POST'])
|
||||||
def edit_page():
|
def edit_page():
|
||||||
global messages
|
global messages
|
||||||
|
import validators
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
uuid = request.args.get('uuid')
|
||||||
|
|
||||||
|
url = request.form.get('url').strip()
|
||||||
|
tag = request.form.get('tag').strip()
|
||||||
|
|
||||||
|
form_headers = request.form.get('headers').strip().split("\n")
|
||||||
|
extra_headers = {}
|
||||||
|
if form_headers:
|
||||||
|
for header in form_headers:
|
||||||
|
if len(header):
|
||||||
|
parts = header.split(':', 1)
|
||||||
|
extra_headers.update({parts[0].strip(): parts[1].strip()})
|
||||||
|
|
||||||
|
validators.url(url) # @todo switch to prop/attr/observer
|
||||||
|
datastore.data['watching'][uuid].update({'url': url,
|
||||||
|
'tag': tag,
|
||||||
|
'headers': extra_headers})
|
||||||
|
datastore.needs_write = True
|
||||||
|
|
||||||
|
messages.append({'class': 'ok', 'message': 'Updated watch.'})
|
||||||
|
|
||||||
|
return redirect(url_for('main_page'))
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
uuid = request.args.get('uuid')
|
||||||
|
output = render_template("edit.html", uuid=uuid, watch=datastore.data['watching'][uuid], messages=messages)
|
||||||
|
|
||||||
uuid = request.args.get('uuid')
|
|
||||||
output = render_template("edit.html", uuid=uuid, watch=datastore.data['watching'][uuid], messages=messages)
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
@@ -264,35 +292,7 @@ def api_delete():
|
|||||||
return redirect(url_for('main_page'))
|
return redirect(url_for('main_page'))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/update", methods=['POST'])
|
|
||||||
def api_update():
|
|
||||||
global messages
|
|
||||||
import validators
|
|
||||||
|
|
||||||
uuid = request.args.get('uuid')
|
|
||||||
|
|
||||||
url = request.form.get('url').strip()
|
|
||||||
tag = request.form.get('tag').strip()
|
|
||||||
|
|
||||||
form_headers = request.form.get('headers').strip().split("\n")
|
|
||||||
extra_headers = {}
|
|
||||||
if form_headers:
|
|
||||||
for header in form_headers:
|
|
||||||
if len(header):
|
|
||||||
parts = header.split(':', 1)
|
|
||||||
extra_headers.update({parts[0].strip(): parts[1].strip()})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
validators.url(url) #@todo switch to prop/attr/observer
|
|
||||||
datastore.data['watching'][uuid].update({'url': url,
|
|
||||||
'tag': tag,
|
|
||||||
'headers':extra_headers})
|
|
||||||
datastore.needs_write = True
|
|
||||||
|
|
||||||
messages.append({'class': 'ok', 'message': 'Updated watch.'})
|
|
||||||
|
|
||||||
return redirect(url_for('main_page'))
|
|
||||||
|
|
||||||
@app.route("/api/checknow", methods=['GET'])
|
@app.route("/api/checknow", methods=['GET'])
|
||||||
def api_watch_checknow():
|
def api_watch_checknow():
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<div class="home-menu pure-menu pure-menu-horizontal pure-menu-fixed">
|
<div class="home-menu pure-menu pure-menu-horizontal pure-menu-fixed">
|
||||||
<a class="pure-menu-heading" href="/"><strong>Change</strong>Detection.io</a>
|
<a class="pure-menu-heading" href="/"><strong>Change</strong>Detection.io</a>
|
||||||
{% if current_diff_url %}
|
{% if current_diff_url %}
|
||||||
<a class=current-diff-url href="{{ current_diff_url }}">{{ current_diff_url }}</a>
|
<a class=current-diff-url href="{{ current_diff_url }}"><span style="max-width: 30%; overflow: hidden;">{{ current_diff_url }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<ul class="pure-menu-list">
|
<ul class="pure-menu-list">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<div class="edit-form">
|
<div class="edit-form">
|
||||||
|
|
||||||
|
|
||||||
<form class="pure-form pure-form-stacked" action="/api/update?uuid={{uuid}}" method="POST">
|
<form class="pure-form pure-form-stacked" action="/edit?uuid={{uuid}}" method="POST">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="url">URL</label>
|
<label for="url">URL</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user