From 596f690cceb67c18b9e650c6a022629b2bf9af0d Mon Sep 17 00:00:00 2001 From: raphael Date: Tue, 14 Apr 2020 20:11:34 +0000 Subject: [PATCH] adds sending toggle (true, false) information; adds color picker and sending that information back to server - the color picker is from 'colorPick' which makes implementation easy. It's only a .js and a .css file which need to be included and the color-picker is simple enough to handle on the client side. The only main problem with it, is that accessing the 'id' information of the css it was called from is not straightforward - the toggle switch which is just implemented in .css currently has the checklist inverted, works but ugly - The Client sends this information back to the server via a json file, which defines the calendar id and either color or the toggle information. The server currently just prints this information.great stuff. --- app.py | 49 +++++++++++----- database/sqlite_db | Bin 16384 -> 16384 bytes template/calendar.html | 123 ++++++++++++++++++++++++++++++++--------- template/sidebar.html | 14 ++++- 4 files changed, 147 insertions(+), 39 deletions(-) diff --git a/app.py b/app.py index cb8eafb..fc6a3ef 100644 --- a/app.py +++ b/app.py @@ -90,6 +90,7 @@ class Calendar: self.color = color @app.route("/calendar") +@login_required def calendar(): ca1 = Calendar("Hightower", "#30ff30") ca2 = Calendar("Toast", "#66e230") @@ -97,10 +98,6 @@ def calendar(): return flask.render_template('calendar.html', calendars=calendars) - - - - @app.route('/test') def test_api_request(): if 'credentials' not in flask.session: @@ -117,7 +114,9 @@ def test_api_request(): # ACTION ITEM: In a production app, you likely want to save these # credentials in a persistent database instead. flask.session['credentials'] = credentials_to_dict(credentials) - + + with open('./userinfo/' + current_user.id + '/calendarevents.json', 'w') as outfile: + json.dump(todaysCal, outfile) return flask.jsonify(todaysCal) @app.route("/login/google") @@ -141,13 +140,11 @@ def login(): # Create flow instance to manage the OAuth 2.0 Authorization Grant Flow steps. flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file( CLIENT_SECRETS_FILE, scopes=SCOPES) - # The URI created here must exactly match one of the authorized redirect URIs # for the OAuth 2.0 client, which you configured in the API Console. If this # value doesn't match an authorized URI, you will get a 'redirect_uri_mismatch' # error. flow.redirect_uri = request.base_url + "/callback" - authorization_url, state = flow.authorization_url( # Enable offline access so that you can refresh an access token without # re-prompting the user for permission. Recommended for web server apps. @@ -183,7 +180,7 @@ def callback(): session = flow.authorized_session() userinfo = session.get('https://www.googleapis.com/userinfo/v2/me').json() - + # Create a user in your db with the information provided # by Google user = User( @@ -200,7 +197,7 @@ def callback(): # Begin user session by logging the user in login_user(user) return flask.redirect(flask.url_for('index')) - + @app.route("/logout") @login_required def logout(): @@ -216,14 +213,40 @@ def credentials_to_dict(credentials): 'scopes': credentials.scopes} -@app.route("/userinfo/107971745944668140075/calendarevents.json") -def downloader(): - path = "/home/raphael/dev/website_ws/website/login/userinfo/107971745944668140075" +@app.route("/userinfo//calendarevents.json") +def downloader(user): + print(user) + path = "/home/raphael/dev/website_ws/website/userinfo/" + user return flask.send_from_directory(path, "calendarevents.json") +# POST + +@app.route('/calendar', methods = ['POST', 'DELETE']) +@login_required +def user(): + if request.method == 'POST': + calId = request.json.get('calendar_id') + color = request.json.get('color') + toggle = request.json.get('toggle') + + print(calId) + if color != None: + print(color) + if toggle != None: + print(toggle) + # toggle specific calendar of user + elif request.method == 'DELETE': + # do nothing + return 'NONE' + else: + # POST Error 405 + print("405") + + return 'OK' + if __name__ == "__main__": context = ('certificate/xip.io.crt', 'certificate/xip.io.key')#certificate and key files - app.run('192.168.68.103.xip.io', 1234, ssl_context=context, debug=True) + app.run('0.0.0.0', 1234, ssl_context=context, debug=True) diff --git a/database/sqlite_db b/database/sqlite_db index 01e423b46e6125e06cc1e8f2d00ce3825c7a5551..0f1b7dfe7fbad1a0e848ecf16eb509e6987b4d9b 100644 GIT binary patch delta 501 zcmZo@U~Fh$oFL7}GEv5vk!54T5`HdbK3xX>Jigm}x*Hqi`RW_Bnc2)0jT?&%4Ghdo z3=PZ;O%2T~%`A-!49ra|vr6-_GxHKl@{2M-%#zgP42SgG#LOJMl9GaAD}DW( z3{$=I{QUHs)Y9VAqU8L%lGMBskOF;OBjZw!fXdJ!OK%f>M>z0AudCw0Wz{l` z&C3l!{GyEA0}|7MOv_zD3NDg2Z3} p#pLJuvOu9%4E(R4Le^rU%!Zsrdbx?Ic{!;L>A8uSIeN+Yxd7d{99{qb diff --git a/template/calendar.html b/template/calendar.html index d0de596..288bdaf 100644 --- a/template/calendar.html +++ b/template/calendar.html @@ -1,35 +1,108 @@ {% extends "sidebar.html" %} {% block body%} + +
+
Calendar
+
Show on device
+
Color
+
+
-
Calendar
-
Show on device
-
Color
-
- -
{% for item in calendars %} -
{{ item.name }}
+
+ +
{{ item.name }}
-
- - -
+ +
+ + +
-
-
- - + +
+
+ +
+
- -
- {% endfor %} - +
+ + + {% endblock %} \ No newline at end of file diff --git a/template/sidebar.html b/template/sidebar.html index e2791ec..2d8fc66 100644 --- a/template/sidebar.html +++ b/template/sidebar.html @@ -6,10 +6,19 @@ + + + + + + + Index + +
View @@ -20,12 +29,15 @@
- + {% block body %} // content here {% endblock %}
+ + +