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.
This commit is contained in:
2020-04-14 20:11:34 +00:00
parent 53a1f201f8
commit 596f690cce
4 changed files with 147 additions and 39 deletions

49
app.py
View File

@ -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/<path:user>/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)