Skip to content

Commit

Permalink
Adding macros current_user_id & current_username
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 10, 2017
1 parent 66bff01 commit b38bec3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions superset/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime, timedelta
import inspect
import random
import time
import uuid

from jinja2.sandbox import SandboxedEnvironment
from flask import request
from flask import request, g

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time
import uuid
import random

from superset import app

Expand Down Expand Up @@ -40,6 +41,16 @@ def url_param(param, default=None):
return request.args.get(param, default)


def current_user_id():
"""The id of the user who is currently logged in"""
return g.user.id


def current_username():
"""The username of the user who is currently logged in"""
return g.user.username


class BaseTemplateProcessor(object):

"""Base class for database-specific jinja context
Expand Down Expand Up @@ -67,6 +78,8 @@ def __init__(self, database=None, query=None, table=None, **kwargs):
self.schema = table.schema
self.context = {
'url_param': url_param,
'current_user_id': current_user_id,
'current_username': current_username,
}
self.context.update(kwargs)
self.context.update(BASE_CONTEXT)
Expand Down

0 comments on commit b38bec3

Please sign in to comment.