예제 #1
0
def logs_create(vehicle_id):
    form = LogForm(request.form)

    if not form.validate():
        flash("Please, check your input!", category="warning")
        return render_template("logs/new.html",
                               form=form,
                               vehicle_id=vehicle_id)

    log_type = form.log_type.data
    odometer = form.odometer.data

    last_log = Log.query.filter_by(vehicle_id=vehicle_id).order_by(
        Log.odometer.desc()).first()
    last_odo = last_log.odometer

    if last_odo > odometer:
        flash("Check odometer reading. (Must be greater or equal than last.)",
              category="warning")
        return render_template("logs/new.html",
                               form=form,
                               vehicle_id=vehicle_id,
                               last_odo=last_odo)

    driver_id = current_user.id

    l = Log(log_type, odometer, driver_id, vehicle_id)
    l.cost = form.cost.data
    l.details = form.details.data

    db.session().add(l)
    db.session().commit()

    return redirect(url_for("vehicles_index"))
예제 #2
0
def logs_course_user(course_id, user_id):
    logs = Log.find_logs_of_course(course_id, user_id)
    duration = Log.total_workhours(course_id, user_id)
    course = Course.query.get(course_id)
    user = User.query.get(user_id)

    return render_template("logs/list.html",
                           course=course,
                           course_id=course_id,
                           logs=logs,
                           duration=duration,
                           student=user)
예제 #3
0
def logs_index_desc(course_id):
    logs = Log.find_logs_of_course_desc(course_id, current_user.id)
    duration = Log.total_workhours(course_id, current_user.id)

    if not duration:
        duration = 0

    course = Course.query.get(course_id)

    return render_template("logs/list.html",
                           course=course,
                           course_id=course_id,
                           logs=logs,
                           duration=round(duration, 1),
                           desc=True)
예제 #4
0
def logs_create(course_id):
    form = LogForm(request.form)

    if not form.validate():
        return render_template("/logs/new.html",
                               form=form,
                               course_id=course_id)

    log = Log(form.description.data, form.duration.data)
    log.user_id = current_user.id
    log.course_id = course_id

    db.session().add(log)
    db.session().commit()

    return redirect(url_for("logs_index", course_id=course_id))
예제 #5
0
def index():
    if not current_user.is_authenticated:
        return render_template("index.html")

    user = User.query.get(current_user.id)
    name = user.firstname + ' ' + user.lastname

    if user.is_student():
        courses = Log.fetch_five_most_recent_courses_with_activity()
        return render_template("index.html", name = name, courses = courses)

    if user.is_teacher():
        courses = Course.fetch_five_most_recent_courses()
        return render_template("index.html", name = name, courses = courses)

    return render_template("index.html")
예제 #6
0
def logs_all():
    active_courses = Log.fetch_students_courses_with_progress()
    inactive_courses = Course.fetch_users_courses_without_logs()
    return render_template("logs/logs.html",
                           active_courses=active_courses,
                           inactive_courses=inactive_courses)