예제 #1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context["mdm"] = True
     context["meta_business_unit"] = self.meta_business_unit
     dep_profile_form = kwargs.get("dep_profile_form")
     if not dep_profile_form:
         dep_profile_form = CreateDEPProfileForm(prefix="dp")
     context["dep_profile_form"] = dep_profile_form
     enrollment_secret_form = kwargs.get("enrollment_secret_form")
     if not enrollment_secret_form:
         enrollment_secret_form = EnrollmentSecretForm(
             prefix="es",
             no_restrictions=True,
             meta_business_unit=self.meta_business_unit,
         )
     context["enrollment_secret_form"] = enrollment_secret_form
     return context
예제 #2
0
 def post(self, request, *args, **kwargs):
     dep_profile_form = CreateDEPProfileForm(request.POST, prefix="dp")
     enrollment_secret_form = EnrollmentSecretForm(
         request.POST,
         prefix="es",
         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)
     )