diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-04-09 20:22:12 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:39:42 +0200 | 
| commit | 478bef4100f4b18553a74e79fbacc2ffec695d7c (patch) | |
| tree | 26d66e9387005a4e7b047b1bd9a2a6542856076d /ishtar_common/forms_common.py | |
| parent | eada3318b5244c9556314f1f68012260e7b95d22 (diff) | |
| download | Ishtar-478bef4100f4b18553a74e79fbacc2ffec695d7c.tar.bz2 Ishtar-478bef4100f4b18553a74e79fbacc2ffec695d7c.zip | |
Add a profile page to manage preferences (refs #4046)
Diffstat (limited to 'ishtar_common/forms_common.py')
| -rw-r--r-- | ishtar_common/forms_common.py | 34 | 
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") | 
