-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
{% 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 #} | ||
<img src="{% if 'http' in tethys_app.icon %}{{ tethys_app.icon }}{% else %}{% static tethys_app.icon %}{% endif %}" /> | ||
{# The path you provided in your app.py is accessible through the tethys_app.icon context variable #} | ||
<img src="{% if 'http' in tethys_app.icon %}{{ tethys_app.icon }}{% else %}{% static tethys_app.icon %}{% endif %}" /> | ||
{% 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 %} | ||
<li class="nav-item title">App Navigation</li> | ||
<li class="nav-item active"><a class="nav-link" href="">Home</a></li> | ||
<li class="nav-item"><a class="nav-link" href="">Jobs</a></li> | ||
<li class="nav-item"><a class="nav-link" href="">Results</a></li> | ||
<li class="nav-item title">Steps</li> | ||
<li class="nav-item"><a class="nav-link" href="">1. The First Step</a></li> | ||
<li class="nav-item"><a class="nav-link" href="">2. The Second Step</a></li> | ||
<li class="nav-item"><a class="nav-link" href="">3. The Third Step</a></li> | ||
<li class="nav-item separator"></li> | ||
<li class="nav-item"><a class="nav-link" href="">Get Started</a></li> | ||
{% endblock %} | ||
|
||
{% block app_content %} | ||
{% endblock %} | ||
|
||
{% block app_actions %} | ||
{% endblock %} | ||
|
||
{% block content_dependent_styles %} | ||
{{ block.super }} | ||
<link href="{% static 'dask_tutorial/css/main.css' %}" rel="stylesheet"/> | ||
{{ block.super }} | ||
<link href="{% static 'dask_tutorial/css/main.css' %}" rel="stylesheet"/> | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
{{ block.super }} | ||
<script src="{% static 'dask_tutorial/js/main.js' %}" type="text/javascript"></script> | ||
{% endblock %} | ||
{{ block.super }} | ||
<script src="{% static 'dask_tutorial/js/main.js' %}" type="text/javascript"></script> | ||
{% endblock %} |
12 changes: 12 additions & 0 deletions
12
tethysapp/dask_tutorial/templates/dask_tutorial/error.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "dask_tutorial/base.html" %} | ||
{% load tethys_gizmos %} | ||
|
||
{% block app_content %} | ||
<div class="error-message"> | ||
{{ error_message }} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block app_actions %} | ||
{% gizmo jobs_button %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,6 @@ | ||
{% extends "dask_tutorial/base.html" %} | ||
{% load tethys_gizmos %} | ||
|
||
{% block header_buttons %} | ||
<div class="header-button glyphicon-button" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Help"> | ||
<a data-bs-toggle="modal" data-bs-target="#help-modal"><i class="bi bi-question-circle"></i></a> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block app_content %} | ||
<h1>Welcome to your Tethys App!</h1> | ||
<p>Take advantage of beautiful typography to organize the content of your app:</p> | ||
<h1>Heading 1</h1> | ||
<h2>Heading 2</h2> | ||
<h3>Heading 3</h3> | ||
<h4>Heading 4</h4> | ||
<h5>Heading 5</h5> | ||
<h6>Heading 6</h6> | ||
{% endblock %} | ||
|
||
{# Use the after_app_content block for modals #} | ||
{% block after_app_content %} | ||
<!-- Example Modal --> | ||
<div class="modal fade" id="help-modal" tabindex="-1" role="dialog" aria-labelledby="help-modal-label"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="help-modal-label">Example Modal</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<p>You can add custom buttons to the app header using the <code>header_buttons</code> block. Use anchor/link tags for the button and wrap it in a div with the class <code>header-button</code>. For buttons with the gliphyicons, add the <code>glyphicon-button</code> class as well.</p> | ||
<p>Ever have trouble using a modal in a Tethys app? Use the <code>after_app_content</code> block for modal content to allow them to function properly. See: <a href="https://getbootstrap.com/docs/5.1/components/modal/">Bootstrap Modals</a></p> | ||
<p>Add tooltips to any element by adding the <code>data-bs-toggle</code>, <code>data-bs-placement</code>, and <code>title</code> attributes to the button. See: <a href="https://getbootstrap.com/docs/5.1/components/tooltips/">Bootstrap Tooltips</a></p> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> | ||
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block app_actions %} | ||
{% gizmo save_button %} | ||
{% gizmo edit_button %} | ||
{% gizmo remove_button %} | ||
{% gizmo previous_button %} | ||
{% gizmo next_button %} | ||
{% endblock %} | ||
{% gizmo jobs_button %} | ||
{% endblock %} |
37 changes: 37 additions & 0 deletions
37
tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} | ||
<link rel="stylesheet" href="{% static 'tethys_gizmos/css/gizmo_showcase.css' %}" type="text/css" /> | ||
<style> | ||
#content { | ||
padding-bottom: 50px; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block app_content %} | ||
<div class="gizmo-page-wrapper"> | ||
<h2>Jobs Table</h2> | ||
{% gizmo jobs_table %} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block app_actions %} | ||
{% gizmo home_button %} | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
{% gizmo_dependencies css %} | ||
{{ block.super }} | ||
{% gizmo_dependencies js %} | ||
{% endblock %} |
Oops, something went wrong.