Exemple #1
0
def application(application_id):
    user = require_user()
    title = 'Your Application'
    conn = db.session.connection()
    application = conn.execute("""
        SELECT * FROM application
        WHERE id = %s
    """, (application_id,)).fetchone()
    if application is None:
        abort(404)
    if user.id != application['account_id'] and not user.is_admin:
        abort(404)
    monthly_stats = conn.execute("""
        SELECT
            date_trunc('month', date) AS month,
            sum(count_hits) + sum(count_nohits) AS lookups
        FROM stats_lookups
        WHERE application_id = %s
        GROUP BY date_trunc('month', date)
        ORDER BY date_trunc('month', date) DESC
    """, (application_id,)).fetchall()
    lookups = find_application_lookup_stats(conn, application_id)
    return render_template('application.html', title=title,
        app=application, monthly_stats=monthly_stats,
        lookups=lookups,
        lookups_json=json.dumps(prepare_chart_data(lookups)))
Exemple #2
0
def application(application_id):
    user = require_user()
    title = 'Your Application'
    conn = db.session.connection()
    application = conn.execute("""
        SELECT * FROM application
        WHERE id = %s
    """, (application_id,)).fetchone()
    if application is None:
        abort(404)
    if user.id != application['account_id'] and not user.is_admin:
        abort(404)
    monthly_stats = conn.execute("""
        SELECT
            date_trunc('month', date) AS month,
            sum(count_hits) + sum(count_nohits) AS lookups
        FROM stats_lookups
        WHERE application_id = %s
        GROUP BY date_trunc('month', date)
        ORDER BY date_trunc('month', date) DESC
    """, (application_id,)).fetchall()
    lookups = find_application_lookup_stats(conn, application_id)
    return render_template('application.html', title=title,
        app=application, monthly_stats=monthly_stats,
        lookups=lookups,
        lookups_json=json.dumps(prepare_chart_data(lookups)))
 def _handle_request(self, req):
     self.require_user(req)
     application_id = self.url_args['id']
     title = 'Your Application'
     application = self.conn.execute("""
         SELECT * FROM application
         WHERE id = %s
     """, (application_id,)).fetchone()
     if application is None:
         raise NotFound()
     if self.session['id'] != 3 and self.session['id'] != application['account_id']:
         raise Forbidden()
     monthly_stats = self.conn.execute("""
         SELECT
             date_trunc('month', date) AS month,
             sum(count_hits) + sum(count_nohits) AS lookups
         FROM stats_lookups
         WHERE application_id = %s
         GROUP BY date_trunc('month', date)
         ORDER BY date_trunc('month', date)
     """, (application_id,)).fetchall()
     lookups = find_application_lookup_stats(self.conn, application_id)
     return self.render_template('application.html', title=title,
         app=application, monthly_stats=monthly_stats, lookups=lookups)