No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

formfields.py 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # This file is part of dnmgmt, a number resource management system
  2. # Licensed under GNU General Public License v3 or later
  3. # Written by Sebastian Lohff (seba@someserver.de)
  4. from django import forms
  5. class MultiTextInput(forms.widgets.Input):
  6. input_type = "text"
  7. def render(self, name, value, attrs=None):
  8. if value is not None:
  9. selectedOptions = []
  10. for val in value:
  11. for k, v in self.choices:
  12. if val == k:
  13. selectedOptions.append(v)
  14. value = " ".join(selectedOptions)
  15. return super(MultiTextInput, self).render(name, value, attrs)
  16. def value_from_datadict(self, data, files, name):
  17. values = list(filter(bool, map(lambda _x: _x.strip(), data.get(name).split(" "))))
  18. result = []
  19. for value in values:
  20. # FIXME: using value here throws a weird error message at some point
  21. # could be handled by overriding the messages in ChoiceField
  22. # or... well, don't know
  23. kId = value
  24. for k, v in self.choices:
  25. if v.lower() == value.lower():
  26. kId = str(k)
  27. break
  28. result.append(kId)
  29. return result