Exemple #1
0
 def post(self, request, *args, **kwargs):
     dep_profile_form = UpdateDEPProfileForm(
         request.POST,
         prefix="dp",
         instance=self.object
     )
     enrollment_secret_form = EnrollmentSecretForm(
         request.POST,
         prefix="es",
         instance=self.object.enrollment_secret,
         no_restrictions=True,
         meta_business_unit=self.meta_business_unit,
     )
     if dep_profile_form.is_valid() and enrollment_secret_form.is_valid():
         dep_profile = dep_profile_form.save(commit=False)
         dep_profile.enrollment_secret = enrollment_secret_form.save()
         enrollment_secret_form.save_m2m()
         try:
             add_dep_profile(dep_profile)
         except DEPClientError as error:
             dep_profile_form.add_error(None, str(error))
         else:
             return HttpResponseRedirect(dep_profile.get_absolute_url())
     return self.render_to_response(
         self.get_context_data(dep_profile_form=dep_profile_form,
                               enrollment_secret_form=enrollment_secret_form)
     )
Exemple #2
0
 def post(self, request, *args, **kwargs):
     dep_enrollment_form = UpdateDEPEnrollmentForm(request.POST,
                                                   prefix="de",
                                                   instance=self.object)
     enrollment_secret_form = EnrollmentSecretForm(
         request.POST,
         prefix="es",
         instance=self.object.enrollment_secret,
         no_restrictions=True,
     )
     if dep_enrollment_form.is_valid() and enrollment_secret_form.is_valid(
     ):
         dep_enrollment = dep_enrollment_form.save(commit=False)
         dep_enrollment.enrollment_secret = enrollment_secret_form.save()
         enrollment_secret_form.save_m2m()
         try:
             add_dep_profile(dep_enrollment)
         except DEPClientError as error:
             dep_enrollment_form.add_error(None, str(error))
         else:
             return redirect(dep_enrollment)
     return self.render_to_response(
         self.get_context_data(
             dep_enrollment_form=dep_enrollment_form,
             enrollment_secret_form=enrollment_secret_form))
Exemple #3
0
 def form_valid(self, form):
     dep_profile = form.save(commit=False)
     try:
         add_dep_profile(dep_profile)
     except DEPClientError as error:
         form.add_error(None, str(error))
         return self.form_invalid(form)
     return HttpResponseRedirect(dep_profile.get_absolute_url())