-
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
2 changed files
with
44 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,50 @@ | ||
import random | ||
import string | ||
|
||
from django.shortcuts import render | ||
from tethys_sdk.routing import controller | ||
from tethys_sdk.gizmos import Button | ||
|
||
from tethys_sdk.gizmos import * | ||
from .app import GeoserverApp as app | ||
|
||
|
||
WORKSPACE = 'geoserver_app' | ||
GEOSERVER_URI = 'http://www.example.com/geoserver-app' | ||
|
||
|
||
@controller | ||
def home(request): | ||
""" | ||
Controller for the app home page. | ||
""" | ||
save_button = Button( | ||
display_text='', | ||
name='save-button', | ||
icon='save', | ||
style='success', | ||
attributes={ | ||
'data-bs-toggle':'tooltip', | ||
'data-bs-placement':'top', | ||
'title':'Save' | ||
} | ||
) | ||
# Retrieve a geoserver engine | ||
geoserver_engine = app.get_spatial_dataset_service(name='main_geoserver', as_engine=True) | ||
|
||
# Check for workspace and create workspace for app if it doesn't exist | ||
response = geoserver_engine.list_workspaces() | ||
|
||
edit_button = Button( | ||
display_text='', | ||
name='edit-button', | ||
icon='pen', | ||
style='warning', | ||
attributes={ | ||
'data-bs-toggle':'tooltip', | ||
'data-bs-placement':'top', | ||
'title':'Edit' | ||
} | ||
) | ||
if response['success']: | ||
workspaces = response['result'] | ||
|
||
remove_button = Button( | ||
display_text='', | ||
name='remove-button', | ||
icon='trash', | ||
style='danger', | ||
attributes={ | ||
'data-bs-toggle':'tooltip', | ||
'data-bs-placement':'top', | ||
'title':'Remove' | ||
} | ||
) | ||
if WORKSPACE not in workspaces: | ||
geoserver_engine.create_workspace(workspace_id=WORKSPACE, uri=GEOSERVER_URI) | ||
|
||
previous_button = Button( | ||
display_text='Previous', | ||
name='previous-button', | ||
attributes={ | ||
'data-bs-toggle':'tooltip', | ||
'data-bs-placement':'top', | ||
'title':'Previous' | ||
} | ||
) | ||
# Case where the form has been submitted | ||
if request.POST and 'submit' in request.POST: | ||
# Verify files are included with the form | ||
if request.FILES and 'files' in request.FILES: | ||
# Get a list of the files | ||
file_list = request.FILES.getlist('files') | ||
|
||
next_button = Button( | ||
display_text='Next', | ||
name='next-button', | ||
attributes={ | ||
'data-bs-toggle':'tooltip', | ||
'data-bs-placement':'top', | ||
'title':'Next' | ||
} | ||
) | ||
# Upload shapefile | ||
store = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(6)) | ||
store_id = WORKSPACE + ':' + store | ||
geoserver_engine.create_shapefile_resource( | ||
store_id=store_id, | ||
shapefile_upload=file_list, | ||
overwrite=True | ||
) | ||
|
||
context = { | ||
'save_button': save_button, | ||
'edit_button': edit_button, | ||
'remove_button': remove_button, | ||
'previous_button': previous_button, | ||
'next_button': next_button | ||
} | ||
context = {} | ||
|
||
return render(request, 'geoserver_app/home.html', context) | ||
return render(request, 'geoserver_app/home.html', context) |
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,13 @@ | ||
{% extends "geoserver_app/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> | ||
<h1>Upload a Shapefile</h1> | ||
<form action="" method="post" enctype="multipart/form-data">. | ||
{% csrf_token %} | ||
<div class="mb-3"> | ||
<label for="fileInput" class="form-label">Shapefiles</label> | ||
<input name="files" type="file" multiple class="form-control" id="fileInput" placeholder="Shapefiles"> | ||
</div> | ||
</div> | ||
<input name="submit" type="submit" class="btn btn-secondary"> | ||
</form> | ||
{% endblock %} | ||
|
||
{% block app_actions %} | ||
{% gizmo save_button %} | ||
{% gizmo edit_button %} | ||
{% gizmo remove_button %} | ||
{% gizmo previous_button %} | ||
{% gizmo next_button %} | ||
{% endblock %} |