Commit cafb0e02 authored by ibuler's avatar ibuler

[Update] 修改dictfiled

parent 9d399c47
...@@ -5,6 +5,7 @@ import json ...@@ -5,6 +5,7 @@ import json
from django import forms from django import forms
from django.utils import six from django.utils import six
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
class DictField(forms.Field): class DictField(forms.Field):
...@@ -21,12 +22,13 @@ class DictField(forms.Field): ...@@ -21,12 +22,13 @@ class DictField(forms.Field):
value = json.loads(value) value = json.loads(value)
return value return value
except json.JSONDecodeError: except json.JSONDecodeError:
pass return ValidationError(_("Not a valid json"))
value = {} else:
return value return ValidationError(_("Not a string type"))
def validate(self, value): def validate(self, value):
print(value) if isinstance(value, ValidationError):
raise value
if not value and self.required: if not value and self.required:
raise ValidationError(self.error_messages['required'], code='required') raise ValidationError(self.error_messages['required'], code='required')
......
...@@ -26,7 +26,7 @@ def to_form_value(value): ...@@ -26,7 +26,7 @@ def to_form_value(value):
data = value data = value
return data return data
except json.JSONDecodeError: except json.JSONDecodeError:
return '' return ""
class BaseForm(forms.Form): class BaseForm(forms.Form):
...@@ -39,7 +39,7 @@ class BaseForm(forms.Form): ...@@ -39,7 +39,7 @@ class BaseForm(forms.Form):
if db_value is False or db_value: if db_value is False or db_value:
field.initial = to_form_value(db_value) field.initial = to_form_value(db_value)
elif django_value is False or django_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"): def save(self, category="default"):
if not self.is_bound: if not self.is_bound:
......
{% extends '_modal.html' %}
{% load i18n %}
{% block modal_id %}add_command_storage_model{% endblock %}
{% block modal_title%}{% trans "Add command storage" %}{% endblock %}
{% block modal_body %}
<form method="post" action="" id="add_command_storage_form">
{% csrf_token %}
<div class="form-group">
<label class="control-label" for="id_assets">{% trans "Template" %}</label>
<a href="{% url 'assets:asset-export' %}" style="display: block">{% trans 'Download' %}</a>
</div>
<div class="form-group">
<label class="control-label" for="id_users">{% trans "Asset csv file" %}</label>
<input id="id_assets" type="file" name="file" />
<span class="help-block red-fonts">
{% trans 'If set id, will use this id update asset existed' %}
</span>
</div>
</form>
{% endblock %}
{% block modal_confirm_id %}btn_asset_import{% endblock %}
...@@ -73,8 +73,8 @@ ...@@ -73,8 +73,8 @@
</tbody> </tbody>
</table> </table>
{# <button class="btn btn-default btn-circle btn-add-command-storage" data-toggle="modal" data-target="#add_command_storage_model" tabindex="0" type="button"><i class="fa fa-plus"></i></button>#} {# <button class="btn btn-default btn-circle btn-add-command-storage" data-toggle="modal" data-target="#add_command_storage_model" tabindex="0" type="button"><i class="fa fa-plus"></i></button>#}
<div class="hr-line-dashed"></div> {# <div class="hr-line-dashed"></div>#}
<h3>{% trans "Replay storage" %}</h3> {# <h3>{% trans "Replay storage" %}</h3>#}
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
</div> </div>
</div> </div>
</div> </div>
{% include 'common/_add_terminal_command_storage_modal.html' %}
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
......
...@@ -378,8 +378,8 @@ COMMAND_STORAGE = { ...@@ -378,8 +378,8 @@ COMMAND_STORAGE = {
} }
TERMINAL_COMMAND_STORAGE = { TERMINAL_COMMAND_STORAGE = {
'default': { "default": {
'TYPE': 'server', "TYPE": "server",
}, },
# 'ali-es': { # 'ali-es': {
# 'TYPE': 'elasticsearch', # 'TYPE': 'elasticsearch',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment