From b1f5bad2ddaebe2dd9943333d7efd131f63896e9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 16 Aug 2016 16:57:14 +0200 Subject: Account management: fix edit - can delete an account (refs #2977) --- ishtar_common/forms_common.py | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'ishtar_common/forms_common.py') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 1d8dc2092..a9873cb0a 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2015 Étienne Loks +# Copyright (C) 2010-2016 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -306,6 +306,51 @@ class SimplePersonForm(NewItemForm): self.fields['raw_name'].widget.attrs['readonly'] = True +class PersonUserSelect(PersonSelect): + ishtaruser__isnull = forms.NullBooleanField( + label=_(u"Already has an account"), initial=False) + + +class PersonUserFormSelection(PersonFormSelection): + form_label = _(u"Person search") + associated_models = {'pk': models.Person} + currents = {'pk': models.Person} + pk = forms.IntegerField( + label="", + widget=widgets.JQueryJqGrid(reverse_lazy('get-person'), + PersonUserSelect, models.Person), + validators=[models.valid_id(models.Person)]) + + +class IshtarUserSelect(TableSelect): + username = forms.CharField(label=_(u"Username"), max_length=200) + name = forms.CharField(label=_(u"Name"), max_length=200) + surname = forms.CharField(label=_(u"Surname"), max_length=50) + email = forms.CharField(label=_(u"Email"), max_length=75) + person_types = forms.ChoiceField(label=_(u"Type"), choices=[]) + attached_to = forms.IntegerField( + label=_("Organization"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-organization'), + associated_model=models.Organization), + validators=[models.valid_id(models.Organization)]) + + def __init__(self, *args, **kwargs): + super(IshtarUserSelect, self).__init__(*args, **kwargs) + self.fields['person_types'].choices = models.PersonType.get_types() + + +class AccountFormSelection(forms.Form): + form_label = _(u"Account search") + associated_models = {'pk': models.IshtarUser} + currents = {'pk': models.IshtarUser} + pk = forms.IntegerField( + label="", + widget=widgets.JQueryJqGrid(reverse_lazy('get-ishtaruser'), + IshtarUserSelect, models.IshtarUser), + validators=[models.valid_id(models.IshtarUser)]) + + class BasePersonForm(forms.ModelForm): class Meta: model = models.Person @@ -427,11 +472,11 @@ class AccountForm(forms.Form): raise forms.ValidationError(_(u"You must provide a correct " u"password.")) # check username unicity - usernames = models.IshtarUser.objects.filter( + q = models.IshtarUser.objects.filter( username=cleaned_data.get('username')) if cleaned_data.get('pk'): - usernames.exclude(pk=cleaned_data.get('pk')) - if usernames.count(): + q = q.exclude(person__pk=cleaned_data.get('pk')) + if q.count(): raise forms.ValidationError(_(u"This username already exists.")) return cleaned_data -- cgit v1.2.3