def delete(self, request, *args, **kwargs): instance = get_object(self.model, self.kwargs['pk']) if instance is not None: self.model.objects.filter(id=self.kwargs['pk']).update( model_state=False) return redirect(self.success_url) else: return redirect(self.success_url)
def get(self, request, form=None, *args, **kwargs): self.template_name = build_template_name(self.template_name, self.model, 'update') form = get_form(form, self.model) form = form(instance=get_object(self.model, self.kwargs['pk'])) context = self.get_context_data() if context['object'] == None: return redirect(self.success_url) context['form'] = form return render(request, self.template_name, context)
def delete(self,request,model,*args,**kwargs): self.model = model # login required validation validation_login_required,response = self.validate_login_required() if validation_login_required: return response # permission required validation validation_permissions,response = self.validate_permissions() if validation_permissions: return response instance = get_object(self.model,self.kwargs['pk']) if instance is not None: self.model.objects.filter(id = self.kwargs['pk']).update(model_state = False) return success_delete_message(self.model) return not_found_message(self.model)
def post(self, request, form=None, *args, **kwargs): self.template_name = build_template_name(self.template_name, self.model, 'list') form = get_form(form, self.model) instance = get_object(self.model, self.kwargs['pk']) if instance is not None: if self.form_class == None: form = form(request.POST, request.FILES, instance=instance) else: form = self.form_class(request.POST, request.FILES, instance=instance) if form.is_valid(): form.save() return redirect(self.success_url) else: form = self.form_class() context = {'form': form} return render(request, self.template_name, context) else: return redirect(self.success_url)
def post(self,request,model,form = None,*args,**kwargs): self.model = model # login required validation validation_login_required,response = self.validate_login_required() if validation_login_required: return response # permission required validation validation_permissions,response = self.validate_permissions() if validation_permissions: return response self.form_class = get_form(form,self.model) instance = get_object(self.model,self.kwargs['pk']) if instance is not None: form = self.form_class(request.POST,request.FILES,instance = instance) if form.is_valid(): form.save() return success_update_message(self.model) else: return error_update_message(self.model,form) return not_found_message(self.model)
def get(self,request,model,*args,**kwargs): self.model = model # login required validation validation_login_required,response = self.validate_login_required() if validation_login_required: return response # permission required validation validation_permissions,response = self.validate_permissions() if validation_permissions: return response self.data = get_object(self.model,self.kwargs['pk']) if self.data is not None: self.data = serialize( 'json',[self.data,], fields = self.get_fields_for_model(), use_natural_foreign_keys = True, use_natural_primary_keys = True ) self.normalize_data() return HttpResponse(self.data, content_type="application/json") return not_found_message(self.model)
def get_context_data(self, **kwargs): context = {} context['object'] = get_object(self.model, self.kwargs['pk']) return context