diff --git a/core/templates/partials/account-list.html b/core/templates/partials/account-list.html index e28851a..59c1123 100644 --- a/core/templates/partials/account-list.html +++ b/core/templates/partials/account-list.html @@ -1,6 +1,12 @@ {% include 'partials/notify.html' %} - +
@@ -35,6 +41,7 @@ hx-get="{% url 'account_update' type=type pk=item.id %}" hx-trigger="click" hx-target="#{{ type }}s-here" + hx-swap="innerHTML" class="button is-info"> @@ -47,6 +54,7 @@ hx-delete="{% url 'account_delete' type=type pk=item.id %}" hx-trigger="click" hx-target="#modals-here" + hx-swap="innerHTML" hx-confirm="Are you sure you wish to delete {{ item.name }}?" class="button is-danger"> diff --git a/core/templates/partials/hook-list.html b/core/templates/partials/hook-list.html index 46b3102..5da0b40 100644 --- a/core/templates/partials/hook-list.html +++ b/core/templates/partials/hook-list.html @@ -1,6 +1,12 @@ {% include 'partials/notify.html' %} -
id user
+
@@ -25,6 +31,7 @@ hx-get="{% url 'hook_update' type=type pk=item.id %}" hx-trigger="click" hx-target="#{{ type }}s-here" + hx-swap="innerHTML" class="button is-info"> @@ -37,6 +44,7 @@ hx-delete="{% url 'hook_delete' type=type pk=item.id %}" hx-trigger="click" hx-target="#modals-here" + hx-swap="innerHTML" hx-confirm="Are you sure you wish to delete {{ item.name }}?" class="button is-danger"> diff --git a/core/templates/partials/strategy-list.html b/core/templates/partials/strategy-list.html index e6e68ee..40d00df 100644 --- a/core/templates/partials/strategy-list.html +++ b/core/templates/partials/strategy-list.html @@ -1,6 +1,12 @@ {% include 'partials/notify.html' %} -
id user
+
@@ -37,6 +43,7 @@ hx-get="{% url 'strategy_update' type=type pk=item.id %}" hx-trigger="click" hx-target="#{{ type }}s-here" + hx-swap="innerHTML" class="button is-info"> @@ -49,6 +56,7 @@ hx-delete="{% url 'strategy_delete' type=type pk=item.id %}" hx-trigger="click" hx-target="#modals-here" + hx-swap="innerHTML" hx-confirm="Are you sure you wish to delete {{ item.name }}?" class="button is-danger"> diff --git a/core/templates/partials/trade-list.html b/core/templates/partials/trade-list.html index 30c9e96..e126409 100644 --- a/core/templates/partials/trade-list.html +++ b/core/templates/partials/trade-list.html @@ -1,6 +1,12 @@ {% include 'partials/notify.html' %} -
id name
+
@@ -31,6 +37,7 @@ hx-get="{% url 'trade_update' type=type pk=item.id %}" hx-trigger="click" hx-target="#{{ type }}s-here" + hx-swap="innerHTML" class="button is-info"> @@ -43,6 +50,7 @@ hx-delete="{% url 'trade_delete' type=type pk=item.id %}" hx-trigger="click" hx-target="#modals-here" + hx-swap="innerHTML" class="button is-danger"> diff --git a/core/templates/window-content/positions.html b/core/templates/window-content/positions.html deleted file mode 100644 index d7debec..0000000 --- a/core/templates/window-content/positions.html +++ /dev/null @@ -1,6 +0,0 @@ -

-

