def get(self, *args, **kwargs): """Display signup form """ context = { 'company_form': CompanyForm(), 'signup_form': SignupForm(), } return render(self.request, self.template_name, context)
def post(self, *args, **kwargs): company_form = CompanyForm(self.request.POST, self.request.FILES) signup_form = SignupForm(self.request.POST, self.request.FILES) if signup_form.is_valid() and company_form.is_valid(): company = company_form.save(commit=False) user = signup_form.save(commit=False) company.save() user.company = company user.save() messages.error( self.request, 'Account successfully created. Activate your account from the admin.' ) return redirect('index') else: context = { 'company_form': CompanyForm(self.request.POST), 'signup_form': SignupForm(self.request.POST), } return render(self.request, self.template_name, context)
def get(self, *args, **kwargs): """Display form """ user = get_object_or_404(User, pk=kwargs['user_id']) if self.request.user == user: context = { 'company_form': CompanyForm(instance=user.company), 'user_form': UserUpdateForm(instance=user), } return render(self.request, self.template_name, context=context) else: raise Http404("Does not exist")
def post(self, request, *args, **kwargs): """Update a user """ user = get_object_or_404(User, pk=kwargs['user_id']) user_form = UserUpdateForm(self.request.POST, self.request.FILES, instance=user) company_form = CompanyForm(self.request.POST, self.request.FILES, instance=user.company) if user_form.is_valid() and company_form.is_valid(): company_form.save() user_form.save() messages.success(self.request, 'User is successfully updated') return redirect('index') else: context = { 'company_form': company_form, 'user_form': user_form, } return render(self.request, self.template_name, context=context)