You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/01/09 22:16:44 UTC

[GitHub] feng-tao closed pull request #4401: [AIRFLOW-3596] Clean up undefined template variables.

feng-tao closed pull request #4401: [AIRFLOW-3596] Clean up undefined template variables.
URL: https://github.com/apache/airflow/pull/4401
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/www/templates/airflow/config.html b/airflow/www/templates/airflow/config.html
index a6f011d57c..89ad4fcd04 100644
--- a/airflow/www/templates/airflow/config.html
+++ b/airflow/www/templates/airflow/config.html
@@ -33,10 +33,6 @@ <h2>{{ title }}</h2>
         <h5>{{ subtitle }}</h5>
     {% endif %}
 
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
     {% if code_html %}
         {{ code_html|safe }}
     {% endif %}
diff --git a/airflow/www/templates/airflow/dag_code.html b/airflow/www/templates/airflow/dag_code.html
index 35f85b2f78..65d957356c 100644
--- a/airflow/www/templates/airflow/dag_code.html
+++ b/airflow/www/templates/airflow/dag_code.html
@@ -21,25 +21,7 @@
 {% block body %}
     {{ super() }}
     <h4>{{ title }}</h4>
-    {% if html_code %}
-        {{ html_code|safe }}
-    {% endif %}
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
-    {% if code_dict %}
-        {% for k, v in code_dict.items() %}
-            <h5>{{ k }}</h5>
-            <pre>{{ v }}</pre>
-        {% endfor %}
-    {% endif %}
-    {% if html_dict %}
-        {% for k, v in html_dict.items() %}
-            <h5>{{ k }}</h5>
-            {{ v|safe }}
-        {% endfor %}
-    {% endif %}
+    {{ html_code|safe }}
 {% endblock %}
 
 {% block tail %}
diff --git a/airflow/www/templates/airflow/dag_details.html b/airflow/www/templates/airflow/dag_details.html
index 4f9f2eb6ad..588e7ea582 100644
--- a/airflow/www/templates/airflow/dag_details.html
+++ b/airflow/www/templates/airflow/dag_details.html
@@ -42,7 +42,7 @@ <h2>{{ title }}</h2>
       </tr>
       <tr>
         <th>max_active_runs</td>
-        <td>{{ dag.active_runs | length }} / {{ dag.max_active_runs }}</td>
+        <td>{{ active_runs | length }} / {{ dag.max_active_runs }}</td>
       </tr>
       <tr>
         <th>concurrency</td>
diff --git a/airflow/www/templates/airflow/graph.html b/airflow/www/templates/airflow/graph.html
index 1fede359a6..44fc997e69 100644
--- a/airflow/www/templates/airflow/graph.html
+++ b/airflow/www/templates/airflow/graph.html
@@ -31,7 +31,7 @@
 
 {% block body %}
 {{ super() }}
-    {% if dag.doc_md %}
+    {% if doc_md %}
         <div class="rich_doc" style="margin-bottom: 15px;">{{ doc_md|safe }}</div>
     {% endif %}
     <div class="form-inline">
diff --git a/airflow/www/templates/airflow/task.html b/airflow/www/templates/airflow/task.html
index e45b745fb8..820a4a9814 100644
--- a/airflow/www/templates/airflow/task.html
+++ b/airflow/www/templates/airflow/task.html
@@ -37,7 +37,9 @@ <h5>Dependencies Blocking Task From Getting Scheduled</h5>
                 </tr>
             {% endfor %}
         </table>
-        {{ html_code|safe }}
+        {% if html_code is defined %}
+            {{ html_code|safe }}
+        {% endif %}
     </div>
     <div>
         {% for attr, value in special_attrs_rendered.items() %}
@@ -70,6 +72,8 @@ <h5>Task Attributes</h5>
                 </tr>
             {% endfor %}
         </table>
-        {{ html_code|safe }}
+        {% if html_code is defined %}
+            {{ html_code|safe }}
+        {% endif %}
     </div>
 {% endblock %}
