2016-07-26 14:58:37 -04:00
|
|
|
from django import forms
|
2016-09-20 11:08:25 -04:00
|
|
|
from django.db.models import Count
|
2016-07-26 14:58:37 -04:00
|
|
|
|
2016-08-23 12:05:28 -04:00
|
|
|
from extras.forms import CustomFieldForm, CustomFieldBulkEditForm, CustomFieldFilterForm
|
2016-09-20 11:08:25 -04:00
|
|
|
from utilities.forms import BootstrapMixin, BulkImportForm, CommentField, CSVDataField, FilterChoiceField, SlugField
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
from .models import Tenant, TenantGroup
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tenant groups
|
|
|
|
#
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class TenantGroupForm(BootstrapMixin, forms.ModelForm):
|
2016-07-26 14:58:37 -04:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TenantGroup
|
|
|
|
fields = ['name', 'slug']
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tenants
|
|
|
|
#
|
|
|
|
|
2016-08-15 15:24:23 -04:00
|
|
|
class TenantForm(BootstrapMixin, CustomFieldForm):
|
2016-07-26 14:58:37 -04:00
|
|
|
slug = SlugField()
|
|
|
|
comments = CommentField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Tenant
|
2016-07-26 17:44:32 -04:00
|
|
|
fields = ['name', 'slug', 'group', 'description', 'comments']
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TenantFromCSVForm(forms.ModelForm):
|
2016-08-02 16:04:25 -04:00
|
|
|
group = forms.ModelChoiceField(TenantGroup.objects.all(), required=False, to_field_name='name',
|
2016-07-26 14:58:37 -04:00
|
|
|
error_messages={'invalid_choice': 'Group not found.'})
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Tenant
|
2016-07-26 17:47:40 -04:00
|
|
|
fields = ['name', 'slug', 'group', 'description']
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2016-12-21 14:15:18 -05:00
|
|
|
class TenantImportForm(BootstrapMixin, BulkImportForm):
|
2016-07-26 14:58:37 -04:00
|
|
|
csv = CSVDataField(csv_form=TenantFromCSVForm)
|
|
|
|
|
|
|
|
|
2016-08-22 13:11:57 -04:00
|
|
|
class TenantBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
2016-07-26 14:58:37 -04:00
|
|
|
pk = forms.ModelMultipleChoiceField(queryset=Tenant.objects.all(), widget=forms.MultipleHiddenInput)
|
2016-09-30 16:17:41 -04:00
|
|
|
group = forms.ModelChoiceField(queryset=TenantGroup.objects.all(), required=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
nullable_fields = ['group']
|
2016-07-26 14:58:37 -04:00
|
|
|
|
|
|
|
|
2016-08-23 12:05:28 -04:00
|
|
|
class TenantFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|
|
|
model = Tenant
|
2016-09-20 11:08:25 -04:00
|
|
|
group = FilterChoiceField(queryset=TenantGroup.objects.annotate(filter_count=Count('tenants')),
|
|
|
|
to_field_name='slug', null_option=(0, 'None'))
|