summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index c7cea9bdc..06debe9ce 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -731,6 +731,39 @@ class FinalAccountForm(forms.Form):
return super(FinalAccountForm, self).__init__(*args, **kwargs)
+class ProfilePersonForm(forms.Form):
+ current_profile = forms.ChoiceField(label=_(u"Current profile"),
+ choices=[])
+
+ def __init__(self, *args, **kwargs):
+ self.user = kwargs.pop('user')
+ choices, initial = [], kwargs.get('initial', {})
+ for profile in self.user.ishtaruser.person.profiles.all():
+ if profile.current:
+ initial['current_profile'] = profile.pk
+ choices.append((profile.pk, unicode(profile)))
+ kwargs['initial'] = initial
+ super(ProfilePersonForm, self).__init__(*args, **kwargs)
+ self.fields['current_profile'].choices = choices
+
+ def save(self, *args, **kwargs):
+ q = models.UserProfile.objects.filter(
+ person__ishtaruser=self.user.ishtaruser, current=True)
+ for profile in q.all():
+ profile.current = False
+ profile.save()
+
+ q = models.UserProfile.objects.filter(
+ person__ishtaruser=self.user.ishtaruser,
+ pk=int(self.cleaned_data['current_profile'])
+ )
+ if not q.count():
+ return
+ profile = q.all()[0]
+ profile.current = True
+ profile.save()
+
+
class TownForm(forms.Form):
form_label = _("Towns")
base_model = 'town'
@@ -1009,6 +1042,7 @@ class AuthorFormSet(FormSet):
return self.check_duplicate(('author',),
_("There are identical authors."))
+
AuthorFormset = formset_factory(AuthorFormSelection, can_delete=True,
formset=AuthorFormSet)
AuthorFormset.form_label = _("Authors")