Added cleaning method to convert a list of comma separated strings into a set.
Reviewed by: Lennard de Rijk
--- a/app/soc/logic/cleaning.py Thu Sep 03 12:46:07 2009 +0530
+++ b/app/soc/logic/cleaning.py Fri Sep 04 22:35:13 2009 +0200
@@ -791,3 +791,28 @@
if not has_access(rights, access_level, scope_path, prefix):
self._errors[field] = ErrorList([DEF_NO_RIGHTS_FOR_ACL_MSG])
del self.cleaned_data[field]
+
+
+def str2set(string_field):
+ """Clean method for cleaning comma separated strings.
+
+ Obtains the comma separated string from the form and returns it as
+ a set of strings.
+ """
+
+ def wrapper(self):
+ """Decorator wrapper method.
+ """
+ cleaned_data = self.cleaned_data
+
+ string_data = cleaned_data.get(string_field)
+
+ list_data = []
+ for string in string_data.split(','):
+ string_strip = string.strip()
+ if string_strip and string_strip not in list_data:
+ list_data.append(string_strip)
+
+ return list_data
+
+ return wrapper