def document(request, document_id): document = Document.objects.get(pk=document_id) json_context = {} if request.method == 'POST': form = DocumentForm(request.POST, instance=document) if form.is_valid(): document = form.save() json_context['status'] = 'success' json_context['html'] = render_to_string('library/partial_document_summary.html', { 'document': document }) return HttpResponse(json.dumps(json_context), content_type='application/json') else: json_context['status'] = 'error' else: form = DocumentForm(instance=document) json_context['status'] = 'ok' csrf_token = unicode(csrf(request)['csrf_token']) json_context['html'] = render_to_string('library/document.html', { 'form': form, 'csrf_token': csrf_token }) return HttpResponse(json.dumps(json_context), content_type='application/json')
def document(request, document_id): document = Document.objects.get(pk=document_id) json_context = {} if request.method == "POST": form = DocumentForm(request.POST, instance=document) if form.is_valid(): document = form.save() json_context["status"] = "success" json_context["html"] = render_to_string("library/partial_document_summary.html", {"document": document}) return HttpResponse(json.dumps(json_context), content_type="application/json") else: json_context["status"] = "error" else: form = DocumentForm(instance=document) json_context["status"] = "ok" csrf_token = unicode(csrf(request)["csrf_token"]) json_context["html"] = render_to_string("library/document.html", {"form": form, "csrf_token": csrf_token}) return HttpResponse(json.dumps(json_context), content_type="application/json")
def new_document(request): json_context = {} if request.method == 'POST': form = DocumentForm(request.POST) if form.is_valid(): form.instance.user = request.user document = form.save() messages.success(request, 'Document added successfully!') json_context['status'] = 'success' json_context['redirect_to'] = r('library:index') else: json_context['status'] = 'error' else: form = DocumentForm() json_context['status'] = 'ok' csrf_token = unicode(csrf(request)['csrf_token']) html = render_to_string('library/new_document.html', { 'form': form, 'csrf_token': csrf_token }) json_context['html'] = html dump = json.dumps(json_context) return HttpResponse(dump, content_type='application/json')
def new_document(request): json_context = {} if request.method == "POST": form = DocumentForm(request.POST) if form.is_valid(): form.instance.user = request.user document = form.save() messages.success(request, "Document added successfully!") json_context["status"] = "success" json_context["redirect_to"] = r("library:index") else: json_context["status"] = "error" else: form = DocumentForm() json_context["status"] = "ok" csrf_token = unicode(csrf(request)["csrf_token"]) html = render_to_string("library/new_document.html", {"form": form, "csrf_token": csrf_token}) json_context["html"] = html dump = json.dumps(json_context) return HttpResponse(dump, content_type="application/json")
def document(request, document_id): document = Document.objects.get(pk=document_id) json_context = {} if request.method == 'POST': form = DocumentForm(request.POST, instance=document) if form.is_valid(): document = form.save() json_context['status'] = 'success' json_context['html'] = render_to_string( 'library/partial_document_summary.html', {'document': document}) return HttpResponse(json.dumps(json_context), content_type='application/json') else: json_context['status'] = 'error' else: form = DocumentForm(instance=document) json_context['status'] = 'ok' csrf_token = unicode(csrf(request)['csrf_token']) json_context['html'] = render_to_string('library/document.html', { 'form': form, 'csrf_token': csrf_token }) return HttpResponse(json.dumps(json_context), content_type='application/json')