From 7afdd39af712fda6e01e3fbe05d086717141542d Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 11 Feb 2023 17:45:22 +0000 Subject: [PATCH] Fix adding asset restrictions --- core/forms.py | 4 +++- core/models.py | 2 +- core/trading/assetfilter.py | 2 +- core/views/assets.py | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/forms.py b/core/forms.py index 04e4b08..ab2190f 100644 --- a/core/forms.py +++ b/core/forms.py @@ -333,7 +333,7 @@ class AssetRestrictionForm(RestrictedFormMixin, ModelForm): "pairs": "Comma-separated list of pairs to restrict when a webhook is received. This does nothing on its own.", } - pairs_parsed = forms.BooleanField(widget=forms.HiddenInput) + pairs_parsed = forms.BooleanField(widget=forms.HiddenInput, required=False) def clean(self): cleaned_data = super(AssetRestrictionForm, self).clean() @@ -351,5 +351,7 @@ class AssetRestrictionForm(RestrictedFormMixin, ModelForm): return cleaned_data["pairs_parsed"] = new_pairs + else: + cleaned_data["pairs_parsed"] = {} return cleaned_data diff --git a/core/models.py b/core/models.py index 5ba1a7d..06103a1 100644 --- a/core/models.py +++ b/core/models.py @@ -426,7 +426,7 @@ class AssetRestriction(models.Model): name = models.CharField(max_length=255) description = models.TextField(null=True, blank=True) pairs = models.CharField(max_length=4096, null=True, blank=True) - pairs_parsed = models.JSONField(null=True, blank=True, default=dict) + pairs_parsed = models.JSONField(null=True, blank=True, default=list) webhook_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) diff --git a/core/trading/assetfilter.py b/core/trading/assetfilter.py index 851a9c6..6ccda02 100644 --- a/core/trading/assetfilter.py +++ b/core/trading/assetfilter.py @@ -4,4 +4,4 @@ def get_allowed(strategy, symbol, direction): linked to the strategy. """ - #asset_group = strategy. \ No newline at end of file + # asset_group = strategy. diff --git a/core/views/assets.py b/core/views/assets.py index 3047385..ff7ab3f 100644 --- a/core/views/assets.py +++ b/core/views/assets.py @@ -86,6 +86,10 @@ class AssetRestrictionCreate( submit_url_name = "assetrestriction_create" submit_url_args = ["type", "group"] + def form_invalid(self, form): + """If the form is invalid, render the invalid form.""" + return self.get(self.request, **self.kwargs, form=form) + def pre_save_mutate(self, user, obj): try: assetgroup = AssetGroup.objects.get(pk=self.kwargs["group"], user=user)