1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Implemented recursive regions with django-mptt

This commit is contained in:
Jeremy Stretch
2017-02-28 14:15:15 -05:00
parent f3b9930dea
commit 9313ba08ed
11 changed files with 80 additions and 26 deletions

View File

@@ -2,6 +2,8 @@ import csv
import itertools
import re
from mptt.forms import TreeNodeMultipleChoiceField
from django import forms
from django.conf import settings
from django.core.urlresolvers import reverse_lazy
@@ -365,7 +367,7 @@ class SlugField(forms.SlugField):
self.widget.attrs['slug-source'] = slug_source
class FilterChoiceField(forms.ModelMultipleChoiceField):
class FilterChoiceFieldMixin(object):
iterator = forms.models.ModelChoiceIterator
def __init__(self, null_option=None, *args, **kwargs):
@@ -374,12 +376,13 @@ class FilterChoiceField(forms.ModelMultipleChoiceField):
kwargs['required'] = False
if 'widget' not in kwargs:
kwargs['widget'] = forms.SelectMultiple(attrs={'size': 6})
super(FilterChoiceField, self).__init__(*args, **kwargs)
super(FilterChoiceFieldMixin, self).__init__(*args, **kwargs)
def label_from_instance(self, obj):
label = super(FilterChoiceFieldMixin, self).label_from_instance(obj)
if hasattr(obj, 'filter_count'):
return u'{} ({})'.format(obj, obj.filter_count)
return force_text(obj)
return u'{} ({})'.format(label, obj.filter_count)
return label
def _get_choices(self):
if hasattr(self, '_choices'):
@@ -391,6 +394,14 @@ class FilterChoiceField(forms.ModelMultipleChoiceField):
choices = property(_get_choices, forms.ChoiceField._set_choices)
class FilterChoiceField(FilterChoiceFieldMixin, forms.ModelMultipleChoiceField):
pass
class FilterTreeNodeMultipleChoiceField(FilterChoiceFieldMixin, TreeNodeMultipleChoiceField):
pass
class LaxURLField(forms.URLField):
"""
Custom URLField which allows any valid URL scheme