-
Notifications
You must be signed in to change notification settings - Fork 233
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
base: master
Are you sure you want to change the base?
Conversation
3e3078c
to
965c660
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
This PR adds two new Jinja predefined variables, as well as a custom
slugify
filter using thepython-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.