diff --git a/app.py b/app.py index 3c0f8fc..9fcf330 100644 --- a/app.py +++ b/app.py @@ -87,15 +87,10 @@ def get_google_provider_cfg(): return requests.get(GOOGLE_DISCOVERY_URL).json() class Calendar: - def __init__(self, name, toggle=0, color="#000000"): + def __init__(self, name, toggle='False', color="#000000"): self.name = name self.color = color - - if toggle == 0: - self.toggle = False - else: - self.toggle = True - + self.toggle=toggle def calendarsFromDb(): calendars = dbCalendar.getCalendars(current_user.id) pyCalendars = [] @@ -260,15 +255,14 @@ def downloader(user): @login_required def user(): if request.method == 'POST': - calId = request.json.get('calendar_id') + calName = request.json.get('calendar_id') color = request.json.get('color') toggle = request.json.get('toggle') - print(calId) if color != None: - print(color) + dbCalendar.updateCalendar(current_user.id, calName, color=color) if toggle != None: - print(toggle) + dbCalendar.updateCalendar(current_user.id, calName, toggle=toggle) # toggle specific calendar of user elif request.method == 'DELETE': # do nothing diff --git a/database/schema.sql b/database/schema.sql index 5846c52..9c23aee 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -9,6 +9,6 @@ CREATE TABLE calendar ( usr_id TEXT NOT NULL, calendar_id TEXT PRIMARY KEY, name TEXT NOT NULL, - toggle INT NOT NULL, + toggle TEXT, color TEXT ); diff --git a/database/user.py b/database/user.py index 4033423..bcc70bf 100644 --- a/database/user.py +++ b/database/user.py @@ -56,13 +56,33 @@ class dbCalendar(): def getCalendar(user_id, calendar_id): db = get_db() calendar = db.execute( - "SELECT * FROM calendar WHERE usr_id = ? AND calendar_id = ?", (user_id, calendar_id,) + "SELECT * FROM calendar WHERE usr_id = ? AND calendar_id = ?", (user_id, calendar_id) ).fetchone() + if not calendar: return None + + return calendar @staticmethod - def create(user_id, calendar_id, name, color, toggle = False): + def updateCalendar(user_id, calendar_name, toggle=None, color=None): + db = get_db() + print("updating") + if(toggle != None): + print(toggle) + db.execute( + "UPDATE calendar SET toggle = ? WHERE usr_id = ? AND name = ?", (toggle, user_id, calendar_name) + ) + db.commit() + + if(color != None): + db.execute( + "UPDATE calendar SET color = ? WHERE usr_id = ? AND name = ?", (color, user_id, calendar_name) + ) + db.commit() + + @staticmethod + def create(user_id, calendar_id, name, color, toggle = 'True'): db = get_db() db.execute( "INSERT INTO calendar (usr_id, calendar_id, name, toggle, color) " diff --git a/template/calendar.html b/template/calendar.html index cad847c..ad91a3b 100644 --- a/template/calendar.html +++ b/template/calendar.html @@ -17,8 +17,8 @@
@@ -37,7 +37,11 @@ {% endblock %} \ No newline at end of file