Fix client group display in client management
This commit is contained in:
parent
4bf2553888
commit
b376a167ed
4 changed files with 16 additions and 5 deletions
|
@ -9,6 +9,7 @@ from internationalflavor.vat_number.forms import VATNumberFormField
|
|||
|
||||
from core.models.local import Currency
|
||||
from core.models.brands import Brand
|
||||
from core.models.profiles import ClientGroup
|
||||
|
||||
class AdminEditForm(ModelForm):
|
||||
display_name = CharField(required=False, label=_('Internal Display Name'))
|
||||
|
@ -44,12 +45,13 @@ class ClientEditForm(ModelForm):
|
|||
company_id = CharField(label=_('Company Registration Number'), required=False)
|
||||
default_currency = ModelChoiceField(Currency.objects.all(), label=_("Default Currency"))
|
||||
brands = ModelMultipleChoiceField(Brand.objects.all(), label=_("Associated Brands"))
|
||||
client_groups = ModelMultipleChoiceField(ClientGroup.objects.all(), label=_("Client Groups"))
|
||||
marketing_opt_in = BooleanField(label=_("Opted in to marketing messages"), required=False)
|
||||
pgp_key = CharField(label=_("GPG encryption key"), required=False)
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ('first_name', 'last_name', "company", "email", 'mobile', 'address1', 'address2', 'zip', 'city', 'state', 'country', 'vat_id', 'company_id', 'default_currency', 'brands', 'marketing_opt_in', 'pgp_key')
|
||||
fields = ('first_name', 'last_name', "company", "email", 'mobile', 'address1', 'address2', 'zip', 'city', 'state', 'country', 'vat_id', 'company_id', 'default_currency', 'brands', 'client_groups', 'marketing_opt_in', 'pgp_key')
|
||||
|
||||
class ClientCreateForm(ModelForm):
|
||||
company = CharField(required=False, label=_('Company Name'))
|
||||
|
@ -64,10 +66,11 @@ class ClientCreateForm(ModelForm):
|
|||
company_id = CharField(label=_('Company Registration Number'), required=False)
|
||||
default_currency = ModelChoiceField(Currency.objects.all(), label=_("Default Currency"))
|
||||
brands = ModelMultipleChoiceField(Brand.objects.all(), label=_("Associated Brands"))
|
||||
client_groups = ModelMultipleChoiceField(ClientGroup.objects.all(), label=_("Client Groups"))
|
||||
marketing_opt_in = BooleanField(label=_("Opted in to marketing messages"), required=False)
|
||||
pgp_key = CharField(label=_("GPG encryption key"), required=False)
|
||||
send_password = BooleanField(label=_("Send password reset email now?"), required=False)
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ('first_name', 'last_name', "company", "email", 'mobile', 'address1', 'address2', 'zip', 'city', 'state', 'country', 'vat_id', 'company_id', 'default_currency', 'brands', 'marketing_opt_in', 'pgp_key', 'send_password')
|
||||
fields = ('first_name', 'last_name', "company", "email", 'mobile', 'address1', 'address2', 'zip', 'city', 'state', 'country', 'vat_id', 'company_id', 'default_currency', 'brands', 'client_groups', 'marketing_opt_in', 'pgp_key', 'send_password')
|
|
@ -16,6 +16,9 @@ class ClientGroup(Model):
|
|||
name = LongCharField()
|
||||
color = ColorField()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Profile(PolymorphicModel):
|
||||
user = OneToOneField(get_user_model(), CASCADE)
|
||||
mobile = PhoneNumberField(blank=True)
|
||||
|
|
|
@ -145,12 +145,13 @@ class ClientEditView(BackendFormView):
|
|||
initial["company_id"] = client.profile.company_id
|
||||
initial["default_currency"] = client.profile.default_currency
|
||||
initial["brands"] = client.profile.brands.all()
|
||||
initial["client_groups"] = client.profile.client_groups.all()
|
||||
initial["marketing_opt_in"] = bool(client.profile.marketing_opt_in)
|
||||
initial["pgp_key"] = client.profile.pgp_key
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
client = get_user_model().objects.get(id=self.kwargs["pk"])
|
||||
client = ClientProfile.objects.get(id=self.kwargs["pk"]).user
|
||||
client.first_name = form.cleaned_data["first_name"]
|
||||
client.last_name = form.cleaned_data["last_name"]
|
||||
client.username = form.cleaned_data["email"]
|
||||
|
@ -166,6 +167,7 @@ class ClientEditView(BackendFormView):
|
|||
client.profile.company_id = form.cleaned_data["company_id"]
|
||||
client.profile.default_currency = form.cleaned_data["default_currency"]
|
||||
client.profile.brands.set(form.cleaned_data["brands"])
|
||||
client.profile.client_groups.set(form.cleaned_data["client_groups"])
|
||||
client.profile.marketing_opt_in = timezone.now() if form.cleaned_data["marketing_opt_in"] and not client.profile.marketing_opt_in else None
|
||||
client.profile.pgp_key = form.cleaned_data["pgp_key"]
|
||||
|
||||
|
@ -224,6 +226,7 @@ class ClientCreateView(BackendFormView):
|
|||
profile.save()
|
||||
|
||||
profile.brands.set(form.cleaned_data["brands"])
|
||||
profile.client_groups.set(form.cleaned_data["client_groups"])
|
||||
profile.save()
|
||||
|
||||
if form.cleaned_data["send_password"]:
|
||||
|
|
|
@ -38,14 +38,16 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Country</th>
|
||||
<th>Client Groups</th>
|
||||
<th>Options</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for client in object_list %}
|
||||
<tr>
|
||||
<td>{% if client.profile.company %}{{ client.profile.company }}{% else %}{{ client.get_full_name }}{% endif %}</td>
|
||||
<td>{{ client.profile.country }}</td>
|
||||
<td>{% if client.company %}{{ client.company }}{% else %}{{ client.user.get_full_name }}{% endif %}</td>
|
||||
<td>{{ client.country }}</td>
|
||||
<td>{% for group in client.client_groups.all %}{{ group.name }}{% endfor %}</td>
|
||||
<td><a href="{% url "clients_edit" client.id %}"><i class="fas fa-edit" title="Edit Client"></i></a> <a href="{% url "clients_delete" client.id %}"><i style="color: darkred;" class="fas fa-trash-alt" title="Delete Client"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue