예제 #1
0
 def validate(self, value, model_instance):
     # json.loadsができるかどうか確認.
     if not self.editable:
         # Skip validation for non-editable fields.
         return
     
     models.TextField.validate(self, value, model_instance)
     try:
         Json.encode(value, ensure_ascii=False)
     except:
         raise exceptions.ValidationError(self.error_messages['notjson'])
예제 #2
0
 def to_python(self, value):
     """
     loadsしてみて成功したら結果を返す。
     失敗したらそのまま返す。
     """
     if isinstance(value, unicode):
         value = StrUtil.to_s(value)
     if isinstance(value, str):
         try:
             value = Json.decode(value)
         except:
             pass
     return value
예제 #3
0
 def render(self, name, value, attrs=None):
     try:
         value = Json.encode(value, ensure_ascii=False)
     except:
         pass
     return super(JsonInput, self).render(name, value, attrs=attrs)
예제 #4
0
 def get_db_prep_value(self, value, connection, prepared=False):
     if value is None:
         return None
     return Json.encode(value, ensure_ascii=False)