BasPH commented on a change in pull request #17451: URL: https://github.com/apache/airflow/pull/17451#discussion_r683673558
########## File path: docs/apache-airflow/templates-ref.rst ########## @@ -105,14 +105,35 @@ For example, you could use expressions in your templates like ``{{ conn.my_conn_ Just like with ``var`` it's possible to fetch a connection by string (e.g. ``{{ conn.get('my_conn_id_'+index).host }}`` ) or provide defaults (e.g ``{{ conn.get('my_conn_id', {"host": "host1", "login": "user1"}).host }}``) +Filters +------- + +Airflow defines the some Jinja filters that can be used to format values. + +For example, using ``{{ execution_date | ds }}`` will output the execution_date in the ``YYYY-MM-DD`` format. + +===================== ============ ================================================================== +Filter Operates on Description +===================== ============ ================================================================== +``ds`` datetime Format the datetime as ``YYYY-MM-DD`` +``ds_no_dash`` datetime Format the datetime as ``YYYYMMDD`` +``ts`` datetime Same as ``.isoformat()``, Example: ``2018-01-01T00:00:00+00:00`` +``ts_no_dash`` datetime Same as ``ts`` filter without ``-``, ``:`` or TimeZone info. + Example: ``20180101T000000`` +``ts_nodash_with_tz`` datetime As ``ts`` filter without ``-`` or ``:``. Example Review comment: Doesn't align with the filter name ```suggestion ``ts_no_dash_with_tz`` datetime As ``ts`` filter without ``-`` or ``:``. Example ``` ########## File path: airflow/templates.py ########## @@ -30,3 +35,32 @@ def is_safe_attribute(self, obj, attr, value): ``_``) whilst still blocking internal or truely private attributes (``__`` prefixed ones). """ return not jinja2.sandbox.is_internal_attribute(obj, attr) + + +def ds_filter(value): + return value.strftime('%Y-%m-%d') + + +def ds_nodash_filter(value): + return value.strftime('%Y%m%d') + + +def ts_filter(value): + return value.isoformat() + + +def ts_nodash_filter(value): + return value.strftime('%Y%m%dT%H%M%S') + + +def ts_nodash_with_tz_filter(value): + return value.isoformat().replace('-', '').replace(':', '') + + +FILTERS = { + 'ds': ds_filter, + 'ds_no_dash': ds_nodash_filter, + 'ts': ts_filter, + 'ts_no_dash': ts_nodash_filter, + 'ts_no_dash_with_tz': ts_nodash_with_tz_filter, Review comment: Bit nitpicky, but I think keeping the "no_dash" naming equal avoids any confusion. ```suggestion def ds_no_dash_filter(value): return value.strftime('%Y%m%d') def ts_filter(value): return value.isoformat() def ts_no_dash_filter(value): return value.strftime('%Y%m%dT%H%M%S') def ts_no_dash_with_tz_filter(value): return value.isoformat().replace('-', '').replace(':', '') FILTERS = { 'ds': ds_filter, 'ds_no_dash': ds_no_dash_filter, 'ts': ts_filter, 'ts_no_dash': ts_no_dash_filter, 'ts_no_dash_with_tz': ts_no_dash_with_tz_filter, ``` ########## File path: docs/apache-airflow/index.rst ########## @@ -110,7 +110,7 @@ unit of work and continuity. Operators and hooks <operators-and-hooks-ref> CLI <cli-and-env-variables-ref> - Macros <macros-ref> + Templates <templates-ref> Review comment: Why not name it something like "context" or "task context"? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org