diff --git a/airflow/www/templates/airflow/ti_code.html b/airflow/www/templates/airflow/ti_code.html
index 44942ca7d7..72008f0468 100644
--- a/airflow/www/templates/airflow/ti_code.html
+++ b/airflow/www/templates/airflow/ti_code.html
@@ -21,23 +21,8 @@
 {% block body %}
     {{ super() }}
     <h4>{{ title }}</h4>
-    {% if html_code %}
-        {{ html_code|safe }}
-    {% endif %}
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
-    {% if code_dict %}
-        {% for k, v in code_dict.items() %}
-            <h5>{{ k }}</h5>
-            <pre>{{ v }}</pre>
-        {% endfor %}
-    {% endif %}
-    {% if html_dict %}
-        {% for k, v in html_dict.items() %}
-            <h5>{{ k }}</h5>
-            {{ v|safe }}
-        {% endfor %}
-    {% endif %}
+    {% for k, v in html_dict.items() %}
+        <h5>{{ k }}</h5>
+        {{ v|safe }}
+    {% endfor %}
 {% endblock %}
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 642a63a2e2..8e7fddaa21 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -673,6 +673,7 @@ def dag_details(self, session=None):
         dag_id = request.args.get('dag_id')
         dag = dagbag.get_dag(dag_id)
         title = "DAG details"
+        root = request.args.get('root', '')
 
         TI = models.TaskInstance
         states = session\
@@ -681,9 +682,17 @@ def dag_details(self, session=None):
             .group_by(TI.state)\
             .all()
 
+        active_runs = models.DagRun.find(
+            dag_id=dag.dag_id,
+            state=State.RUNNING,
+            external_trigger=False,
+            session=session
+        )
+
         return self.render(
             'airflow/dag_details.html',
-            dag=dag, title=title, states=states, State=State)
+            dag=dag, title=title, root=root, states=states, State=State,
+            active_runs=active_runs)
 
     @current_app.errorhandler(404)
     def circles(self):
@@ -733,6 +742,7 @@ def rendered(self):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dag = dagbag.get_dag(dag_id)
         task = copy.copy(dag.get_task(task_id))
         ti = models.TaskInstance(task=task, execution_date=dttm)
@@ -757,7 +767,8 @@ def rendered(self):
             task_id=task_id,
             execution_date=execution_date,
             form=form,
-            title=title, )
+            root=root,
+            title=title)
 
     @expose('/get_logs_with_metadata')
     @login_required
@@ -836,11 +847,13 @@ def log(self, session=None):
             models.TaskInstance.execution_date == dttm).first()
 
         logs = [''] * (ti.next_try_number - 1 if ti is not None else 0)
+        root = request.args.get('root', '')
         return self.render(
             'airflow/ti_log.html',
             logs=logs, dag=dag, title="Log by attempts",
             dag_id=dag.dag_id, task_id=task_id,
-            execution_date=execution_date, form=form)
+            execution_date=execution_date, form=form,
+            root=root)
 
     @expose('/task')
     @login_required
@@ -855,6 +868,7 @@ def task(self):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dag = dagbag.get_dag(dag_id)
 
         if not dag or task_id not in dag.task_ids:
@@ -928,6 +942,7 @@ def task(self):
             execution_date=execution_date,
             special_attrs_rendered=special_attrs_rendered,
             form=form,
+            root=root,
             dag=dag, title=title)
 
     @expose('/xcom')
@@ -942,6 +957,7 @@ def xcom(self, session=None):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dm_db = models.DagModel
         ti_db = models.TaskInstance
         dag = session.query(dm_db).filter(dm_db.dag_id == dag_id).first()
@@ -969,6 +985,7 @@ def xcom(self, session=None):
             task_id=task_id,
             execution_date=execution_date,
             form=form,
+            root=root,
             dag=dag, title=title)
 
     @expose('/run')
