Simplify DB object management with Django CRUD helpers

This commit is contained in:
2022-10-29 12:43:13 +01:00
parent 8f705e2f25
commit c685b6d25f
26 changed files with 435 additions and 936 deletions

View File

@@ -10,7 +10,7 @@
<th>sandbox</th>
<th>actions</th>
</thead>
{% for item in items %}
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.user }}</td>
@@ -32,7 +32,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'account_action' type=type account_id=item.id %}"
hx-get="{% url 'account_update' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
@@ -44,9 +44,10 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'account_action' type=type account_id=item.id %}"
hx-delete="{% url 'account_delete' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#accounts-table"
hx-target="#modals-here"
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
class="button is-danger">
<span class="icon-text">
<span class="icon">
@@ -55,7 +56,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'account_info' type=type account_id=item.id %}"><button
<a href="{% url 'account_info' type=type pk=item.id %}"><button
class="button is-success">
<span class="icon-text">
<span class="icon">
@@ -67,7 +68,7 @@
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'account_info' type=type account_id=item.id %}"
hx-get="{% url 'account_info' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-success">

View File

@@ -1,5 +1,4 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of received callbacks</h1>
<table class="table is-fullwidth is-hoverable" id="callbacks-table">
<thead>
@@ -17,14 +16,14 @@
<th>contract</th>
<th>actions</th>
</thead>
{% for item in items %}
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.hook.id }}</td>
<td>
<a
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'hook_action' type=type hook_id=item.hook.id %}"
hx-get="{% url 'hook_update' type=type pk=item.hook.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here">{{ item.hook.name }}
</a>

View File

@@ -10,7 +10,7 @@
<th>received hooks</th>
<th>actions</th>
</thead>
{% for item in items %}
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.user }}</td>
@@ -22,7 +22,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'hook_action' type=type hook_id=item.id %}"
hx-get="{% url 'hook_update' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
@@ -34,9 +34,10 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'hook_action' type=type hook_id=item.id %}"
hx-delete="{% url 'hook_delete' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#hooks-table"
hx-target="#modals-here"
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
class="button is-danger">
<span class="icon-text">
<span class="icon">
@@ -45,7 +46,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'callbacks' type='page' hook_id=item.id %}"><button
<a href="{% url 'callbacks' type='page' pk=item.id %}"><button
class="button is-success">
<span class="icon-text">
<span class="icon">
@@ -57,7 +58,7 @@
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'callbacks' type=type hook_id=item.id %}"
hx-get="{% url 'callbacks' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-success">

View File

@@ -41,7 +41,8 @@
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="#trade-close-confirm"
hx-trigger="click"
hx-target="#accounts-table"
hx-target="#positions-table"
hx-confirm="Are you sure you wish to close {{ item.symbol }}?"
class="button is-danger">
<span class="icon-text">
<span class="icon">

View File

@@ -11,7 +11,7 @@
<th>SL</th>
<th>actions</th>
</thead>
{% for item in items %}
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
@@ -34,7 +34,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-get="{% url 'strategy_update' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
@@ -46,9 +46,10 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-delete="{% url 'strategy_delete' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#strategies-table"
hx-target="#modals-here"
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
class="button is-danger">
<span class="icon-text">
<span class="icon">
@@ -57,7 +58,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'strategies_action' type=type strategy_id=item.id %}"><button
<a href="#"><button
class="button is-success">
<span class="icon-text">
<span class="icon">
@@ -69,7 +70,7 @@
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-get="#"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-success">

View File

@@ -13,7 +13,7 @@
<th>TL</th>
<th>actions</th>
</thead>
{% for item in items %}
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.status }}</td>
@@ -28,7 +28,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'trade_action' type=type trade_id=item.id %}"
hx-get="{% url 'trade_update' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
@@ -40,9 +40,9 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'trade_action' type=type trade_id=item.id %}"
hx-delete="{% url 'trade_delete' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#trades-table"
hx-target="#modals-here"
class="button is-danger">
<span class="icon-text">
<span class="icon">

View File

@@ -1,21 +0,0 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of accounts</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'account_action' type=type %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Account</span>
</span>
</button>
</div>
{% include 'partials/account-list.html' %}

View File

@@ -1,31 +0,0 @@
{% include 'partials/notify.html' %}
{% load crispy_forms_tags %}
{% load crispy_forms_bulma_field %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if account_id is not None %}
hx-put="{% url 'account_action' type=type account_id=account_id %}"
{% else %}
hx-put="{% url 'account_action' type=type %}"
{% endif %}
hx-target="#accounts-table"
hx-swap="outerHTML">
{% csrf_token %}
{{ form|crispy }}
<button
type="button"
class="button is-light modal-close-button">
Cancel
</button>
<button type="submit" class="button is-info modal-close-button">Submit</button>
</form>

View File

@@ -1,31 +0,0 @@
{% include 'partials/notify.html' %}
{% load crispy_forms_tags %}
{% load crispy_forms_bulma_field %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if strategy_id is not None %}
hx-put="{% url 'strategies_action' type=type strategy_id=strategy_id %}"
{% else %}
hx-put="{% url 'strategies_action' type=type %}"
{% endif %}
hx-target="#strategies-table"
hx-swap="outerHTML">
{% csrf_token %}
{{ form|crispy }}
<button
type="button"
class="button is-light modal-close-button">
Cancel
</button>
<button type="submit" class="button is-info modal-close-button">Submit</button>
</form>

View File

@@ -1,34 +0,0 @@
<h1 class="title is-5">Add or edit a trade</h1>
<h1 class="subtitle">Updates will be posted to exchange!</h1>
{% include 'partials/notify.html' %}
{% load crispy_forms_tags %}
{% load crispy_forms_bulma_field %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if trade_id is not None %}
hx-put="{% url 'trade_action' type=type trade_id=trade_id %}"
{% else %}
hx-put="{% url 'trade_action' type=type %}"
{% endif %}
hx-target="#trades-table"
hx-swap="outerHTML">
{% csrf_token %}
{{ form|crispy }}
<button
type="button"
class="button is-light modal-close-button">
Cancel
</button>
<button type="submit" class="button is-info modal-close-button">Submit</button>
</form>

View File

@@ -1,23 +0,0 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of active URL endpoints for receiving hooks.</h1>
<h1 class="subtitle">Add URLs here to receive Drakdoo callbacks. Make then unique!</h1>
<h1 class="subtitle">Warning: hooks can only trade in one direction.</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'hook_action' type=type %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Hook</span>
</span>
</button>
</div>
{% include 'partials/hook-list.html' %}

View File

@@ -5,13 +5,9 @@
{% load crispy_forms_bulma_field %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if hook_id is not None %}
hx-put="{% url 'hook_action' type=type hook_id=hook_id %}"
{% else %}
hx-put="{% url 'hook_action' type=type %}"
{% endif %}
hx-target="#hooks-table"
hx-swap="outerHTML">
hx-post="{{ submit_url }}"
hx-target="#modals-here"
hx-swap="innerHTML">
{% csrf_token %}
{{ form|crispy }}
<button

View File

@@ -0,0 +1,28 @@
{% include 'partials/notify.html' %}
{% if page_title is not None %}
<h1 class="title is-4">{{ page_title }}</h1>
{% endif %}
{% if page_subtitle is not None %}
<h1 class="subtitle">{{ page_subtitle }}</h1>
{% endif %}
{% if submit_url is not None %}
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{{ submit_url }}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>{{ title_singular }}</span>
</span>
</button>
</div>
{% endif %}
{% include list_template %}

View File

@@ -1,6 +1,6 @@
<h1 class="title is-4">Live positions from all exchanges</h1>
<h1 class="subtitle">Manual trades are editable under "Bot Trades" tab.</h1>
<h1 class="title is-4"></h1>
<h1 class="subtitle"></h1>
{% include 'partials/notify.html' %}
{% include 'partials/position-list.html' %}
{% include 'partials/position-list.html' %}SSSSSSSSSSSSSSSSS

View File

@@ -1,21 +0,0 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of strategies</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Strategy</span>
</span>
</button>
</div>
{% include 'partials/strategy-list.html' %}

View File

@@ -1,23 +0,0 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'trade_action' type=type %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Trade</span>
</span>
</button>
</div>
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of bot and manual trades. This may not reflect actual live trades.</h1>
<h1 class="subtitle">Trades deleted here will not be closed on the exchange.</h1>
{% include 'partials/trade-list.html' %}