Skip to content

Commit

Permalink
Merge pull request #130 from mistercrunch/log_more
Browse files Browse the repository at this point in the history
Logging more
  • Loading branch information
mistercrunch committed Feb 10, 2016
2 parents 5e9096f + b1f88a5 commit 7b0c045
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
24 changes: 24 additions & 0 deletions panoramix/migrations/versions/430039611635_log_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""log more
Revision ID: 430039611635
Revises: d827694c7555
Create Date: 2016-02-10 08:47:28.950891
"""

# revision identifiers, used by Alembic.
revision = '430039611635'
down_revision = 'd827694c7555'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

def upgrade():
op.add_column('logs', sa.Column('dashboard_id', sa.Integer(), nullable=True))
op.add_column('logs', sa.Column('slice_id', sa.Integer(), nullable=True))


def downgrade():
op.drop_column('logs', 'slice_id')
op.drop_column('logs', 'dashboard_id')
3 changes: 3 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ class Log(Model):
id = Column(Integer, primary_key=True)
action = Column(String(512))
user_id = Column(Integer, ForeignKey('ab_user.id'))
dashboard_id = Column(Integer)
slice_id = Column(Integer)
user_id = Column(Integer, ForeignKey('ab_user.id'))
json = Column(Text)
user = relationship('User', backref='logs', foreign_keys=[user_id])
dttm = Column(DateTime, default=func.now())
Expand Down
8 changes: 5 additions & 3 deletions panoramix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,16 @@ def wrapper(*args, **kwargs):
if g.user:
user_id = g.user.id
from panoramix import models
d = request.args.to_dict()
d.update(kwargs)
log = models.Log(
action=f.__name__,
json=json.dumps(request.args.to_dict()),
json=json.dumps(d),
dashboard_id=d.get('dashboard_id'),
slice_id=d.get('slice_id'),
user_id=user_id)

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

return f(*args, **kwargs)
return wrapper

Expand Down
10 changes: 5 additions & 5 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,15 @@ def testconn(self):
mimetype="application/json")

@has_access
@expose("/dashboard/<identifier>/")
@expose("/dashboard/<dashboard_id>/")
@utils.log_this
def dashboard(self, identifier):
def dashboard(self, dashboard_id):
session = db.session()
qry = session.query(models.Dashboard)
if identifier.isdigit():
qry = qry.filter_by(id=int(identifier))
if dashboard_id.isdigit():
qry = qry.filter_by(id=int(dashboard_id))
else:
qry = qry.filter_by(slug=identifier)
qry = qry.filter_by(slug=dashboard_id)

templates = session.query(models.CssTemplate).all()

Expand Down

0 comments on commit 7b0c045

Please sign in to comment.