Example #1
0
def make_navlinks(daily_report):
    ts = daily_report.report_date
    first = DailyReport.first()
    last = DailyReport.last()
        
    prev = DailyReport.query.filter(
        DailyReport.report_date < ts).order_by(
        DailyReport.report_date.desc()).first()
        
    next = DailyReport.query.filter(
        DailyReport.report_date > ts).order_by(
        DailyReport.report_date.asc()).first()

    return {'first': first, 'last': last,
            'prev': prev, 'next': next}
Example #2
0
def conditional_fetch(report_date, refetch=False):
    daily_report = DailyReport.query.filter(
        DailyReport.report_date == report_date).first()

    if daily_report is None:
        daily_report = DailyReport(report_date=report_date)
        db.session.add(daily_report)
    if daily_report.report_html is None or refetch:
        try:
            daily_report.report_html = fetch_daily_report(
                report_date.strftime("%Y-%m-%d")).encode('utf-8')
            daily_report.fetch_timestamp = datetime.utcnow()
        except (URLError, ReportFetchError, ReportNotFoundError):
            raise
        db.session.commit()

    return daily_report.report_html