# HG changeset patch # User Madhusudan.C.S # Date 1252096513 -7200 # Node ID 391766c2aacf2e435f63cb19431420ada0d72af0 # Parent 9b59d89e67072b695ef5d48165f81d5e30bb3f0f Added cleaning method to convert a list of comma separated strings into a set. Reviewed by: Lennard de Rijk diff -r 9b59d89e6707 -r 391766c2aacf app/soc/logic/cleaning.py --- 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