Large changes in the seperation of backend and google handler

- backend now takes care of all the recoloring, and communication with database
- google handler takes care of the entire communication with google
- colors selected on the front-end are now translated to the watch

- Calendars in the database now directly save the color the user has set
- only if the event has a different color than the calendar (event color from google is not 0)
  is the event color from google used.
- No more passing around of google color ids, hex colors all the way
This commit is contained in:
2020-05-30 23:05:46 +02:00
parent 98b09bb778
commit 70197ee393
5 changed files with 85 additions and 84 deletions

View File

@ -18,9 +18,9 @@ import requests
import server.googleHandler as google
from backend.Routine import Routine
from server import login_manager, app, db
from server.forms import LoginForm, RegistrationForm, DeviceForm
import backend
from database.models import User, Calendar, Device, GoogleToken
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
@ -36,7 +36,11 @@ def privacy():
@app.route("/account")
def index():
if current_user.is_authenticated:
google.updateCalendars()
gCalendars, colors, token = google.fetchCalendars()
current_user.google_token.token = token
db.session.commit()
backend.updateCalendars(current_user, gCalendars, colors)
return (flask.render_template('account.html',
username = current_user.username, email = current_user.email, profile_img=current_user.profile_pic
)
@ -79,7 +83,7 @@ def devices():
@app.route("/calendar")
@login_required
def calendar():
calendars = google.calendarsFromDb()
calendars = backend.calendarsFromDb(current_user)
return flask.render_template('calendar.html', calendars=calendars)
@app.route('/login/email', methods=['GET', 'POST'])
@ -177,14 +181,6 @@ def logout():
logout_user()
return redirect(url_for("index"))
def credentials_to_dict(credentials):
return {'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes}
@app.route("/device/<path:device>/calendarevents.json")
def downloader(device):
@ -199,12 +195,12 @@ def downloader(device):
db.session.commit()
request_user = db.session.query(User).filter(User.id==request_device.user_id).first()
routine = Routine()
# TODO add test if googke token exists
# if request_user.google_token != Null:
client_token = google.GC.build_credentials(request_user.google_token.token,
request_user.google_token.refresh_token)
calendarjson = routine.updateCalendar(request_user, client_token)
# TODO only pass along google calendars form user
startDate, endDate = backend.getTimeStamps()
events, colors = google.fetchCalendarEvents(request_user, request_user.calendars, startDate, endDate)
calendarjson = backend.generateJsonFromCalendarEntries(events, colors)
return jsonify(calendarjson)
@app.route("/devicefingerprint.json")