diff --git a/airflow/www_rbac/app.py b/airflow/www_rbac/app.py
index 69b5acbd2b..e7f5a1e976 100644
--- a/airflow/www_rbac/app.py
+++ b/airflow/www_rbac/app.py
@@ -50,7 +50,6 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
     airflow_home_path = conf.get('core', 'AIRFLOW_HOME')
     webserver_config_path = airflow_home_path + '/webserver_config.py'
     app.config.from_pyfile(webserver_config_path, silent=True)
-    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     app.config['APP_NAME'] = app_name
     app.config['TESTING'] = testing
 
diff --git a/airflow/www_rbac/templates/airflow/config.html b/airflow/www_rbac/templates/airflow/config.html
index 501ef66ec1..a68c5a7aef 100644
--- a/airflow/www_rbac/templates/airflow/config.html
+++ b/airflow/www_rbac/templates/airflow/config.html
@@ -33,10 +33,6 @@ <h2>{{ title }}</h2>
         <h5>{{ subtitle }}</h5>
     {% endif %}
 
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
     {% if code_html %}
         {{ code_html|safe }}
     {% endif %}
diff --git a/airflow/www_rbac/templates/airflow/dag.html b/airflow/www_rbac/templates/airflow/dag.html
index ed545c09cf..cceb2dfaa7 100644
--- a/airflow/www_rbac/templates/airflow/dag.html
+++ b/airflow/www_rbac/templates/airflow/dag.html
@@ -469,7 +469,7 @@ <h4 class="modal-title" id="dagModalLabel">
     });
 
     $("#pause_resume").change(function() {
-      var dag_id =  $(this).attr('dag_id');
+      var dag_id = $(this).attr('dag_id');
       if ($(this).prop('checked')) {
         is_paused = 'true'
       } else {
@@ -479,9 +479,8 @@ <h4 class="modal-title" id="dagModalLabel">
       $.post(url);
     });
 
-    $('#btn_edit_dagrun').click(function(){
-      window.location = "{{ url_for('DagModelView.show', pk=id) }}";
-
+    $('#btn_edit_dagrun').click(function() {
+      window.location = "{{ url_for('DagModelView.show', pk=dag.dag_id) }}";
     });
 
   </script>
diff --git a/airflow/www_rbac/templates/airflow/dag_code.html b/airflow/www_rbac/templates/airflow/dag_code.html
index dfab08b0c0..cb66706352 100644
--- a/airflow/www_rbac/templates/airflow/dag_code.html
+++ b/airflow/www_rbac/templates/airflow/dag_code.html
@@ -21,25 +21,7 @@
 {% block content %}
     {{ super() }}
     <h4>{{ title }}</h4>
-    {% if html_code %}
-        {{ html_code|safe }}
-    {% endif %}
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
-    {% if code_dict %}
-        {% for k, v in code_dict.items() %}
-            <h5>{{ k }}</h5>
-            <pre>{{ v }}</pre>
-        {% endfor %}
-    {% endif %}
-    {% if html_dict %}
-        {% for k, v in html_dict.items() %}
-            <h5>{{ k }}</h5>
-            {{ v|safe }}
-        {% endfor %}
-    {% endif %}
+    {{ html_code|safe }}
 {% endblock %}
 
 {% block tail %}
diff --git a/airflow/www_rbac/templates/airflow/dag_details.html b/airflow/www_rbac/templates/airflow/dag_details.html
index dfd28bc1f8..b04456ba95 100644
--- a/airflow/www_rbac/templates/airflow/dag_details.html
+++ b/airflow/www_rbac/templates/airflow/dag_details.html
@@ -42,7 +42,7 @@ <h2>{{ title }}</h2>
       </tr>
       <tr>
         <th>max_active_runs</td>
-        <td>{{ dag.active_runs | length }} / {{ dag.max_active_runs }}</td>
+        <td>{{ active_runs | length }} / {{ dag.max_active_runs }}</td>
       </tr>
       <tr>
         <th>concurrency</td>
diff --git a/airflow/www_rbac/templates/airflow/dags.html b/airflow/www_rbac/templates/airflow/dags.html
index 64883ba0ed..4e3aa8df2f 100644
--- a/airflow/www_rbac/templates/airflow/dags.html
+++ b/airflow/www_rbac/templates/airflow/dags.html
@@ -78,8 +78,7 @@ <h2>DAGs</h2>
                 <!-- Column 2: Turn dag on/off -->
                 <td>
                   {% if dag_id in orm_dags %}
-                    {% set disabled = 'disabled' if view_only else None %}
-                    <input id="toggle-{{ dag_id }}" {{ disabled }} dag_id="{{ dag_id }}" type="checkbox" {{ "checked" if not orm_dags[dag_id].is_paused else "" }} data-toggle="toggle" data-size="mini" method="post">
+                    <input id="toggle-{{ dag_id }}" dag_id="{{ dag_id }}" type="checkbox" {{ "checked" if not orm_dags[dag_id].is_paused else "" }} data-toggle="toggle" data-size="mini" method="post">
                   {% endif %}
                 </td>
 
diff --git a/airflow/www_rbac/templates/airflow/graph.html b/airflow/www_rbac/templates/airflow/graph.html
index c73d2cbea7..629247980f 100644
--- a/airflow/www_rbac/templates/airflow/graph.html
+++ b/airflow/www_rbac/templates/airflow/graph.html
@@ -27,7 +27,7 @@
 
 {% block content %}
 {{ super() }}
-    {% if dag.doc_md %}
+    {% if doc_md %}
         <div class="rich_doc" style="margin-bottom: 15px;">{{ doc_md|safe }}</div>
     {% endif %}
     <div class="form-inline">
diff --git a/airflow/www_rbac/templates/airflow/task.html b/airflow/www_rbac/templates/airflow/task.html
index 6c843b28e3..2b4356f49e 100644
--- a/airflow/www_rbac/templates/airflow/task.html
+++ b/airflow/www_rbac/templates/airflow/task.html
@@ -37,7 +37,9 @@ <h5>Dependencies Blocking Task From Getting Scheduled</h5>
                 </tr>
             {% endfor %}
         </table>
-        {{ html_code|safe }}
+        {% if html_code is defined %}
+            {{ html_code|safe }}
+        {% endif %}
     </div>
     <div>
         {% for attr, value in special_attrs_rendered.items() %}
@@ -70,6 +72,8 @@ <h5>Task Attributes</h5>
                 </tr>
             {% endfor %}
         </table>
-        {{ html_code|safe }}
+        {% if html_code is defined %}
+            {{ html_code|safe }}
+        {% endif %}
     </div>
 {% endblock %}
diff --git a/airflow/www_rbac/templates/airflow/ti_code.html b/airflow/www_rbac/templates/airflow/ti_code.html
index d38eb7d6c9..8c7db0d9d4 100644
--- a/airflow/www_rbac/templates/airflow/ti_code.html
+++ b/airflow/www_rbac/templates/airflow/ti_code.html
@@ -21,23 +21,8 @@
 {% block content %}
     {{ super() }}
     <h4>{{ title }}</h4>
-    {% if html_code %}
-        {{ html_code|safe }}
-    {% endif %}
-    {% if code %}
-        <pre>{{ code }}</pre>
-    {% endif %}
-
-    {% if code_dict %}
-        {% for k, v in code_dict.items() %}
-            <h5>{{ k }}</h5>
-            <pre>{{ v }}</pre>
-        {% endfor %}
-    {% endif %}
-    {% if html_dict %}
-        {% for k, v in html_dict.items() %}
-            <h5>{{ k }}</h5>
-            {{ v|safe }}
-        {% endfor %}
-    {% endif %}
+    {% for k, v in html_dict.items() %}
+        <h5>{{ k }}</h5>
+        {{ v|safe }}
+    {% endfor %}
 {% endblock %}
diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py
index 42328279a3..975f187868 100644
--- a/airflow/www_rbac/views.py
+++ b/airflow/www_rbac/views.py
@@ -157,6 +157,10 @@ def index(self, session=None):
                                                       'hide_paused_dags_by_default')
         show_paused_arg = request.args.get('showPaused', 'None')
 
+        default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
+        num_runs = request.args.get('num_runs')
+        num_runs = int(num_runs) if num_runs else default_dag_run
+
         def get_int_arg(value, default=0):
             try:
                 return int(value)
@@ -271,7 +275,8 @@ def get_int_arg(value, default=0):
                                            search=arg_search_query,
                                            showPaused=not hide_paused),
             dag_ids_in_page=page_dag_ids,
-            auto_complete_data=auto_complete_data)
+            auto_complete_data=auto_complete_data,
+            num_runs=num_runs)
 
     @expose('/dag_stats')
     @has_access
