Coverage for apis_core/generic/forms/widgets.py: 0%
26 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1import json
3from django.forms.widgets import Input
6class NewlineSeparatedListWidget(Input):
7 input_type = "text"
8 template_name = "widgets/multiline.html"
10 class Media:
11 js = ["js/multiline.js"]
13 def value_from_datadict(self, data, files, name):
14 values = [item for item in data.getlist(name) if item]
15 return "\n".join(values)
17 def format_value(self, value):
18 if value == "" or value is None:
19 return None
20 return value.split("\n")
23class JSONListWidget(Input):
24 input_type = "text"
25 template_name = "widgets/multiline.html"
27 class Media:
28 js = ["js/multiline.js"]
30 def value_from_datadict(self, data, files, name):
31 values = [item for item in data.getlist(name) if item]
32 return values
34 def format_value(self, value):
35 if value == "" or value is None:
36 return None
37 return json.loads(value)