1 # -*- coding: utf-8 -*-
3 # This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django import forms
7 from constance import config
8 from django.contrib.sites.models import Site
9 from django.core.mail import send_mail
11 from .models import Organization, UserCard, countries
14 class OrganizationForm(forms.ModelForm):
21 def save(self, commit=True):
22 organization = super(OrganizationForm, self).save(commit=commit)
23 site = Site.objects.get_current()
25 'New organization in MIL/PEER',
26 '''New organization in MIL/PEER: %s. View their profile: https://%s%s.
29 MIL/PEER team.''' % (organization.name, site.domain, organization.get_absolute_url()),
30 'milpeer@mdrn.pl', [config.NOTIFY_EMAIL])
34 class UserCardForm(forms.ModelForm):
37 first_name = forms.CharField(required=False)
38 last_name = forms.CharField(required=False)
42 exclude = ['_html', 'user']
44 def __init__(self, *args, **kwargs):
45 if 'instance' in kwargs:
47 'first_name': kwargs['instance'].user.first_name,
48 'last_name': kwargs['instance'].user.last_name,
50 super(UserCardForm, self).__init__(*args, **kwargs)
52 def save(self, *args, **kwargs):
53 self.instance.user.first_name = self.cleaned_data.get('first_name', '')
54 self.instance.user.last_name = self.cleaned_data.get('last_name', '')
55 self.instance.user.save()
56 return super(UserCardForm, self).save(*args, **kwargs)