Example #1
0
def mark_exercise_by_email(email_token):

	date_exercise = DateHelper.get_yesterday()

	user = User.query.filter_by(email_exercise_token=email_token).first()

	if(user is None):
		flash('Operation not allowed')
		return abort(404)

	if user.alreadyDidExercise(date_exercise):
		flash('You already did exercise on this date: %s' % date_exercise)
		return redirect(url_for('index'))

	# create a new object to exercise
	exercise = Exercise(date_exercise, user.id)

	# insert the record in our db and commit it
	db.session.add(exercise)
	db.session.commit()

	# display a message to the user
	flash('Keep fitness and do it again tomorrow')

	return redirect(url_for('index'))
Example #2
0
def idid():
	form = IDidExerciseForm(request.form)

	# get the exercise date
	if(form.date_exercise_type.data == 'yesterday'):
		date_exercise = DateHelper.get_yesterday()
	else:
		date_exercise = DateHelper.string_to_date(form.date_exercise.data)

	if date_exercise > DateHelper.get_current_date().date():
		flash('Exercise date can not be newer than today')
		return render_template('exercises/i_did.html', form=form)

	if g.user.alreadyDidExercise(date_exercise):
		flash('You already did exercise on this date: %s' % date_exercise)
		return render_template('exercises/i_did.html', form=form)
	
	# create a new object to exercise
	exercise = Exercise(date_exercise, g.user.id)

	# insert the record in our db and commit it
	db.session.add(exercise)
	db.session.commit()

	# display a message to the user
	flash('Keep fitness and do it again tomorrow')

	# redirect user to the 'index' method of the user module
	return redirect(url_for('users.index'))
def get_all_users_want_receive_mail_notification():
	yesterday = DateHelper.get_yesterday()

	# get all users want to receive email notification
	# and didn't do exercise yesterday
	users = db.session.query(User)\
						.filter(User.receive_email_notification)\
						.filter(User.exercises.any(Exercise.date == yesterday) == False)\
						.all()
	return users