X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f1c6ff102206aa2b0903d61eb648691d5e2e028c..b477b3cfa2ce28678eb6c861b286e86ed77046ee:/apps/organizations/forms.py diff --git a/apps/organizations/forms.py b/apps/organizations/forms.py index 55807663..6af8c6c3 100644 --- a/apps/organizations/forms.py +++ b/apps/organizations/forms.py @@ -5,6 +5,7 @@ # from django import forms from django.contrib.sites.models import Site +from django.utils.translation import ugettext as _ from redakcja.utlis import send_notify_email from .models import Organization, UserCard, countries @@ -18,16 +19,41 @@ class OrganizationForm(forms.ModelForm): exclude = ['_html'] def save(self, commit=True): + new = self.instance.id is None organization = super(OrganizationForm, self).save(commit=commit) - site = Site.objects.get_current() - send_notify_email( - 'New organization in MIL/PEER', - '''New organization in MIL/PEER: %s. View their profile: https://%s%s. + if new: + site = Site.objects.get_current() + send_notify_email( + 'New organization in MIL/PEER', + '''New organization in MIL/PEER: %s. View their profile: https://%s%s. -- MIL/PEER team.''' % (organization.name, site.domain, organization.get_absolute_url())) return organization + def clean_projects(self): + projects = self.cleaned_data.get('projects', '') + lines = [] + for line in projects.split('\n'): + line = line.strip() + if line: + try: + url, lang, desc = 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) + class UserCardForm(forms.ModelForm): cts = countries