Skip to content

Commit

Permalink
Closes #716: Add ASN field to site bulk edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 20, 2016
1 parent 9fd9719 commit 96de61d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class SiteImportForm(BulkImportForm, BootstrapMixin):
class SiteBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
pk = forms.ModelMultipleChoiceField(queryset=Site.objects.all(), widget=forms.MultipleHiddenInput)
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
asn = forms.IntegerField(min_value=1, max_value=4294967295, required=False, label='ASN')

class Meta:
nullable_fields = ['tenant']
nullable_fields = ['tenant', 'asn']


class SiteFilterForm(BootstrapMixin, CustomFieldFilterForm):
Expand Down
7 changes: 5 additions & 2 deletions netbox/utilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.core.urlresolvers import reverse
from django.db import transaction, IntegrityError
from django.db.models import ProtectedError
from django.forms import ModelMultipleChoiceField, MultipleHiddenInput, TypedChoiceField
from django.forms import CharField, ModelMultipleChoiceField, MultipleHiddenInput, TypedChoiceField
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.template import TemplateSyntaxError
Expand Down Expand Up @@ -398,7 +398,10 @@ def post(self, request, **kwargs):
fields_to_update = {}
for field in standard_fields:
if field in form.nullable_fields and field in nullified_fields:
fields_to_update[field] = ''
if isinstance(form.fields[field], CharField):
fields_to_update[field] = ''
else:
fields_to_update[field] = None
elif form.cleaned_data[field]:
fields_to_update[field] = form.cleaned_data[field]
updated_count = self.cls.objects.filter(pk__in=pk_list).update(**fields_to_update)
Expand Down

0 comments on commit 96de61d

Please sign in to comment.