Skip to content

Commit

Permalink
Adding macros current_user_id & current_username (#2582)
Browse files Browse the repository at this point in the history
* Adding macros current_user_id & current_username

* Addressing comments
  • Loading branch information
mistercrunch authored Apr 11, 2017
1 parent 5e4fca4 commit 493ba18
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 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,18 @@ 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"""
if g.user:
return g.user.id


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


class BaseTemplateProcessor(object):

"""Base class for database-specific jinja context
Expand Down Expand Up @@ -67,6 +80,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 493ba18

Please sign in to comment.