@@ -414,6 +419,7 @@ def dag_details(self, session=None):
         dag_id = request.args.get('dag_id')
         dag = dagbag.get_dag(dag_id)
         title = "DAG details"
+        root = request.args.get('root', '')
 
         TI = models.TaskInstance
         states = (
@@ -422,9 +428,17 @@ def dag_details(self, session=None):
                    .group_by(TI.state)
                    .all()
         )
+
+        active_runs = models.DagRun.find(
+            dag_id=dag.dag_id,
+            state=State.RUNNING,
+            external_trigger=False,
+            session=session
+        )
+
         return self.render(
             'airflow/dag_details.html',
-            dag=dag, title=title, states=states, State=State)
+            dag=dag, title=title, root=root, states=states, State=State, active_runs=active_runs)
 
     @app.errorhandler(404)
     def circles(self):
@@ -465,6 +479,7 @@ def rendered(self):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dag = dagbag.get_dag(dag_id)
         task = copy.copy(dag.get_task(task_id))
         ti = models.TaskInstance(task=task, execution_date=dttm)
@@ -490,7 +505,8 @@ def rendered(self):
             task_id=task_id,
             execution_date=execution_date,
             form=form,
-            title=title, )
+            root=root,
+            title=title)
 
     @expose('/get_logs_with_metadata')
     @has_dag_access(can_dag_read=True)
