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
// Parameters ... | |
// Trigger: A click on a button with 'openModal' class | |
// Requires: modal-id as attribute on the button | |
// URL: fetched from the ajax-url attribute on the modal Content div | |
$(document).ready(function () { | |
// A function to run on the click event to open modal, and fetch form via GET AJAX request | |
$('.openModal').on('click', function () { | |
var modalID = $(this).attr("modal-id"); |
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
// Parameters ... | |
// Note this should be run AFTER the form has been loaded in order for the JS to attach to the form | |
// Trigger: Submission of the form | |
// Form: must have the class 'submitByAJAX' for this to work | |
// URL: fetched from the ajax-url attribute on the form object | |
$(".submitByAJAX").each(function () { | |
var form = $(this).find('form'); | |
form.submit(function (e) { | |
e.preventDefault(); |
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
// Post messages | |
function postSuccessMessage(message) { | |
html = ` | |
<div class="alert alert-success fade show"> | |
<button type="button" class="close" data-dismiss="alert">×</button>`+ message + `</div>` | |
$('#messages').append(html); | |
setTimeout(function () { | |
$(".alert").alert('close'); | |
}, 3000); | |
} |
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
// Add refresh app icon | |
function needsRefresh() { | |
$('#refresh').empty(); | |
html = ` | |
<button class="btn" data-toggle="tooltip" title="Click to refresh app"><i data-feather="refresh-cw" onclick="refresh();"></i></button> | |
` | |
$('#refresh').append(html); | |
$('[data-toggle="tooltip"]').tooltip() | |
feather.replace() | |
} |
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
<div class="modal fade" id="messageModal" tabindex="-1" role="dialog" aria-labelledby="messageModalLabel" aria-hidden="true"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title" id="messageModalLabel">Post a message</h5> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
<div class="modal-body"> |
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
<div class="submitByAJAX"> | |
<form method="POST" action="{% url 'message_new' %}"> | |
{% csrf_token %} | |
{{ form }} | |
<button type="submit" value="submit" class="btn">Submit</button> | |
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> | |
</form> | |
</div> |
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 VERSION - fully synchronous | |
import time | |
import random | |
import logging | |
logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.INFO) | |
def get_market_data(market): |
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
import time | |
from unsync import unsync | |
@unsync | |
def my_function(): | |
""" A function which we want to use asynchronously """ | |
time.sleep(1) | |
return "something fascinating" | |
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
# UNSYNC VERSION - this parallelises both the run methods and | |
# then the API and database call methods within each run | |
import time | |
import random | |
import logging | |
from unsync import unsync | |
logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.INFO) |
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
# Github Action to build Python package and run tests with Pytest | |
# Runs on creation of pull request into main branch | |
name: Tests | |
on: | |
pull_request: | |
branches: | |
- main |
OlderNewer