Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding macros current_user_id & current_username #2582

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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