Source code for apis_core.generic.forms.widgets

import json

from django.forms.widgets import Input


[docs] class NewlineSeparatedListWidget(Input): input_type = "text" template_name = "widgets/multiline.html"
[docs] class Media: js = ["js/multiline.js"]
[docs] def value_from_datadict(self, data, files, name): values = [item for item in data.getlist(name) if item] return "\n".join(values)
[docs] def format_value(self, value): if value == "" or value is None: return None return value.split("\n")
[docs] class JSONListWidget(Input): input_type = "text" template_name = "widgets/multiline.html"
[docs] class Media: js = ["js/multiline.js"]
[docs] def value_from_datadict(self, data, files, name): values = [item for item in data.getlist(name) if item] return values
[docs] def format_value(self, value): if value == "" or value is None: return None return json.loads(value)