+
+def clean_projects(projects):
+ lines = []
+ for line in projects.split('\n'):
+ line = line.strip()
+ if line:
+ try:
+ url, lang, desc = [part.strip(',') for part in line.split(None, 2)]
+ except ValueError:
+ raise forms.ValidationError(
+ _('Each line has to consist of an Internet address, language and description, '
+ 'separated with spaces. Failed on: %s' % line))
+ # naive check
+ if '.' not in url or url.endswith('.'):
+ raise forms.ValidationError(
+ _('The first item in each line should be an Internet address. Failed on: %s') % url)
+ if not url.startswith('http'):
+ url = 'http://' + url
+ lines.append(' '.join((url, lang, desc)))
+ else:
+ lines.append('')
+ return '\n'.join(lines)
+
+