Esempio n. 1
0
def index():
    days_left = np.abs((cfg.DT_STOP - DateUtil.now().date()).days)
    users = get_active_users()
    leaders = []
    if users:
        leaders.append(users[0])
        for user in users[1:]:
            if np.isclose(user.get_ydata()[-1], leaders[0].get_ydata()[-1]):
                leaders.append(user)
    return render_template('index.html',
                           title='Home',
                           image=get_image(),
                           days_left=days_left,
                           leaders=[l.get_user().first_name for l in leaders])
Esempio n. 2
0
def weigh_in():
    form = WeighInForm()
    #Shouldnt be possible
    if not current_user.is_authenticated:
        return redirect(url_for('index'))
    if form.validate_on_submit():
        email = current_user.email
        #Measurement wants a datetime, form only gives date
        date = form.timestamp.data
        #Form provides the date Easter Time Zone
        #Form doesnt provide a time
        #This is a work around
        #Get the time in the same TZ as the form
        time = DateUtil.now().time()
        #Now get the datetime object and convert it back to UTC
        dt = datetime.datetime.combine(date, time) - DateUtil.get_utc_offset()

        weight = form.weight.data

        measurement = Measurement(timestamp=dt, email=email, weight=weight)
        db.session.add(measurement)
        db.session.commit()
        return redirect(url_for('user', username=current_user.first_name))
    return render_template('weigh_in.html', title='Weigh In', form=form)