Make variables passed to CRUD helpers consistent
This commit is contained in:
parent
246674b03e
commit
8de99c1bcd
|
@ -185,15 +185,18 @@ class ObjectCreate(RestrictedViewMixin, ObjectNameMixin, CreateView):
|
|||
window_content = "window-content/object-form.html"
|
||||
parser_classes = [FormParser]
|
||||
|
||||
page_title = None
|
||||
page_subtitle = None
|
||||
|
||||
model = None
|
||||
submit_url_name = None
|
||||
|
||||
list_url_name = None
|
||||
# WARNING: TAKEN FROM locals()
|
||||
list_url_args = ["type"]
|
||||
submit_url_args = ["type"]
|
||||
|
||||
request = None
|
||||
|
||||
# Whether to hide the cancel button in the form
|
||||
hide_cancel = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.title = "Create " + self.context_object_name_singular
|
||||
|
@ -230,17 +233,22 @@ class ObjectCreate(RestrictedViewMixin, ObjectNameMixin, CreateView):
|
|||
self.request = request
|
||||
self.kwargs = kwargs
|
||||
|
||||
list_url_args = {}
|
||||
for arg in self.list_url_args:
|
||||
list_url_args[arg] = locals()[arg]
|
||||
if type == "widget":
|
||||
self.hide_cancel = True
|
||||
|
||||
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)
|
||||
submit_url_args = {}
|
||||
for arg in self.submit_url_args:
|
||||
if arg in locals():
|
||||
submit_url_args[arg] = locals()[arg]
|
||||
elif arg in kwargs:
|
||||
submit_url_args[arg] = kwargs[arg]
|
||||
submit_url = reverse(self.submit_url_name, kwargs=submit_url_args)
|
||||
|
||||
context = self.get_context_data()
|
||||
form = kwargs.get("form", None)
|
||||
if form:
|
||||
|
@ -250,8 +258,12 @@ class ObjectCreate(RestrictedViewMixin, ObjectNameMixin, CreateView):
|
|||
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
|
||||
context["hide_cancel"] = self.hide_cancel
|
||||
if self.page_title:
|
||||
context["page_title"] = self.page_title
|
||||
if self.page_subtitle:
|
||||
context["page_subtitle"] = self.page_subtitle
|
||||
response = self.render_to_response(context)
|
||||
# response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
|
||||
return response
|
||||
|
@ -392,6 +404,9 @@ class ObjectUpdate(RestrictedViewMixin, ObjectNameMixin, UpdateView):
|
|||
return HttpResponseBadRequest("Invalid type specified")
|
||||
self.template_name = f"wm/{type}.html"
|
||||
unique = str(uuid.uuid4())[:8]
|
||||
if type == "widget":
|
||||
self.hide_cancel = True
|
||||
|
||||
if type == "page":
|
||||
type = "modal"
|
||||
|
||||
|
|
|
@ -66,9 +66,6 @@ class AccountCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
|
|||
model = Account
|
||||
form_class = AccountForm
|
||||
|
||||
list_url_name = "accounts"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "account_create"
|
||||
|
||||
|
||||
|
@ -76,14 +73,8 @@ class AccountUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
|
|||
model = Account
|
||||
form_class = AccountForm
|
||||
|
||||
list_url_name = "accounts"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "account_update"
|
||||
|
||||
|
||||
class AccountDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
|
||||
model = Account
|
||||
|
||||
list_url_name = "accounts"
|
||||
list_url_args = ["type"]
|
||||
|
|
|
@ -163,9 +163,6 @@ class HookCreate(LoginRequiredMixin, ObjectCreate):
|
|||
model = Hook
|
||||
form_class = HookForm
|
||||
|
||||
list_url_name = "hooks"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "hook_create"
|
||||
|
||||
|
||||
|
@ -173,14 +170,8 @@ class HookUpdate(LoginRequiredMixin, ObjectUpdate):
|
|||
model = Hook
|
||||
form_class = HookForm
|
||||
|
||||
list_url_name = "hooks"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "hook_update"
|
||||
|
||||
|
||||
class HookDelete(LoginRequiredMixin, ObjectDelete):
|
||||
model = Hook
|
||||
|
||||
list_url_name = "hooks"
|
||||
list_url_args = ["type"]
|
||||
|
|
|
@ -99,9 +99,6 @@ class TradingTimeCreate(LoginRequiredMixin, ObjectCreate):
|
|||
model = TradingTime
|
||||
form_class = TradingTimeForm
|
||||
|
||||
list_url_name = "tradingtimes"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "tradingtime_create"
|
||||
|
||||
|
||||
|
@ -109,14 +106,8 @@ class TradingTimeUpdate(LoginRequiredMixin, ObjectUpdate):
|
|||
model = TradingTime
|
||||
form_class = TradingTimeForm
|
||||
|
||||
list_url_name = "tradingtimes"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "tradingtime_update"
|
||||
|
||||
|
||||
class TradingTimeDelete(LoginRequiredMixin, ObjectDelete):
|
||||
model = TradingTime
|
||||
|
||||
list_url_name = "tradingtimes"
|
||||
list_url_args = ["type"]
|
||||
|
|
|
@ -16,9 +16,6 @@ class NotificationsUpdate(LoginRequiredMixin, ObjectUpdate):
|
|||
"At least the topic must be set if you want to receive notifications."
|
||||
)
|
||||
|
||||
# list_url_name = "notifications"
|
||||
# list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "notifications_update"
|
||||
submit_url_args = ["type"]
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@ class SignalCreate(LoginRequiredMixin, ObjectCreate):
|
|||
model = Signal
|
||||
form_class = SignalForm
|
||||
|
||||
list_url_name = "signals"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "signal_create"
|
||||
|
||||
|
||||
|
@ -36,14 +33,8 @@ class SignalUpdate(LoginRequiredMixin, ObjectUpdate):
|
|||
model = Signal
|
||||
form_class = SignalForm
|
||||
|
||||
list_url_name = "signals"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "signal_update"
|
||||
|
||||
|
||||
class SignalDelete(LoginRequiredMixin, ObjectDelete):
|
||||
model = Signal
|
||||
|
||||
list_url_name = "signals"
|
||||
list_url_args = ["type"]
|
||||
|
|
|
@ -25,8 +25,6 @@ class StrategyList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
|||
class StrategyCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
|
||||
model = Strategy
|
||||
form_class = StrategyForm
|
||||
list_url_name = "strategies"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "strategy_create"
|
||||
|
||||
|
@ -35,14 +33,8 @@ class StrategyUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
|
|||
model = Strategy
|
||||
form_class = StrategyForm
|
||||
|
||||
list_url_name = "strategies"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "strategy_update"
|
||||
|
||||
|
||||
class StrategyDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
|
||||
model = Strategy
|
||||
|
||||
list_url_name = "strategies"
|
||||
list_url_args = ["type"]
|
||||
|
|
|
@ -74,9 +74,6 @@ class TradeList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
|||
class TradeCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
|
||||
model = Trade
|
||||
form_class = TradeForm
|
||||
list_url_name = "trades"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "trade_create"
|
||||
|
||||
def post_save(self, obj):
|
||||
|
@ -87,8 +84,6 @@ class TradeCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
|
|||
class TradeUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
|
||||
model = Trade
|
||||
form_class = TradeForm
|
||||
list_url_name = "trades"
|
||||
list_url_args = ["type"]
|
||||
|
||||
submit_url_name = "trade_update"
|
||||
|
||||
|
@ -96,9 +91,6 @@ class TradeUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
|
|||
class TradeDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
|
||||
model = Trade
|
||||
|
||||
list_url_name = "trades"
|
||||
list_url_args = ["type"]
|
||||
|
||||
|
||||
class TradeDeleteAll(LoginRequiredMixin, OTPRequiredMixin, ObjectNameMixin, View):
|
||||
template_name = "partials/notify.html"
|
||||
|
|
Loading…
Reference in New Issue