Skip to content

Commit

Permalink
[AIRFLOW-4341] Remove View.render() already exists in fab.BaseView (#…
Browse files Browse the repository at this point in the history
…5125)

This behaviour is exactly what the fab.BaseView.render_template function
already does, and since that exists it makes more sense to use that than
define our own function

The two error handlers have been moved out of the class since even
though they _looked_ like they were instance methods they weren't: the
`self` argument was actually an error object.
  • Loading branch information
ashb committed Apr 18, 2019
1 parent 3331ca3 commit 15aa990
Showing 1 changed file with 47 additions and 51 deletions.
98 changes: 47 additions & 51 deletions airflow/www_rbac/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,25 @@ def get_date_time_num_runs_dag_runs_form_data(request, session, dag):
# BaseViews
######################################################################################

@app.errorhandler(404)
def circles(error):
return render_template(
'airflow/circles.html', hostname=socket.getfqdn()), 404


@app.errorhandler(500)
def show_traceback(error):
from airflow.utils import asciiart as ascii_
return render_template(
'airflow/traceback.html',
hostname=socket.getfqdn(),
nukular=ascii_.nukular,
info=traceback.format_exc()), 500


class AirflowBaseView(BaseView):
route_base = ''

def render(self, template, **context):
return render_template(template,
base_template=self.appbuilder.base_template,
appbuilder=self.appbuilder,
**context)


class Airflow(AirflowBaseView):
@expose('/health')
Expand Down Expand Up @@ -261,7 +270,7 @@ def get_int_arg(value, default=0):
auto_complete_data.add(row.dag_id)
auto_complete_data.add(row.owners)

