def create_calendar(): """Instantiate calendar and generate associated workout instances""" title = request.form.get('title') cal = Calendar(user_id=session.get('user_id'), title=title) db.session.add(cal) db.session.commit() # instantiated calendar does not have columns for start-end dates -> # a workout w/ datetime values is generated for each day in the user specified ran start_date = request.form.get('schedule-start') start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d") end_date = request.form.get('schedule-end') end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d") day_range = (end_date - start_date).days + 1 for n in range(day_range): # gets day n days from the start date curr_start = start_date + datetime.timedelta(n) # gets the day of the week of the current start as 'mon', 'tue' etc -> # these match the column names for base_workout weekday_str = datetime.datetime.strftime(curr_start, '%a').lower() base_workouts = BaseWorkout.get_by_weekday(session.get('user_id'), weekday_str) # gets all base workouts for a user where the day of the week is true # chooses one baseworkout to generate a workout from if base_workouts: base_workout = random.choice(base_workouts) generate_calendar_workout(base_workout, cal, curr_start) return redirect('/')
def load_calendar(): """Load a calendar into database.""" calendar = Calendar(title="Fall Season", user_id=1) db.session.add(calendar) db.session.commit()
def __init__(self, uid, uRank, nprocs): self.lamportClock = 0 self.uid = uid self.theCalendar = Calendar(uid) self.tt = [[0 for j in range(nprocs)] for i in range(nprocs)] self.log = [] self.uRank = uRank self.nprocs = nprocs
def newcalendar(): # Standard conditions to check if the user has proper right to acces the page *** if DEBUG: pdb.set_trace() user = User.query.filter( User.ext_id_hashed == session.get('profile_ext_id_hashed')).first() if user is None: session.clear() return redirect(url_for('index')) elif user.account_status == 0: return render_template( "message.html", message= "Please wait for admin approval. Contact an admin if needed.", avatar_url=user.avatar_url) elif user.account_type != 2: return render_template( "message.html", message="You do not have proper right to access this site. " "Please contact an admin if needed.", avatar_url=user.avatar_url) # End of conditions ****************************** calendar_action = request.values.get('calendar_action', '') if calendar_action: new_name = request.values.get('new_name', '') calendar_id = request.values.get('calendar_id', '') if calendar_action == "add": try: calendar = Calendar(name=new_name) db.session.add(calendar) db.session.commit() except Exception: db.session.rollback() if calendar_action == "rename": try: calendar = Calendar.query.filter( Calendar.id == calendar_id).first() calendar.name = new_name db.session.commit() except Exception: db.session.rollback() if calendar_action == "delete": if calendar_id != 1: try: calendar = Calendar.query.filter( Calendar.id == calendar_id).first() vacation_data = Holiday.query.filter( Holiday.calendar_id == calendar_id).all() for vacation in vacation_data: db.session.delete(vacation) db.session.delete(calendar) db.session.commit() except Exception: db.session.rollback() # elif calendar_action == "cancel": # The default return function is enough return redirect("/calendars") return render_template("newcalendar.html", user=user, calendar=None)
def seed_calendars(calendarsResult, user_id): calendars = calendarsResult.get('items', []) for calendar in calendars: calendar_id = calendar['id'].lower() timezone = calendar['timeZone'] summary = calendar['summary'] etag = calendar['etag'] if 'primary' in calendar: primary = calendar['primary'] else: primary = False if 'selected' in calendar: selected = calendar['selected'] else: selected = False cal_exists = Calendar.query.get(calendar_id) usercal_exists = UserCal.query.filter_by( user_id=user_id, calendar_id=calendar_id).first() if cal_exists and usercal_exists is None: usercal = UserCal(user_id=user_id, calendar_id=calendar_id, primary=primary, selected=selected) db.session.add(usercal) db.session.commit() elif cal_exists is None: calendar_obj = Calendar(calendar_id=calendar_id, etag=etag, summary=summary, timezone=timezone) db.session.add(calendar_obj) db.session.commit() usercal = UserCal(user_id=user_id, calendar_id=calendar_id, primary=primary, selected=selected) db.session.add(usercal) db.session.commit() return calendar_id
def create_calendar(calendar_url): new_calendar = Calendar(url=calendar_url) db.session.add(new_calendar) db.session.commit()