def post(self, request, *args, **kwargs): if CommonView.superuser_login(request): form = self.form_class(request.POST) try: if form.is_valid(): form.save(request=request) return HttpResponseRedirect('/projects/') except Exception as e: LogHelper.efail(e) return render(request, self.template_name, {'form': form}) else: return redirect('index')
def delete(request): response = {} if CommonView.superuser_login(request): try: project_id = request.POST.get('id') Projects.objects.get(id=project_id).delete() response['success'] = True response['message'] = "Project deleted successfully" except Exception as e: LogHelper.elog(e) response['success'] = False response['message'] = "Something went wrong. Please try again" return HttpResponse(json.dumps(response), content_type='application/json')
def post(self, request, *args, **kwargs): if CommonView.superuser_login(request): response = {} form = self.form_class(request.POST) form.created_by = request.user parents = Components.objects.filter( Q(parent__isnull=True) | Q(parent_id=0)) response['parents'] = parents response['form'] = form try: if form.is_valid(): form.save(request=request) return HttpResponseRedirect('/components/') except Exception as e: LogHelper.efail(e) return render(request, self.template_name, response) else: return redirect('index')
def get(self, request, *args, **kwargs): if CommonView.superuser_login(request): form = self.form_class return render(request, self.template_name, {'form': form}) else: return redirect('index')
def form_valid(self, form): if CommonView.superuser_login(self.request): form.update(request=self.request) return HttpResponseRedirect(self.get_success_url()) else: return redirect('index')