@@ -571,11 +587,13 @@ def log(self, session=None):
             models.TaskInstance.execution_date == dttm).first()
 
         logs = [''] * (ti.next_try_number - 1 if ti is not None else 0)
+        root = request.args.get('root', '')
         return self.render(
             'airflow/ti_log.html',
             logs=logs, dag=dag, title="Log by attempts",
             dag_id=dag.dag_id, task_id=task_id,
-            execution_date=execution_date, form=form)
+            execution_date=execution_date, form=form,
+            root=root)
 
     @expose('/task')
     @has_dag_access(can_dag_read=True)
@@ -591,6 +609,7 @@ def task(self):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dag = dagbag.get_dag(dag_id)
 
         if not dag or task_id not in dag.task_ids:
@@ -653,6 +672,7 @@ def task(self):
             execution_date=execution_date,
             special_attrs_rendered=special_attrs_rendered,
             form=form,
+            root=root,
             dag=dag, title=title)
 
     @expose('/xcom')
@@ -668,6 +688,7 @@ def xcom(self, session=None):
         execution_date = request.args.get('execution_date')
         dttm = pendulum.parse(execution_date)
         form = DateTimeForm(data={'execution_date': dttm})
+        root = request.args.get('root', '')
         dm_db = models.DagModel
         ti_db = models.TaskInstance
         dag = session.query(dm_db).filter(dm_db.dag_id == dag_id).first()
@@ -696,6 +717,7 @@ def xcom(self, session=None):
             task_id=task_id,
             execution_date=execution_date,
             form=form,
+            root=root,
             dag=dag, title=title)
 
     @expose('/run')


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services