Пример #1
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'))
Пример #2
0
def get_all_months_as_dictionary():
	# get all months a user have done exercises
	all_months = db.session.query(label('year', extract('year', Exercise.date)), label('month', extract('month', Exercise.date)))\
						.group_by('year', 'month')\
						.order_by('year desc, month desc')\
						.filter(Exercise.user_id == g.user.id)\
						.all()

	# convert list result to list dates
	all_months_as_date = [DateHelper.string_to_date(('%i/%i/1' % (year, month))) for (year, month) in all_months]

	# convert list to dictionary
	return [(DateHelper.generate_id_by_month_year(item), 
			DateHelper.date_to_year_month_string(item)) 
			for item in all_months_as_date]