return self.render(
return self.render_template(
'airflow/dags.html',
dags=dags,
hide_paused=hide_paused,
Expand Down Expand Up @@ -407,7 +416,7 @@ def code(self, session=None):
except IOError as e:
html_code = str(e)

return self.render(
return self.render_template(
'airflow/dag_code.html', html_code=html_code, dag=dag, title=dag_id,
root=request.args.get('root'),
demo_mode=conf.getboolean('webserver', 'demo_mode'))
Expand Down Expand Up @@ -438,24 +447,10 @@ def dag_details(self, session=None):
external_trigger=False
)

return self.render(
return self.render_template(
'airflow/dag_details.html',
dag=dag, title=title, root=root, states=states, State=State, active_runs=active_runs)

@app.errorhandler(404)
def circles(self):
return render_template(
'airflow/circles.html', hostname=socket.getfqdn()), 404

@app.errorhandler(500)
def show_traceback(self):
from airflow.utils import asciiart as ascii_
return render_template(
'airflow/traceback.html',
hostname=socket.getfqdn(),
nukular=ascii_.nukular,
info=traceback.format_exc()), 500

@expose('/pickle_info')
@has_access
def pickle_info(self):
Expand Down Expand Up @@ -500,7 +495,7 @@ def rendered(self):
html_dict[template_field] = (
"<pre><code>" + str(content) + "</pre></code>")

return self.render(
return self.render_template(
'airflow/ti_code.html',
html_dict=html_dict,
dag=dag,
Expand Down Expand Up @@ -610,7 +605,7 @@ def log(self, session=None):
num_logs += 1
logs = [''] * num_logs
root = request.args.get('root', '')
return self.render(
return self.render_template(
'airflow/ti_log.html',
logs=logs, dag=dag, title="Log by attempts",
dag_id=dag.dag_id, task_id=task_id,
Expand Down Expand Up @@ -685,7 +680,7 @@ def task(self):
dep_context=dep_context)]

title = "Task Instance Details"
return self.render(
return self.render_template(
'airflow/task.html',
task_attrs=task_attrs,
ti_attrs=ti_attrs,
Expand Down Expand Up @@ -733,7 +728,7 @@ def xcom(self, session=None):
attributes.append((xcom.key, xcom.value))

title = "XCom"
return self.render(
return self.render_template(
'airflow/xcom.html',
attributes=attributes,
task_id=task_id,
Expand Down Expand Up @@ -900,7 +895,7 @@ def _clear_dag_tis(self, dag, start_date, end_date, origin,
else:
details = "\n".join([str(t) for t in tis])

response = self.render(
response = self.render_template(
'airflow/confirm.html',
message=("Here's the list of task instances you are about "
"to clear:"),
Expand Down Expand Up @@ -1007,10 +1002,10 @@ def _mark_dagrun_state_as_failed(self, dag_id, execution_date, confirmed, origin
else:
details = '\n'.join([str(t) for t in new_dag_state])

response = self.render('airflow/confirm.html',
message=("Here's the list of task instances you are "
"about to mark as failed"),
details=details)
response = self.render_template(
'airflow/confirm.html',
message=("Here's the list of task instances you are about to mark as failed"),
details=details)

return response

Expand All @@ -1036,10 +1031,10 @@ def _mark_dagrun_state_as_success(self, dag_id, execution_date, confirmed, origi
else:
details = '\n'.join([str(t) for t in new_dag_state])

response = self.render('airflow/confirm.html',
message=("Here's the list of task instances you are "
"about to mark as success"),
details=details)
response = self.render_template(
'airflow/confirm.html',
message=("Here's the list of task instances you are about to mark as success"),
details=details)

return response

Expand Down Expand Up @@ -1102,10 +1097,10 @@ def _mark_task_instance_state(self, dag_id, task_id, origin, execution_date,

details = "\n".join([str(t) for t in to_be_altered])

response = self.render("airflow/confirm.html",
message=("Here's the list of task instances you are "
"about to mark as {}:".format(state)),
details=details)
response = self.render_template(
"airflow/confirm.html",
message=("Here's the list of task instances you are about to mark as {}:".format(state)),
details=details)

return response

Expand Down Expand Up @@ -1268,7 +1263,7 @@ def set_duration(tid):

form = DateTimeWithNumRunsForm(data={'base_date': max_date,
'num_runs': num_runs})
return self.render(
return self.render_template(
'airflow/tree.html',
operators=sorted(
list(set([op.__class__ for op in dag.tasks])),
Expand Down Expand Up @@ -1358,7 +1353,7 @@ class GraphForm(DateTimeWithNumRunsWithDagRunsForm):
doc_md = markdown.markdown(dag.doc_md) \
if hasattr(dag, 'doc_md') and dag.doc_md else ''

return self.render(
return self.render_template(
'airflow/graph.html',
dag=dag,
form=form,
Expand Down Expand Up @@ -1481,7 +1476,7 @@ def duration(self, session=None):
"$( document ).trigger('chartload')" +
cum_chart.htmlcontent[s_index:])

return self.render(
return self.render_template(
'airflow/duration_chart.html',
dag=dag,
demo_mode=conf.getboolean('webserver', 'demo_mode'),
Expand Down Expand Up @@ -1548,7 +1543,7 @@ def tries(self, session=None):

chart.buildcontent()

return self.render(
return self.render_template(
'airflow/chart.html',
dag=dag,
demo_mode=conf.getboolean('webserver', 'demo_mode'),
Expand Down Expand Up @@ -1627,7 +1622,7 @@ def landing_times(self, session=None):
form = DateTimeWithNumRunsForm(data={'base_date': max_date,
'num_runs': num_runs})
chart.buildcontent()
return self.render(
return self.render_template(
'airflow/chart.html',
dag=dag,
chart=chart.htmlcontent,
Expand Down Expand Up @@ -1765,7 +1760,7 @@ def gantt(self, session=None):

session.commit()

return self.render(
return self.render_template(
'airflow/gantt.html',
dag=dag,
execution_date=dttm.isoformat(),
Expand Down Expand Up @@ -1819,10 +1814,11 @@ def version(self):

# Render information
title = "Version Info"
return self.render('airflow/version.html',
title=title,
airflow_version=airflow_version,
git_version=git_version)
return self.render_template(
'airflow/version.html',
title=title,
airflow_version=airflow_version,
git_version=git_version)


class ConfigurationView(AirflowBaseView):
Expand Down Expand Up @@ -1856,7 +1852,7 @@ def conf(self):
lexers.IniLexer(), # Lexer call
HtmlFormatter(noclasses=True))
)
return self.render(
return self.render_template(
'airflow/config.html',
pre_subtitle=settings.HEADER + " v" + airflow.__version__,
code_html=code_html, title=title, subtitle=subtitle,
Expand Down

0 comments on commit 15aa990

Please sign in to comment.