diff --git a/apps/common/fields.py b/apps/common/fields.py index f19689830..417e88504 100644 --- a/apps/common/fields.py +++ b/apps/common/fields.py @@ -5,6 +5,7 @@ import json from django import forms from django.utils import six from django.core.exceptions import ValidationError +from django.utils.translation import ugettext as _ class DictField(forms.Field): @@ -21,12 +22,13 @@ class DictField(forms.Field): value = json.loads(value) return value except json.JSONDecodeError: - pass - value = {} - return value + return ValidationError(_("Not a valid json")) + else: + return ValidationError(_("Not a string type")) def validate(self, value): - print(value) + if isinstance(value, ValidationError): + raise value if not value and self.required: raise ValidationError(self.error_messages['required'], code='required') diff --git a/apps/common/forms.py b/apps/common/forms.py index 3eb8c4989..9b88af3b9 100644 --- a/apps/common/forms.py +++ b/apps/common/forms.py @@ -26,7 +26,7 @@ def to_form_value(value): data = value return data except json.JSONDecodeError: - return '' + return "" class BaseForm(forms.Form): @@ -39,7 +39,7 @@ class BaseForm(forms.Form): if db_value is False or db_value: field.initial = to_form_value(db_value) elif django_value is False or django_value: - field.initial = django_value + field.initial = to_form_value(to_model_value(django_value)) def save(self, category="default"): if not self.is_bound: diff --git a/apps/common/templates/common/_add_terminal_command_storage_modal.html b/apps/common/templates/common/_add_terminal_command_storage_modal.html deleted file mode 100644 index 678152981..000000000 --- a/apps/common/templates/common/_add_terminal_command_storage_modal.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends '_modal.html' %} -{% load i18n %} -{% block modal_id %}add_command_storage_model{% endblock %} -{% block modal_title%}{% trans "Add command storage" %}{% endblock %} -{% block modal_body %} -
- {% csrf_token %} -
- - {% trans 'Download' %} -
-
- - - - {% trans 'If set id, will use this id update asset existed' %} - -
-
-{% endblock %} -{% block modal_confirm_id %}btn_asset_import{% endblock %} diff --git a/apps/common/templates/common/terminal_setting.html b/apps/common/templates/common/terminal_setting.html index 3d0b7eb6f..c15ff4bc7 100644 --- a/apps/common/templates/common/terminal_setting.html +++ b/apps/common/templates/common/terminal_setting.html @@ -73,8 +73,8 @@ {# #} -
-

{% trans "Replay storage" %}

+{#
#} +{#

{% trans "Replay storage" %}

#}
@@ -92,7 +92,6 @@
- {% include 'common/_add_terminal_command_storage_modal.html' %} {% endblock %} {% block custom_foot_js %}