Пример #1
0
def by_day():
    form = DateForm()
    day = None

    if request.method == 'GET':
        lday = db.session.query(Kontrol.date).order_by(Kontrol.date.desc()).limit(1).scalar()
        day = day_interval(str(lday.date()))

    if request.method == 'POST':
        if form.validate():
            sday = request.form['date']
            day = day_interval(sday)

    entries = None
    if not day:
        flash(u'Ошибка в дате.', category="error")
    else:
        form.date.data = day[0]
        entries = db.session.query(Kontrol.id
                                   , Kontrol.date
                                   # , Kontrol.date2
                                   , func.timediff(Kontrol.date2, Kontrol.date).label("dt")
                                   , Kontrol.category
                                   , Kontrol.comment
                                   , Kontrol.message
                                   , Kontrol.object
                                   , Kontrol.obj_id
                                   , Kontrol.prim) \
            .filter(Kontrol.date > day[0]) \
            .filter(Kontrol.date < day[1]) \
            .filter(Kontrol.category!=2) \
            .order_by(Kontrol.date.desc()).all()
    return render_template('kontrol/kontrol_by_day.html', form=form, day=day, entries=entries)
Пример #2
0
def reports_last():
    form = DateForm()
    day = None
    if request.method == 'POST':
        if form.validate():
            sday = request.form['date']
            day = gt_tools.day_interval(sday)
        if not day:
            flash(u'Ошибка в дате. Показаны самые последние протоколы.', category="error")
        else:
            form.date.data = day[0]
    stmtO = db.session.query(Otcep.report_id.label('report_id'), func.count('*').label('otcep_count')). \
        group_by(Otcep.report_id).subquery()
    lst = db.session.query(Report, stmtO.c.otcep_count, Nsl). \
        outerjoin(stmtO, Report.id == stmtO.c.report_id). \
        outerjoin(Nsl, Report.id == Nsl.id)
    if day:
        lst = lst. \
            filter(Report.date > day[0]). \
            filter(Report.date < day[1]). \
            order_by(Report.date.desc()). \
            all()
    else:
        lst = lst. \
            order_by(Report.date.desc()). \
            limit(16).all()
    return render_template('reports/reports.html', form=form, day=day, entries=lst)