Make a proper front page
This commit is contained in:
parent
a39a5c3857
commit
242c9fbaed
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load joinsep %}
|
{% load joinsep %}
|
||||||
{% block outer_content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="grid-stack" id="grid-stack-main">
|
<div class="grid-stack" id="grid-stack-main">
|
||||||
<!-- <div class="grid-stack-item" gs-w="5" gs-h="14" gs-y="0" gs-x="1">
|
<!-- <div class="grid-stack-item" gs-w="5" gs-h="14" gs-y="0" gs-x="1">
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div> -->
|
</div> -->
|
||||||
<div class="grid-stack-item" gs-w="4" gs-h="25" gs-y="0" gs-x="6">
|
<!-- <div class="grid-stack-item" gs-w="4" gs-h="25" gs-y="0" gs-x="6">
|
||||||
<div class="grid-stack-item-content">
|
<div class="grid-stack-item-content">
|
||||||
<nav class="panel">
|
<nav class="panel">
|
||||||
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
</article>
|
</article>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var grid = GridStack.init({
|
var grid = GridStack.init({
|
||||||
|
@ -46,10 +46,15 @@
|
||||||
|
|
||||||
// a widget is ready to be loaded
|
// a widget is ready to be loaded
|
||||||
document.addEventListener('load-widget', function(event) {
|
document.addEventListener('load-widget', function(event) {
|
||||||
let container = htmx.find('#widget');
|
let containers = htmx.findAll('#widget');
|
||||||
|
console.log("CONTAINERS", containers);
|
||||||
|
for (let x = 0, len = containers.length; x < len; x++) {
|
||||||
|
container = containers[x];
|
||||||
|
console.log("CONTAINER", container);
|
||||||
// get the scripts, they won't be run on the new element so we need to eval them
|
// get the scripts, they won't be run on the new element so we need to eval them
|
||||||
var scripts = htmx.findAll(container, "script");
|
|
||||||
let widgetelement = container.firstElementChild.cloneNode(true);
|
let widgetelement = container.firstElementChild.cloneNode(true);
|
||||||
|
console.log(widgetelement);
|
||||||
|
var scripts = htmx.findAll(widgetelement, "script");
|
||||||
var new_id = widgetelement.id;
|
var new_id = widgetelement.id;
|
||||||
|
|
||||||
// check if there's an existing element like the one we want to swap
|
// check if there's an existing element like the one we want to swap
|
||||||
|
@ -67,6 +72,7 @@
|
||||||
}
|
}
|
||||||
// clear the queue element
|
// clear the queue element
|
||||||
container.outerHTML = "";
|
container.outerHTML = "";
|
||||||
|
// container.firstElementChild.outerHTML = "";
|
||||||
grid.addWidget(widgetelement);
|
grid.addWidget(widgetelement);
|
||||||
|
|
||||||
// re-create the HTMX JS listeners, otherwise HTMX won't work inside the grid
|
// re-create the HTMX JS listeners, otherwise HTMX won't work inside the grid
|
||||||
|
@ -91,12 +97,37 @@
|
||||||
for (var i = 0; i < scripts.length; i++) {
|
for (var i = 0; i < scripts.length; i++) {
|
||||||
eval(scripts[i].innerHTML);
|
eval(scripts[i].innerHTML);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// clear the containers we just added
|
||||||
|
// for (let x = 0, len = containers.length; x < len; x++) {
|
||||||
|
// container = containers[x];
|
||||||
|
// container.inner = "";
|
||||||
|
// }
|
||||||
|
grid.compact();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-get="{% url 'positions' type='widget' %}"
|
||||||
|
hx-target="#widgets-here"
|
||||||
|
hx-trigger="load"
|
||||||
|
hx-swap="afterend"
|
||||||
|
style="display: none;"></div>
|
||||||
|
<div
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-get="{% url 'strategies' type='widget' %}"
|
||||||
|
hx-target="#widgets-here"
|
||||||
|
hx-trigger="load"
|
||||||
|
hx-swap="afterend"
|
||||||
|
style="display: none;"></div>
|
||||||
<div
|
<div
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-get="{% url 'profit' type='widget' %}"
|
hx-get="{% url 'profit' type='widget' %}"
|
||||||
hx-target="#widgets-here"
|
hx-target="#widgets-here"
|
||||||
hx-trigger="load"></div>
|
hx-trigger="load"
|
||||||
|
hx-swap="afterend"
|
||||||
|
style="display: none;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="widget">
|
<div id="widget">
|
||||||
<div id="widget-{{ unique }}" class="grid-stack-item" {% block widget_options %}gs-w="5" gs-h="1" gs-y="0" gs-x="1"{% endblock %}>
|
<div id="widget-{{ unique }}" class="grid-stack-item" {% block widget_options %}{% if widget_options is None %}gs-w="6" gs-h="1" gs-y="7" gs-x="0"{% else %}{% autoescape off %}{{ widget_options }}{% endautoescape %}{% endif %}{% endblock %}>
|
||||||
<div class="grid-stack-item-content">
|
<div class="grid-stack-item-content">
|
||||||
|
|
||||||
<nav class="panel">
|
<nav class="panel">
|
||||||
|
|
|
@ -93,6 +93,7 @@ class Positions(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
"list_url": list_url,
|
"list_url": list_url,
|
||||||
"context_object_name_singular": self.context_object_name_singular,
|
"context_object_name_singular": self.context_object_name_singular,
|
||||||
"context_object_name": self.context_object_name,
|
"context_object_name": self.context_object_name,
|
||||||
|
"widget_options": 'gs-w="12" gs-h="1" gs-y="0" gs-x="0"',
|
||||||
}
|
}
|
||||||
# Return partials for HTMX
|
# Return partials for HTMX
|
||||||
if self.request.htmx:
|
if self.request.htmx:
|
||||||
|
|
|
@ -5,15 +5,15 @@ from django.http import HttpResponseBadRequest
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from rest_framework.parsers import FormParser
|
|
||||||
from two_factor.views.mixins import OTPRequiredMixin
|
from two_factor.views.mixins import OTPRequiredMixin
|
||||||
|
|
||||||
from core.exchanges import GenericAPIError
|
from core.exchanges import GenericAPIError
|
||||||
from core.models import Account, Trade
|
from core.models import Account
|
||||||
from core.util import logs
|
from core.util import logs
|
||||||
|
|
||||||
log = logs.get_logger(__name__)
|
log = logs.get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_profit(user):
|
def get_profit(user):
|
||||||
items = []
|
items = []
|
||||||
accounts = Account.objects.filter(user=user)
|
accounts = Account.objects.filter(user=user)
|
||||||
|
@ -21,12 +21,18 @@ def get_profit(user):
|
||||||
try:
|
try:
|
||||||
details = account.client.get_account()
|
details = account.client.get_account()
|
||||||
pl = details["pl"]
|
pl = details["pl"]
|
||||||
item = {"account": account, "pl": float(pl), "balance": details["balance"], "currency": details["currency"]}
|
item = {
|
||||||
|
"account": account,
|
||||||
|
"pl": float(pl),
|
||||||
|
"balance": details["balance"],
|
||||||
|
"currency": details["currency"],
|
||||||
|
}
|
||||||
items.append(item)
|
items.append(item)
|
||||||
except GenericAPIError:
|
except GenericAPIError:
|
||||||
continue
|
continue
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
class Profit(LoginRequiredMixin, OTPRequiredMixin, View):
|
class Profit(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
allowed_types = ["modal", "widget", "window", "page"]
|
allowed_types = ["modal", "widget", "window", "page"]
|
||||||
window_content = "window-content/objects.html"
|
window_content = "window-content/objects.html"
|
||||||
|
|
Loading…
Reference in New Issue