def createCalendar(): if request.method == 'POST': r = request.get_json() userId = current_user.getID() name = r['name'] colour = r['colour'] if (current_user.getCalendarByName(name) == None): newCalendar = Calendar(name, colour) current_user.addCalendar(newCalendar) PCM.addToUpdateQueue(userId, current_user, PCM.DBUpdate.DB_UPDATE_USER) return jsonify({"success": "True"}) return jsonify({"success": "False"})
def deleteCalendar(): if request.method == 'POST': r = request.get_json() name = r['name'] calendar = current_user.getCalendarByName(name) if calendar is not None: for event in calendar.getEvents(): PCM.deleteEvent(event.getID(), current_user.getID()) current_user.deleteCalendar(calendar) PCM.addToUpdateQueue(current_user.getID(), current_user, PCM.DBUpdate.DB_UPDATE_USER) return jsonify({"success": "True"}) return jsonify({"success": "False"})
def editCalendar(): if request.method == 'POST': r = request.get_json() oldName = r['oldName'] name = r['name'] colour = r['colour'] oldCalendar = current_user.getCalendarByName(oldName) if oldCalendar is not None: current_user.changeCalendarName(oldCalendar, name) current_user.changeCalendarColour(oldCalendar, colour) PCM.addToUpdateQueue(current_user.getID(), current_user, PCM.DBUpdate.DB_UPDATE_USER) for event in oldCalendar.getEvents(): PCM.addToUpdateQueue(current_user.getID(), event, PCM.DBUpdate.DB_UPDATE_EVENT, oldCalendar) return jsonify({"success": "True"}) return jsonify({"success": "False"})
def createEvent(): if request.method == 'POST': r = request.get_json() userId = current_user.getID() name = r['name'] desc = r['desc'] if 'desc' in r.keys() else '' if (len(r['startDate']) == 16): startDate = (r['startDate']) print("START DATE 16") elif (len(r['startDate']) == 24): startDate = (r['startDate'][:-8]) print("START DATE 24") else: print("f****d") if (len(r['endDate']) == 16): endDate = (r['endDate']) elif (len(r['endDate']) == 24): endDate = (r['endDate'][:-8]) cal = current_user.getCalendarByName(r['calendar']) category = r['category'] if 'category' in r.keys() else None invitees = None if 'invitees' in r: invitees = r['invitees'].split() groups = None if 'groups' in r: groups = r['groups'] if (cal != None): event = PCM.addEvent(userID=userId, title=name, description=desc, startDateTime=startDate, endDateTime=endDate, calendarName=cal.getName(), category=category, inviteeEmails=invitees) cal.addEvent(event) eventId = event.getID() return jsonify({"success": "True"}) return jsonify({"success": "False"})
def editEvent(): if request.method == 'POST': r = request.get_json() event = PCM.getEventByID(r['eventId']) if event is not None: if (event.getName() != r['name']): event.setName(r['name']) if event.getDescription() != r['desc']: event.setDescription(r['desc']) if event.getStartDateTime() != r['startDate']: if (len(r['startDate']) == 16): event.setStartDateTime(r['startDate']) print(event.getStartDateTime()) elif (len(r['startDate']) == 24): event.setStartDateTime(r['startDate'][:-8]) print(event.getStartDateTime()) if event.getEndDateTime() != r['endDate']: if (len(r['endDate']) == 16): event.setEndDateTime(r['endDate']) print(event.getEndDateTime()) elif (len(r['endDate']) == 24): event.setEndDateTime(r['endDate'][:-8]) print(event.getEndDateTime()) if event.getCategory() != r['category']: event.setCategory(r['category']) current_user.moveEvent(event, r['calendar']) PCM.addToUpdateQueue(current_user.getID(), event, PCM.DBUpdate.DB_UPDATE_EVENT, current_user.getCalendarByName(r['calendar'])) PCM.sendNotification(event.getID(), current_user.getID(), event.getInvitees(), Notification.NOTIF_EVENTCHANGE) print("edited") return jsonify({"success": "True"}) return jsonify({"success": "False"})