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): class Timestamp(Model):
sent = fields.DateTime() sent = fields.Int()
trade = fields.DateTime() trade = fields.Int()
class BaseDrakdoo(Model): 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) title = models.CharField(max_length=1024, null=True, blank=True)
message = 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) period = models.CharField(max_length=255, null=True, blank=True)
market = models.CharField(max_length=255, null=True, blank=True) timestamp_sent = models.BigIntegerField(null=True, blank=True)
timestamp_sent = models.DateTimeField(null=True, blank=True) timestamp_trade = models.BigIntegerField(null=True, blank=True)
timestamp_trade = models.DateTimeField(null=True, blank=True)
market_exchange = models.CharField(max_length=255, 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_item = models.CharField(max_length=255, null=True, blank=True)
market_currency = 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 <i
class="fa-solid fa-xmark has-text-grey-light float-right" class="fa-solid fa-xmark has-text-grey-light float-right"
onclick='grid.removeWidget("widget-{{ unique }}");'></i> onclick='grid.removeWidget("widget-{{ unique }}");'></i>

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

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

@ -6,6 +6,14 @@
<th>hook id</th> <th>hook id</th>
<th>hook name</th> <th>hook name</th>
<th>title</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> <th>actions</th>
</thead> </thead>
{% for item in items %} {% for item in items %}
@ -15,12 +23,21 @@
<td> <td>
<a <a
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' 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-trigger="click"
hx-target="#modals-here">{{ item.hook.name }} hx-target="#modals-here">{{ item.hook.name }}
</a> </a>
</td> </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> <td>
<div class="buttons"> <div class="buttons">

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

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

Loading…
Cancel
Save