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 .models import Organization, UserCard, countries
10 class OrganizationForm(forms.ModelForm):
18 class UserCardForm(forms.ModelForm):
21 first_name = forms.CharField(required=False)
22 last_name = forms.CharField(required=False)
26 exclude = ['_html', 'user']
28 def __init__(self, *args, **kwargs):
29 if 'instance' in kwargs:
31 'first_name': kwargs['instance'].user.first_name,
32 'last_name': kwargs['instance'].user.last_name,
34 super(UserCardForm, self).__init__(*args, **kwargs)
36 def save(self, *args, **kwargs):
37 self.instance.user.first_name = self.cleaned_data.get('first_name', '')
38 self.instance.user.last_name = self.cleaned_data.get('last_name', '')
39 self.instance.user.save()
40 return super(UserCardForm, self).save(*args, **kwargs)