def form_valid(self, form): self.object = form.save(commit=False) try: form = kickstart.vlan_create(form) if form.cleaned_data['active']: VLAN.objects.all().update(active=False) self.object.activate() log_form_valid(self) messages.success(self.request, 'VLAN {0} added to Kickstart!'.format(self.object)) return super(Create, self).form_valid(form) except Exception as msg: featherfail(self, msg) return super(Create, self).form_invalid(form)
def form_valid(self, form): try: if self.object.client.count() is 0: kickstart.vlan_delete(self.object) form = kickstart.vlan_create(form) if form.cleaned_data['active']: VLAN.objects.all().update(active=False) self.object.activate() log_form_valid(self) messages.success(self.request, 'Changes saved!') return super(Update, self).form_valid(form) except Exception as msg: featherfail(self, msg) return super(Update, self).form_invalid(form)