#
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
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
def get_projects(self):
for project_line in self.projects.strip().split('\n'):
- parts = project_line.strip().split(' ', 2)
+ parts = project_line.strip().split(None, 2)
if not parts or not parts[0]:
continue
url, lang, desc = (parts + [''] * 2)[:3]
<form enctype="multipart/form-data" method="POST">
- {% csrf_token %}
- {{ form.non_field_errors }}
- <label for="title">{% trans "Name" %}</label>
- {{ form.name.errors }}
- <input class="form-control" name="name" type="text" value="{{ form.name.value|default:"" }}">
- <label for="logo">{% trans "Logo" %}</label>
- {{ form.logo.errors }}
- <div>
- {{ form.logo }}
- </div>
- <label for="country">{% trans "Country" %}</label>
- {{ form.country.errors }}
- <select class="form-control" name="country">
- {% for c, t in form.cts %}
- <option value='{{ c }}' {% if form.country.value == c %}selected="selected"{% endif %}>{{ t }}</option>
- {% endfor %}
- </select>
- <label for="www">{% trans "WWW" %}</label>
- {{ form.www.errors }}
- <input class="form-control" name="www" type="www" value="{{ form.www.value|default:"" }}">
- <label for="title">{% trans "Description" %}</label>
- {{ form.description.errors }}
- <textarea class="form-control" name="description">{{ form.description.value|default:"" }}</textarea>
- <label for="title">{% trans "Projects" %}</label>
- {{ form.projects.errors }}
- <textarea class="form-control" name="projects">{{ form.projects.value|default:"" }}</textarea>
- {% trans "Enter each line as: URL language description" %}<br/>
-
+ {% include "organizations/snippets/organization_form.html" %}
<button style="margin-top:1em;" class="btn btn-default" type="submit">{% trans "Change" %}</button></td></tr>
</form>
<form enctype="multipart/form-data" method="POST">
- {% csrf_token %}
- {{ form.non_field_errors }}
- <label for="title">{% trans "Name" %}</label>
- {{ form.name.errors }}
- <input class="form-control" name="name" type="text" value="{{ form.name.value|default:"" }}">
- <label for="logo">{% trans "Logo" %}</label>
- {{ form.logo.errors }}
- <div>
- {{ form.logo }}
- </div>
- <label for="country">{% trans "Country" %}</label>
- {{ form.country.errors }}
- <select class="form-control" name="country">
- {% for c, t in form.cts %}
- <option value='{{ c }}' {% if form.country.value == c %}selected="selected"{% endif %}>{{ t }}</option>
- {% endfor %}
- </select>
- <label for="www">{% trans "WWW" %}</label>
- {{ form.www.errors }}
- <input class="form-control" name="www" type="www" value="{{ form.www.value|default:"" }}">
- <label for="title">{% trans "Description" %}</label>
- {{ form.description.errors }}
- <textarea class="form-control" name="description">{{ form.description.value|default:"" }}</textarea>
- <label for="title">{% trans "Projects" %}</label>
- {{ form.projects.errors }}
- <textarea class="form-control" name="projects">{{ form.projects.value|default:"" }}</textarea>
- {% trans "Enter each line as: URL language description" %}<br/>
-
+ {% include "organizations/snippets/organization_form.html" %}
<button style="margin-top:1em;" class="btn btn-default" type="submit">{% trans "Create organization" %}</button></td></tr>
</form>
--- /dev/null
+{% load i18n %}
+
+{% csrf_token %}
+{{ form.non_field_errors }}
+<label for="title">{% trans "Name" %}</label>
+ {{ form.name.errors }}
+ <input class="form-control" name="name" type="text" value="{{ form.name.value|default:"" }}">
+<label for="logo">{% trans "Logo" %}</label>
+ {{ form.logo.errors }}
+ <div>
+ {{ form.logo }}
+ </div>
+<label for="country">{% trans "Country" %}</label>
+ {{ form.country.errors }}
+ <select class="form-control" name="country">
+ {% for c, t in form.cts %}
+ <option value='{{ c }}' {% if form.country.value == c %}selected="selected"{% endif %}>{{ t }}</option>
+ {% endfor %}
+ </select>
+<label for="www">{% trans "WWW" %}</label>
+ {{ form.www.errors }}
+ <input class="form-control" name="www" type="www" value="{{ form.www.value|default:"" }}">
+<label for="title">{% trans "Description" %}</label>
+ {{ form.description.errors }}
+ <textarea class="form-control" name="description">{{ form.description.value|default:"" }}</textarea>
+<label for="title">{% trans "Projects" %}</label>
+ {{ form.projects.errors }}
+ <textarea class="form-control" name="projects">{{ form.projects.value|default:"" }}</textarea>
+{% trans "Enter each line as: Internet address, language, description, separated with spaces" %}<br/>
\ No newline at end of file