diff --git a/qr.py b/qr.py index f7c5bfb..34afa09 100644 --- a/qr.py +++ b/qr.py @@ -18,40 +18,41 @@ def codeValidation(code): def codeLink(code): global links if code not in links: - return None + return False if len(links[code]['url'])==0: return None return links[code]['url'] -@app.route("/create", methods=['GET', 'POST']) -def create(): - code = request.args.get("code") +@app.route("/edit", methods=['GET', 'POST']) +def edit(): + code = request.form.get("code") + print ("code: {}".format(code)) + if codeLink(code) is False: + return render_template('invalid.html', code=code) if codeLink(code) is not None: - return 'This link already points here: .'.format(codeLink(code)) - return "Creating a link for {}".format(request.args.get("")) + return render_template('cantedit.html', url=codeLink(code)) + url = request.form.get("url") + if url is None: + return render_template('editlink.html', code=code) + return render_template('success.html') + +@app.route("/admin", methods=['GET', 'POST']) +def admin(): + return render_template('admin.html') -@app.route("/list", methods=['GET', 'POST']) +@app.route("/list") def list(): - return 'Look at all my codes:' + return render_template('message.html', message='Comming soon!™') @app.route('/', defaults={'path': ''}) @app.route('/') def catch_all(path): if len(path)==0: - return landing_page(path) + return render_template('welcome.html') if path in links: if codeLink(path) is not None: return redirect(links[path]['url'], code=302) else: - return notfound(path) + return render_template('newcode.html', code=path) else: - return invalid(path) - -def landing_page(path): - return 'Hello, QR! You are here: {}'.format(path) - -def notfound(path): - return 'This is a new QR code. Click here to create a link for it'.format(path) - -def invalid(path): - return "Your code: {} is not valid. Please go away.".format(path) + return render_template('invalid.html', code=path) \ No newline at end of file diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..8fe76bc --- /dev/null +++ b/static/style.css @@ -0,0 +1,75 @@ +body { + background-color: #C5C5C3; + font-size: larger; + font-family: "Helvetica Neue", "Segoe UI", sans-serif; +} + +.outer-div +{ + padding: 30px; +} + +.floater +{ + margin: 0 auto; + width: 30rem; + padding: 20px; +} + +.content +{ + min-height: 8em; + background-color: white; +} + +.graybar /* Girl! I want to take you to a gray bar! */ +{ + background-color: #4B4B4B; + color: white!important; + font-size: x-large; + font-weight: 600; +} + +.code{ + color: #4B4B4B; + font-family: "Lucida Console", Monaco, monospace; + font-weight: 600; +} + +input{ + font-size: larger; + font-family: "Helvetica Neue", "Segoe UI", sans-serif; + background-color: white; + margin-bottom: 1em; + padding: 10px; + width: 100%; + box-sizing: border-box; +} + +button{ + padding: 20px; + width: 100%; + margin-top: 2em; + margin-bottom: 1em; +} + +a{ + color: #202222; + font-weight: 800; +} + +a:link { + text-decoration: none; +} + +a:visited { + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +a:active { + text-decoration: underline; +} \ No newline at end of file diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..b8ffef9 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} + +{% block content %} +

Welcome Mr. admin person.

+

This funcionality has not been implemented yet. Please return later

+{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..311070f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,17 @@ + + + + QR labels + + + +
+
+ QR-Labels +
+
+ {% block content %}{% endblock %} +
+
+ + \ No newline at end of file diff --git a/templates/cantedit.html b/templates/cantedit.html new file mode 100644 index 0000000..5f66538 --- /dev/null +++ b/templates/cantedit.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} + +{% block content %} +

This label already has this link attached to it:

+

{{url}}

+

Configured labels can not be modified.

+{% endblock %} \ No newline at end of file diff --git a/templates/editlink.html b/templates/editlink.html new file mode 100644 index 0000000..ed16532 --- /dev/null +++ b/templates/editlink.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +
+ +QR-code:
+
+URL:
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/templates/invalid.html b/templates/invalid.html new file mode 100644 index 0000000..405a296 --- /dev/null +++ b/templates/invalid.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} + +{% block content %} +

This label {{code}} is invalid!

+

Please go away!

+{% endblock %} \ No newline at end of file diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000..2781942 --- /dev/null +++ b/templates/message.html @@ -0,0 +1,5 @@ +{% extends 'base.html' %} + +{% block content %} +{{message}} +{% endblock %} \ No newline at end of file diff --git a/templates/newcode.html b/templates/newcode.html new file mode 100644 index 0000000..8407176 --- /dev/null +++ b/templates/newcode.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% block content %} +This is a new QR-Label. You can attach a link to it.
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/success.html b/templates/success.html new file mode 100644 index 0000000..625463c --- /dev/null +++ b/templates/success.html @@ -0,0 +1,5 @@ +{% extends 'base.html' %} + +{% block content %} +

Your link has successfully been attached!

+{% endblock %} \ No newline at end of file diff --git a/templates/welcome.html b/templates/welcome.html new file mode 100644 index 0000000..fcd85c4 --- /dev/null +++ b/templates/welcome.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} + +{% block content %} +

Welcome to the QR-Label system.

+

Scan any label using a standart QR reading app to follow the link attached to it. To create a new label, find a printed "blank" QR code from this system and scan it.

+

Note that once created, a label can not be modified. Unless you are an admin.

+{% endblock %} \ No newline at end of file