示例#1
0
def report_edit(reportid):
    report = getreport(reportid)
    if request.method == 'POST':
        name = request.form['name']
        sql = request.form['sql']
        template = request.form['template']
        template_headers = request.form['template_headers']
        defaults = request.form['defaults']
        if (name != report[1] or sql != report[2] or template != report[3] or template_headers != report[4] or defaults != report[5]):
            db = get_db()
            cur = db.cursor()
            cur.execute('UPDATE reports SET name = %s, sql = %s, template = %s, template_headers = %s, defaults=%s, last_modified=now() WHERE id = %s', [name, sql, template, template_headers, defaults, reportid])
            if cur.rowcount > 0:
                flash('Successfully updated!')
            else:
                flash('Something went wrong.')
            db.commit()
            cur.close()
            db.close()
        else:
            flash('No changes.')
        return redirect(url_for("report_edit", reportid=reportid))
    else:
        mbdb = get_mbdb()
        mbcur = mbdb.cursor()
        try:
            mbcur.execute('EXPLAIN ' + report[2], json.loads(report[5]))
            vals = mbcur.fetchall()
            error = None
        except Exception, e:
            vals = None
            error = str(e).decode('utf-8')
        finally:
示例#2
0
def getreplication():
    mbdb = get_mbdb()
    mbcur = mbdb.cursor(cursor_factory=psycopg2.extras.DictCursor)
    try:
        mbcur.execute("SELECT last_replication_date from replication_control")
        date = mbcur.fetchone()[0]
    except psycopg2.ProgrammingError, e:
        return None
示例#3
0
        rtime = 0

    key = "%s:%s" % (reportid, hashlib.sha256("|".join(["%s:%s" % (decode_if_str(k), decode_if_str(query_args[k])) for k in sorted(query_args.keys())])).hexdigest())
    prerendered = cache.get_multi([key], key_prefix='reportstool:')
    if not error and prerendered.get(key, False):
        app.logger.warning("Got %s from cache" % key)
        vals = prerendered.get(key)['vals']
        rtime = prerendered.get(key)['time'].replace(tzinfo=psycopg2.tz.FixedOffsetTimezone(0))
        if rtime < report[6] or rtime < last_repl_date:
            app.logger.warning("%s rtime of %s is less than either last-modified %s or replication date %s" % (key, rtime, report[6], last_repl_date))
            cache.delete_multi(key, key_prefix='reportstool:')
            vals = None
            rtime = 0

    if not error and not vals:
        mbdb = get_mbdb()
        mbcur = mbdb.cursor(cursor_factory=psycopg2.extras.DictCursor)
        try:
            query_args = json.loads(report[5])
            query_args.update(request.args.to_dict())
            mbcur.execute(report[2], query_args)
            vals = [runtemplate(report[3], row) for row in mbcur.fetchall()]
            rtime = datetime.datetime.utcnow()
            try:
                cache.set_multi({key: {'time': rtime, 'vals': vals}}, time=60*60, key_prefix='reportstool:', min_compress_len=10000)
                app.logger.warning("Set cache for key %s" % key)
            except: app.logger.warning("Couldn't set cache for key %s" % key) # hack since things >1mb fail on rika
        except Exception, e:
            vals = None
            error = str(e).decode('utf-8')
            rtime = 0