Пример #1
0
 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')
Пример #2
0
 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')
Пример #3
0
 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')
Пример #4
0
 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')
Пример #5
0
 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')