From b7c4dcbcdc880fc0d18f65e356471837447b5d12 Mon Sep 17 00:00:00 2001 From: Nathan Swain Date: Sun, 22 May 2022 00:44:27 -0600 Subject: [PATCH] Create setup views solution branch --- tethysapp/dask_tutorial/app.py | 2 +- tethysapp/dask_tutorial/controllers.py | 142 ++++++++++++------ tethysapp/dask_tutorial/job_functions.py | 26 ++++ .../dask_tutorial/public/images/dask-logo.png | Bin 0 -> 4398 bytes .../templates/dask_tutorial/base.html | 29 +--- .../templates/dask_tutorial/error.html | 12 ++ .../templates/dask_tutorial/home.html | 49 +----- .../templates/dask_tutorial/jobs_table.html | 37 +++++ .../templates/dask_tutorial/results.html | 38 +++++ 9 files changed, 217 insertions(+), 118 deletions(-) create mode 100644 tethysapp/dask_tutorial/job_functions.py create mode 100644 tethysapp/dask_tutorial/public/images/dask-logo.png create mode 100644 tethysapp/dask_tutorial/templates/dask_tutorial/error.html create mode 100644 tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html create mode 100644 tethysapp/dask_tutorial/templates/dask_tutorial/results.html diff --git a/tethysapp/dask_tutorial/app.py b/tethysapp/dask_tutorial/app.py index 963dd6c..ff6eb0a 100644 --- a/tethysapp/dask_tutorial/app.py +++ b/tethysapp/dask_tutorial/app.py @@ -11,7 +11,7 @@ class DaskTutorial(TethysAppBase): description = '' package = 'dask_tutorial' # WARNING: Do not change this value index = 'home' - icon = f'{package}/images/icon.gif' + icon = f'{package}/images/dask-logo.png' root_url = 'dask-tutorial' color = '#CA4D34' tags = '' diff --git a/tethysapp/dask_tutorial/controllers.py b/tethysapp/dask_tutorial/controllers.py index 5d38de1..c8d39f2 100644 --- a/tethysapp/dask_tutorial/controllers.py +++ b/tethysapp/dask_tutorial/controllers.py @@ -1,74 +1,118 @@ -from django.shortcuts import render +import random +from django.shortcuts import render, reverse, redirect from tethys_sdk.routing import controller +from django.http.response import HttpResponseRedirect +from django.contrib import messages from tethys_sdk.gizmos import Button +from tethys_sdk.gizmos import JobsTable +from tethys_compute.models.dask.dask_job_exception import DaskJobException +from tethysapp.dask_tutorial.app import DaskTutorial as app + +# get job manager for the app +job_manager = app.get_job_manager() + @controller def home(request): """ Controller for the app home page. """ - save_button = Button( - display_text='', - name='save-button', - icon='save', - style='success', + + jobs_button = Button( + display_text='Show All Jobs', + name='dask_button', attributes={ - 'data-bs-toggle':'tooltip', - 'data-bs-placement':'top', - 'title':'Save' - } + 'data-bs-toggle': 'tooltip', + 'data-bs-placement': 'top', + 'title': 'Show All Jobs' + }, + href=reverse('dask_tutorial:jobs_table') ) - edit_button = Button( - display_text='', - name='edit-button', - icon='pen', - style='warning', - attributes={ - 'data-bs-toggle':'tooltip', - 'data-bs-placement':'top', - 'title':'Edit' - } + context = { + 'jobs_button': jobs_button + } + + return render(request, 'dask_tutorial/home.html', context) + + +@controller +def jobs_table(request): + # Use job manager to get all the jobs. + jobs = job_manager.list_jobs(order_by='-id', filters=None) + + # Table View + jobs_table_options = JobsTable( + jobs=jobs, + column_fields=('id', 'name', 'description', 'creation_time'), + hover=True, + striped=False, + bordered=False, + condensed=False, + actions=['logs', 'delete'], + results_url='dask_tutorial:result', + refresh_interval=1000, + show_detailed_status=True, ) - remove_button = Button( - display_text='', - name='remove-button', - icon='trash', - style='danger', + home_button = Button( + display_text='Home', + name='home_button', attributes={ - 'data-bs-toggle':'tooltip', - 'data-bs-placement':'top', - 'title':'Remove' - } + 'data-bs-toggle': 'tooltip', + 'data-bs-placement': 'top', + 'title': 'Home' + }, + href=reverse('dask_tutorial:home') ) - previous_button = Button( - display_text='Previous', - name='previous-button', + context = {'jobs_table': jobs_table_options, 'home_button': home_button} + + return render(request, 'dask_tutorial/jobs_table.html', context) + + +@controller +def result(request, job_id): + # Use job manager to get the given job. + job = job_manager.get_job(job_id=job_id) + + # Get result and name + job_result = job.result + name = job.name + + home_button = Button( + display_text='Home', + name='home_button', attributes={ - 'data-bs-toggle':'tooltip', - 'data-bs-placement':'top', - 'title':'Previous' - } + 'data-bs-toggle': 'tooltip', + 'data-bs-placement': 'top', + 'title': 'Home' + }, + href=reverse('dask_tutorial:home') ) - next_button = Button( - display_text='Next', - name='next-button', + jobs_button = Button( + display_text='Show All Jobs', + name='dask_button', attributes={ - 'data-bs-toggle':'tooltip', - 'data-bs-placement':'top', - 'title':'Next' - } + 'data-bs-toggle': 'tooltip', + 'data-bs-placement': 'top', + 'title': 'Show All Jobs' + }, + href=reverse('dask_tutorial:jobs_table') ) context = { - 'save_button': save_button, - 'edit_button': edit_button, - 'remove_button': remove_button, - 'previous_button': previous_button, - 'next_button': next_button + 'result': job_result, + 'name': name, + 'home_button': home_button, + 'jobs_button': jobs_button } - return render(request, 'dask_tutorial/home.html', context) \ No newline at end of file + return render(request, 'dask_tutorial/results.html', context) + + +@controller +def error_message(request): + messages.add_message(request, messages.ERROR, 'Invalid Scheduler!') + return redirect(reverse('dask_tutorial:home')) diff --git a/tethysapp/dask_tutorial/job_functions.py b/tethysapp/dask_tutorial/job_functions.py new file mode 100644 index 0000000..17294d4 --- /dev/null +++ b/tethysapp/dask_tutorial/job_functions.py @@ -0,0 +1,26 @@ +import time +import dask + + +def inc(x): + time.sleep(3) + return x + 1 + + +def double(x): + time.sleep(3) + return x + 2 + + +def add(x, y): + time.sleep(10) + return x + y + + +def sum_up(x): + time.sleep(5) + return sum(x) + + +def convert_to_dollar_sign(result): + return '$' + str(result) diff --git a/tethysapp/dask_tutorial/public/images/dask-logo.png b/tethysapp/dask_tutorial/public/images/dask-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..2e98b5c06eaea8d7bf6fbb65496383b808c52bf4 GIT binary patch literal 4398 zcmZvgRag^_*T+G+rV>5Y^|2?=Qsks3WZMyIsYs3Ax?x`cruj1fN=-IAMh zj0UCL>)m_vzc}Z6uFi9w^F2486R)SM!9dGSOF}}z@KRIN;GZu3i*;(UfBE*2(+mj- zDX*UP8#N-4IQmX@+(B`t(rwIEe!@v}%Q0%FKL>Z4;}5%%c9Cz7dh?G4>sE_Gms8$f5^xJK?`B}uE4fh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9%i9!h^)tF+IvQptcn!rdd{U_s(zj;vo(i5v*Ki ztmfzRp#l`KO#XE}pPT@3{{Cu}-~PeGG}pw{H2(>(d^bM$y{U zwduSS=Pr122%=y`bC)x?Bb>e>xO~Aqpy5fgcO^fco~9Ub&b4v(39j$UgTK%)(1CR6fwb(V!{_{i+$f@{5< zHloaSFr}{ULZU8gEP7W2{?QlBmK*4oUQ~C%avP*l`1@YGTKcdd^fEQ@oM_pbLP6z! zB5^j^cHsKPnlxpFDROLM@x~iD?F;8DcFa9JDlWQf?X<+im}TxrH$M9!L+;zhN7ZlK z?{!@)^q8;HsU>_8`EVaEgQ@ZAFw`H>88-?H);Ye=^$l@NsO>j|oYv$K7nrRQffE<^ m4SiVtH&OpTY>$OpD(c08M6O$nQvUrxNM5Sxs@5vMi~K*s7^J!Y literal 0 HcmV?d00001 diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/base.html b/tethysapp/dask_tutorial/templates/dask_tutorial/base.html index 90486ee..7ba1b8e 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/base.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/base.html @@ -1,30 +1,17 @@ -{% extends "tethys_apps/app_base.html" %} +{% extends "tethys_apps/app_no_nav.html" %} {% load static %} {% block title %}{{ tethys_app.name }}{% endblock %} {% block app_icon %} - {# The path you provided in your app.py is accessible through the tethys_app.icon context variable #} - +{# The path you provided in your app.py is accessible through the tethys_app.icon context variable #} + {% endblock %} {# The name you provided in your app.py is accessible through the tethys_app.name context variable #} {% block app_title %}{{ tethys_app.name }}{% endblock %} -{% block app_navigation_items %} - - - - - - - - - - -{% endblock %} - {% block app_content %} {% endblock %} @@ -32,11 +19,11 @@ {% endblock %} {% block content_dependent_styles %} - {{ block.super }} - +{{ block.super }} + {% endblock %} {% block scripts %} - {{ block.super }} - -{% endblock %} \ No newline at end of file +{{ block.super }} + +{% endblock %} diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/error.html b/tethysapp/dask_tutorial/templates/dask_tutorial/error.html new file mode 100644 index 0000000..f416e6a --- /dev/null +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/error.html @@ -0,0 +1,12 @@ +{% extends "dask_tutorial/base.html" %} +{% load tethys_gizmos %} + +{% block app_content %} +
+ {{ error_message }} +
+{% endblock %} + +{% block app_actions %} +{% gizmo jobs_button %} +{% endblock %} diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/home.html b/tethysapp/dask_tutorial/templates/dask_tutorial/home.html index 4499aa5..0f567da 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/home.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/home.html @@ -1,51 +1,6 @@ {% extends "dask_tutorial/base.html" %} {% load tethys_gizmos %} -{% block header_buttons %} -
- -
-{% endblock %} - -{% block app_content %} -

