def form_valid(self, form): kext_policy = form.save(commit=False) kext_policy.meta_business_unit = self.meta_business_unit kext_policy.save() form.save_m2m() transaction.on_commit(lambda: send_mbu_device_notifications(kext_policy.meta_business_unit)) return HttpResponseRedirect(kext_policy.get_absolute_url())
def form_valid(self, form): existing_kext_policies = (KernelExtensionPolicy.objects.select_for_update() .filter(meta_business_unit=self.meta_business_unit)) # there should be at most a trashed one. try: instance = existing_kext_policies[0] except IndexError: pass else: form.instance = instance kext_policy = form.save(commit=False) kext_policy.meta_business_unit = self.meta_business_unit kext_policy.trashed_at = None kext_policy.save() form.save_m2m() transaction.on_commit(lambda: send_mbu_device_notifications(kext_policy.meta_business_unit)) return HttpResponseRedirect(kext_policy.get_absolute_url())
def forms_valid(self, secret_form, enrollment_form): # make secret secret = secret_form.save() # make enrollment enrollment = enrollment_form.save(commit=False) enrollment.version = 0 enrollment.secret = secret enrollment.save() enrollment_form.save_m2m() # MDM enrollment package mep = MDMEnrollmentPackage.objects.create( meta_business_unit=secret.meta_business_unit, builder=self.builder_key, enrollment_pk=enrollment.pk ) # link from enrollment to mdm enrollment package, for config update propagation enrollment.distributor = mep enrollment.save() # build package and package manifest via callback call transaction.on_commit(lambda: send_mbu_device_notifications(mep.meta_business_unit)) return HttpResponseRedirect(mep.get_absolute_url())
def delete(self, request, *args, **kwargs): self.object = self.get_object() self.object.trashed_at = timezone.now() self.object.save() transaction.on_commit(lambda: send_mbu_device_notifications(self.object.meta_business_unit)) return HttpResponseRedirect(reverse("mdm:mbu", args=(self.object.meta_business_unit.pk,)))
def form_valid(self, form): self.configuration_profile = form.save() transaction.on_commit(lambda: send_mbu_device_notifications(self.meta_business_unit)) return super().form_valid(form)