- -{% include 'partials/notify.html' %} - -{% include 'partials/position-list.html' %}SSSSSSSSSSSSSSSSS \ No newline at end of file diff --git a/core/views/__init__.py b/core/views/__init__.py index df32c13..af60a19 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -19,12 +19,17 @@ class ObjectList(ListView): model = None context_object_name = "objects" + context_object_name_singular = "object" page_title = None page_subtitle = None title = "Objects" title_singular = "Object" + list_url_name = None + # WARNING: TAKEN FROM locals() + list_url_args = ["type"] + submit_url_name = None # copied from BaseListView @@ -39,6 +44,12 @@ class ObjectList(ListView): return HttpResponseBadRequest("Invalid type specified") self.template_name = f"wm/{type}.html" unique = str(uuid.uuid4())[:8] + + list_url_args = {} + for arg in self.list_url_args: + list_url_args[arg] = locals()[arg] + print("LIST URL ARGS", list_url_args) + if type == "page": type = "modal" @@ -55,6 +66,8 @@ class ObjectList(ListView): if is_empty: raise Http404("Empty list") submit_url = reverse(self.submit_url_name, kwargs={"type": type}) + + list_url = reverse(self.list_url_name, kwargs=list_url_args) context = self.get_context_data() context["title"] = self.title + f" ({type})" context["title_singular"] = self.title_singular @@ -65,6 +78,13 @@ class ObjectList(ListView): context["page_subtitle"] = self.page_subtitle context["type"] = type context["submit_url"] = submit_url + context["list_url"] = list_url + context["context_object_name"] = self.context_object_name + context["context_object_name_singular"] = self.context_object_name_singular + + # Return partials for HTMX + if self.request.htmx: + self.template_name = self.list_template return self.render_to_response(context) @@ -77,6 +97,10 @@ class ObjectCreate(CreateView): context_object_name = "objects" submit_url_name = None + list_url_name = None + # WARNING: TAKEN FROM locals() + list_url_args = ["type"] + request = None def form_valid(self, form): @@ -87,7 +111,9 @@ class ObjectCreate(CreateView): obj.save() form.save_m2m() context = {"message": "Object created", "class": "success"} - return self.render_to_response(context) + response = self.render_to_response(context) + response["HX-Trigger"] = f"{self.context_object_name_singular}Event" + return response def get(self, request, *args, **kwargs): self.request = request @@ -98,16 +124,26 @@ class ObjectCreate(CreateView): return HttpResponseBadRequest("Invalid type specified") self.template_name = f"wm/{type}.html" unique = str(uuid.uuid4())[:8] + + list_url_args = {} + for arg in self.list_url_args: + list_url_args[arg] = locals()[arg] + print("LIST URL ARGS", list_url_args) + if type == "page": type = "modal" self.object = None submit_url = reverse(self.submit_url_name, kwargs={"type": type}) + + list_url = reverse(self.list_url_name, kwargs=list_url_args) context = self.get_context_data() context["unique"] = unique context["window_content"] = self.window_content context["context_object_name"] = self.context_object_name + context["context_object_name_singular"] = self.context_object_name_singular context["submit_url"] = submit_url + context["list_url"] = list_url context["type"] = type return self.render_to_response(context) @@ -143,7 +179,9 @@ class ObjectUpdate(UpdateView): obj.save() form.save_m2m() context = {"message": "Object updated", "class": "success"} - return self.render_to_response(context) + response = self.render_to_response(context) + response["HX-Trigger"] = f"{self.context_object_name_singular}Event" + return response def get(self, request, *args, **kwargs): self.request = request @@ -166,6 +204,7 @@ class ObjectUpdate(UpdateView): context["unique"] = unique context["window_content"] = self.window_content context["context_object_name"] = self.context_object_name + context["context_object_name_singular"] = self.context_object_name_singular context["submit_url"] = submit_url context["type"] = type return self.render_to_response(context) @@ -178,6 +217,7 @@ class ObjectUpdate(UpdateView): class ObjectDelete(DeleteView): model = None + context_object_name_singular = "object" template_name = "partials/notify.html" # Overriden to prevent success URL from being used @@ -190,7 +230,9 @@ class ObjectDelete(DeleteView): # success_url = self.get_success_url() self.object.delete() context = {"message": "Object deleted", "class": "success"} - return self.render_to_response(context) + response = self.render_to_response(context) + response["HX-Trigger"] = f"{self.context_object_name_singular}Event" + return response # This will be used in newer Django versions, until then we get a warning def form_valid(self, form): @@ -200,4 +242,6 @@ class ObjectDelete(DeleteView): self.object = self.get_object() self.object.delete() context = {"message": "Object deleted", "class": "success"} - return self.render_to_response(context) + response = self.render_to_response(context) + response["HX-Trigger"] = f"{self.context_object_name_singular}Event" + return response diff --git a/core/views/accounts.py b/core/views/accounts.py index db6c518..da795c6 100644 --- a/core/views/accounts.py +++ b/core/views/accounts.py @@ -63,10 +63,14 @@ class AccountList(LoginRequiredMixin, ObjectList): list_template = "partials/account-list.html" model = Account context_object_name = "accounts" + context_object_name_singular = "account" title = "Accounts" title_singular = "Account" page_title = "List of accounts" + list_url_name = "accounts" + list_url_args = ["type"] + submit_url_name = "account_create" @@ -74,6 +78,11 @@ class AccountCreate(LoginRequiredMixin, ObjectCreate): model = Account form_class = AccountForm context_object_name = "accounts" + context_object_name_singular = "account" + + list_url_name = "accounts" + list_url_args = ["type"] + submit_url_name = "account_create" @@ -94,8 +103,18 @@ class AccountUpdate(LoginRequiredMixin, ObjectUpdate): model = Account form_class = AccountForm context_object_name = "accounts" + context_object_name_singular = "account" + + list_url_name = "accounts" + list_url_args = ["type"] + submit_url_name = "account_update" class AccountDelete(LoginRequiredMixin, ObjectDelete): model = Account + context_object_name = "accounts" + context_object_name_singular = "account" + + list_url_name = "accounts" + list_url_args = ["type"] diff --git a/core/views/hooks.py b/core/views/hooks.py index c0f60a4..b5553d3 100644 --- a/core/views/hooks.py +++ b/core/views/hooks.py @@ -104,11 +104,15 @@ class HookList(LoginRequiredMixin, ObjectList): list_template = "partials/hook-list.html" model = Hook context_object_name = "hooks" + context_object_name_singular = "hook" title = "Hooks" title_singular = "Hook" page_title = "List of active URL endpoints for receiving hooks." page_subtitle = "Add URLs here to receive Drakdoo callbacks. Make then unique!" + list_url_name = "hooks" + list_url_args = ["type"] + submit_url_name = "hook_create" @@ -116,6 +120,11 @@ class HookCreate(LoginRequiredMixin, ObjectCreate): model = Hook form_class = HookForm context_object_name = "hooks" + context_object_name_singular = "hook" + + list_url_name = "hooks" + list_url_args = ["type"] + submit_url_name = "hook_create" @@ -123,8 +132,18 @@ class HookUpdate(LoginRequiredMixin, ObjectUpdate): model = Hook form_class = HookForm context_object_name = "hooks" + context_object_name_singular = "hook" + + list_url_name = "hooks" + list_url_args = ["type"] + submit_url_name = "hook_update" class HookDelete(LoginRequiredMixin, ObjectDelete): model = Hook + context_object_name = "hooks" + context_object_name_singular = "hook" + + list_url_name = "hooks" + list_url_args = ["type"] diff --git a/core/views/strategies.py b/core/views/strategies.py index 65d9c7d..e844d6e 100644 --- a/core/views/strategies.py +++ b/core/views/strategies.py @@ -15,10 +15,14 @@ class StrategyList(LoginRequiredMixin, ObjectList): list_template = "partials/strategy-list.html" model = Strategy context_object_name = "strategies" + context_object_name_singular = "strategy" title = "Strategies" title_singular = "Strategy" page_title = "List of strategies" + list_url_name = "strategies" + list_url_args = ["type"] + submit_url_name = "strategy_create" @@ -26,6 +30,11 @@ class StrategyCreate(LoginRequiredMixin, ObjectCreate): model = Strategy form_class = StrategyForm context_object_name = "strategies" + context_object_name_singular = "strategy" + + list_url_name = "strategies" + list_url_args = ["type"] + submit_url_name = "strategy_create" @@ -33,8 +42,18 @@ class StrategyUpdate(LoginRequiredMixin, ObjectUpdate): model = Strategy form_class = StrategyForm context_object_name = "strategies" + context_object_name_singular = "strategy" + + list_url_name = "strategies" + list_url_args = ["type"] + submit_url_name = "strategy_update" class StrategyDelete(LoginRequiredMixin, ObjectDelete): model = Strategy + context_object_name = "strategies" + context_object_name_singular = "strategy" + + list_url_name = "strategies" + list_url_args = ["type"] diff --git a/core/views/trades.py b/core/views/trades.py index 52bd320..a2b4f86 100644 --- a/core/views/trades.py +++ b/core/views/trades.py @@ -12,6 +12,7 @@ class TradeList(LoginRequiredMixin, ObjectList): list_template = "partials/trade-list.html" model = Trade context_object_name = "trades" + context_object_name_singular = "trade" title = "Trades" title_singular = "Trade" page_title = ( @@ -19,6 +20,9 @@ class TradeList(LoginRequiredMixin, ObjectList): ) page_subtitle = "Trades deleted here will not be closed on the exchange." + list_url_name = "trades" + list_url_args = ["type"] + submit_url_name = "trade_create" @@ -26,6 +30,11 @@ class TradeCreate(LoginRequiredMixin, ObjectCreate): model = Trade form_class = TradeForm context_object_name = "trades" + context_object_name_singular = "trade" + + list_url_name = "trades" + list_url_args = ["type"] + submit_url_name = "trade_create" @@ -33,8 +42,18 @@ class TradeUpdate(LoginRequiredMixin, ObjectUpdate): model = Trade form_class = TradeForm context_object_name = "trades" + context_object_name_singular = "trade" + + list_url_name = "trades" + list_url_args = ["type"] + submit_url_name = "trade_update" class TradeDelete(LoginRequiredMixin, ObjectDelete): model = Trade + context_object_name = "trades" + context_object_name_singular = "trade" + + list_url_name = "trades" + list_url_args = ["type"]
id status