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

feat: Add current_user variable and slugify filter to Jinja #1436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

baumandm
Copy link
Contributor

@baumandm baumandm commented Apr 11, 2024

This PR adds two new Jinja predefined variables, as well as a custom slugify filter using the python-slugify package.

  • {{ current_user }}: Renders the current user's username
  • {{ current_user_email }}: Renders the current user's email address
  • {{ ... | slugify }}: Transforms the input into a slugified version with underscores, stripping spaces, Unicode, and special characters. This is suitable for generating table / column names dynamically, among other uses.

This works both ad hoc and in scheduled Data Docs. I updated the Template Guide documentation, and added additional test cases.

Screenshot 2024-04-11 at 09-13-58 Additional Jinja Variables _ Filters - Querybook
Screenshot 2024-04-11 at 9 11 57 AM
Screenshot 2024-04-11 at 9 12 04 AM

@baumandm baumandm force-pushed the external/jinja-current-user branch from 3e3078c to 965c660 Compare April 11, 2024 14:39
Copy link
Collaborator

@czgu czgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, just small nits

@@ -315,7 +326,7 @@ def get_templated_query_variables(variables_provided, jinja_env):


def render_templated_query(
query: str, variables: Dict[str, str], engine_id: int, session=None
query: str, variables: Dict[str, str], engine_id: int, uid: int, session=None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query: str, variables: Dict[str, str], engine_id: int, uid: int, session=None
query: str, variables: Dict[str, str], engine_id: int, uid: Optional[int] = None, session=None

@@ -164,12 +168,19 @@ def get_latest_partition(
return get_latest_partition


def get_templated_query_env(engine_id: int, session=None):
def get_templated_query_env(engine_id: int, user: User, session=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_templated_query_env(engine_id: int, user: User, session=None):
def get_templated_query_env(engine_id: int, user: Optional[User], session=None):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants