Add all model fields to callbacks

Mark Veidemanis 2 years ago
parent 97d12b0fab
commit 5a7332eb96
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -9,8 +9,8 @@ class Market(Model):
class Timestamp(Model):
sent = fields.DateTime()
trade = fields.DateTime()
sent = fields.Int()
trade = fields.Int()
class BaseDrakdoo(Model):

@ -0,0 +1,27 @@
# Generated by Django 4.1.2 on 2022-10-16 13:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_remove_callback_data_callback_market_and_more'),
]
operations = [
migrations.RemoveField(
model_name='callback',
name='market',
),
migrations.AlterField(
model_name='callback',
name='timestamp_sent',
field=models.BigIntegerField(blank=True, null=True),
),
migrations.AlterField(
model_name='callback',
name='timestamp_trade',
field=models.BigIntegerField(blank=True, null=True),
),
]

@ -86,9 +86,8 @@ class Callback(models.Model):
title = models.CharField(max_length=1024, null=True, blank=True)
message = models.CharField(max_length=1024, null=True, blank=True)
period = models.CharField(max_length=255, null=True, blank=True)
market = models.CharField(max_length=255, null=True, blank=True)
timestamp_sent = models.DateTimeField(null=True, blank=True)
timestamp_trade = models.DateTimeField(null=True, blank=True)
timestamp_sent = models.BigIntegerField(null=True, blank=True)
timestamp_trade = models.BigIntegerField(null=True, blank=True)
market_exchange = models.CharField(max_length=255, null=True, blank=True)
market_item = models.CharField(max_length=255, null=True, blank=True)
market_currency = models.CharField(max_length=255, null=True, blank=True)

@ -1,3 +1,3 @@
<i
class="fa-solid fa-xmark has-text-grey-light float-right"
onclick='grid.removeWidget("widget-{{ unique }}");'></i>
class="fa-solid fa-xmark has-text-grey-light float-right"
onclick='grid.removeWidget("widget-{{ unique }}");'></i>

@ -1,3 +1,3 @@
<i
class="fa-solid fa-xmark has-text-grey-light float-right"
data-script="on click remove the closest <nav/>"></i>
class="fa-solid fa-xmark has-text-grey-light float-right"
data-script="on click remove the closest <nav/>"></i>

@ -6,9 +6,9 @@
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if hook_id is not None %}
hx-put="{% url 'hook_action' hook_id %}"
hx-put="{% url 'hook_action' type=type hook_id=hook_id %}"
{% else %}
hx-put="{% url 'hook_action' %}"
hx-put="{% url 'hook_action' type=type %}"
{% endif %}
hx-target="#hooks-table"
hx-swap="outerHTML">

@ -6,6 +6,14 @@
<th>hook id</th>
<th>hook name</th>
<th>title</th>
<th>message</th>
<th>period</th>
<th>sent</th>
<th>trade</th>
<th>exchange</th>
<th>item</th>
<th>currency</th>
<th>contract</th>
<th>actions</th>
</thead>
{% for item in items %}
@ -15,12 +23,21 @@
<td>
<a
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'hook_action' hook_id=item.hook.id %}"
hx-get="{% url 'hook_action' type=type hook_id=item.hook.id %}"
hx-trigger="click"
hx-target="#modals-here">{{ item.hook.name }}
</a>
</td>
<td><pre>{{ item.title }}</pre></td>
<td>{{ item.title }}</td>
<td>{{ item.message }}</td>
<td>{{ item.period }}</td>
<td>{{ item.timestamp_sent }}</td>
<td>{{ item.timestamp_trade }}</td>
<td>{{ item.market_exchange }}</td>
<td>{{ item.market_item }}</td>
<td>{{ item.market_currency }}</td>
<td>{{ item.market_contract }}</td>
<td>
<div class="buttons">

@ -35,8 +35,9 @@ class Callbacks(LoginRequiredMixin, View):
context = {
"message": message,
"class": message_class,
"type": type,
}
return render(request, "wm/modal.html", context)
return render(request, template_name, context)
callbacks = get_callbacks(hook)
else:
callbacks = get_callbacks(user=request.user)
@ -46,5 +47,6 @@ class Callbacks(LoginRequiredMixin, View):
"unique": unique,
"window_content": self.window_content,
"items": callbacks,
"type": type,
}
return render(request, template_name, context)

@ -29,14 +29,14 @@ class HookAPI(APIView):
log.debug(f"HookAPI POST: {request.data}")
# Try loading the JSON
try:
loaded_json = orjson.loads(request.data)
except orjson.JSONDecodeError:
return HttpResponseBadRequest("Invalid JSON")
# try:
# loaded_json = orjson.loads(request.data)
# except orjson.JSONDecodeError:
# return HttpResponseBadRequest("Invalid JSON")
# Try validating the JSON
try:
hook_resp = drakdoo.BaseDrakdoo.from_dict(loaded_json)
hook_resp = drakdoo.BaseDrakdoo.from_dict(request.data)
except ValidationError as e:
log.error(f"HookAPI POST: {e}")
return HttpResponseBadRequest(e)
@ -45,7 +45,6 @@ class HookAPI(APIView):
"title": hook_resp.title,
"message": hook_resp.message,
"period": hook_resp.period,
"market": hook_resp.market,
"timestamp_sent": hook_resp.timestamp.sent,
"timestamp_trade": hook_resp.timestamp.trade,
"market_exchange": hook_resp.market.exchange,
@ -87,6 +86,8 @@ class Hooks(LoginRequiredMixin, View):
template_name = f"wm/{type}.html"
unique = str(uuid.uuid4())[:8]
hooks = get_hooks(request.user)
if type == "page":
type = "modal"
context = {
"title": f"Hooks ({type})",
"unique": unique,

Loading…
Cancel
Save