admins can edit and remove links
This commit is contained in:
+16
-4
@@ -92,15 +92,27 @@ def serveCode(code):
|
|||||||
|
|
||||||
@app.route("/edit", methods=['GET', 'POST'])
|
@app.route("/edit", methods=['GET', 'POST'])
|
||||||
def edit():
|
def edit():
|
||||||
code = request.form.get("code")
|
code = request.form.get("code") if request.form.get("code") is not None else request.args.get("code")
|
||||||
print ("code: {}".format(code))
|
url = request.form.get("url")
|
||||||
|
|
||||||
if codeLink(code) is False:
|
if codeLink(code) is False:
|
||||||
return render_template('invalid.html', code=code)
|
return render_template('invalid.html', code=code)
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
if url==None:
|
||||||
|
return render_template('editlink.html', code=code, url=codeLink(code), admin=current_user.is_authenticated)
|
||||||
|
else:
|
||||||
|
if url=='remove':
|
||||||
|
url = ''
|
||||||
|
links[code]['url']=url
|
||||||
|
saveFile()
|
||||||
|
return render_template('message.html', message="Done Mr. Admin person")
|
||||||
|
else:
|
||||||
if codeLink(code) is not None:
|
if codeLink(code) is not None:
|
||||||
return render_template('cantedit.html', url=codeLink(code))
|
return render_template('cantedit.html', url=codeLink(code))
|
||||||
url = request.form.get("url")
|
|
||||||
if url is None:
|
if url is None:
|
||||||
return render_template('editlink.html', code=code)
|
return render_template('editlink.html', code=code, url='', admin=current_user.is_authenticated)
|
||||||
|
|
||||||
#Saving the link:
|
#Saving the link:
|
||||||
if url.lower().startswith('https://') is False and url.lower().startswith('http://') is False:
|
if url.lower().startswith('https://') is False and url.lower().startswith('http://') is False:
|
||||||
return render_template('message.html', message="Only http:// and https:// links alowed. Plz fix your link!")
|
return render_template('message.html', message="Only http:// and https:// links alowed. Plz fix your link!")
|
||||||
|
|||||||
+11
-2
@@ -1,12 +1,21 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action=/edit method="post">
|
<form action=/edit id="editform" method="post">
|
||||||
<input type="hidden" name="code" value="{{code}}" />
|
<input type="hidden" name="code" value="{{code}}" />
|
||||||
QR-code:<br />
|
QR-code:<br />
|
||||||
<input type="text" value="{{code}}" disabled /><br />
|
<input type="text" value="{{code}}" disabled /><br />
|
||||||
URL:<br />
|
URL:<br />
|
||||||
<input type="url" name="url" value=""/><br />
|
<input type="url" id="url" name="url" value="{{url}}"/><br />
|
||||||
<button type="submit" class="graybar" >Save</button>
|
<button type="submit" class="graybar" >Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% if admin == True %}
|
||||||
|
<button class="graybar" onclick="removeLink()">Remove link</button>
|
||||||
|
{% endif %}
|
||||||
|
<script>
|
||||||
|
function removeLink() {
|
||||||
|
document.getElementById("url").value = "";
|
||||||
|
document.getElementById("editform").submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
+2
-1
@@ -5,7 +5,8 @@
|
|||||||
{% for label in linklist %}
|
{% for label in linklist %}
|
||||||
<p>
|
<p>
|
||||||
<span class="code">{{label['code']}}</span>:
|
<span class="code">{{label['code']}}</span>:
|
||||||
<a href="/code/{{label['code']}}.png" class="linkonalist">Show QR</a> | <a href="/edit" class="linkonalist">Edit</a>
|
|
||||||
|
<a href="/code/{{label['code']}}.png" class="linkonalist">Show QR</a> | <a href="/edit?code={{label['code']}}" class="linkonalist">Edit</a>
|
||||||
<br />
|
<br />
|
||||||
<a href="{{label['url']}}" class="linkonalist">{{label['url']}}</a>
|
<a href="{{label['url']}}" class="linkonalist">{{label['url']}}</a>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
Reference in New Issue
Block a user