Welcome to your Tethys App!

-

Take advantage of beautiful typography to organize the content of your app:

-

Heading 1

-

Heading 2

-

Heading 3

-

Heading 4

-
Heading 5
-
Heading 6
-{% endblock %} - -{# Use the after_app_content block for modals #} -{% block after_app_content %} - - -{% endblock %} - {% block app_actions %} - {% gizmo save_button %} - {% gizmo edit_button %} - {% gizmo remove_button %} - {% gizmo previous_button %} - {% gizmo next_button %} -{% endblock %} \ No newline at end of file +{% gizmo jobs_button %} +{% endblock %} diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html b/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html new file mode 100644 index 0000000..66b8c1a --- /dev/null +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html @@ -0,0 +1,37 @@ +{% extends "dask_tutorial/base.html" %} +{% load static tethys_gizmos %} + +{% load tethys_gizmos %} + +{% block global_scripts %} + {{ block.super }} + {% gizmo_dependencies global_js %} +{% endblock %} + +{% block styles %} + {{ block.super }} + {% gizmo_dependencies global_css %} + + +{% endblock %} + +{% block app_content %} +
+

Jobs Table

+ {% gizmo jobs_table %} +
+{% endblock %} + +{% block app_actions %} +{% gizmo home_button %} +{% endblock %} + +{% block scripts %} +{% gizmo_dependencies css %} + {{ block.super }} +{% gizmo_dependencies js %} +{% endblock %} diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/results.html b/tethysapp/dask_tutorial/templates/dask_tutorial/results.html new file mode 100644 index 0000000..910cb9b --- /dev/null +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/results.html @@ -0,0 +1,38 @@ +{% extends "dask_tutorial/base.html" %} +{% load static tethys_gizmos %} + +{% load tethys_gizmos %} + +{% block title %}- Gizmos - Map View{% endblock %} + +{% block global_scripts %} + {{ block.super }} + {% gizmo_dependencies global_js %} +{% endblock %} + +{% block styles %} + {{ block.super }} + {% gizmo_dependencies global_css %} + + +{% endblock %} + +{% block app_content %} +
  • The result of running {{ name }} job is : {{ result }}
  • + +{% endblock %} + +{% block app_actions %} +{% gizmo home_button %} +{% gizmo jobs_button %} +{% endblock %} + +{% block scripts %} +{% gizmo_dependencies css %} + {{ block.super }} +{% gizmo_dependencies js %} +{% endblock %}