def create_topic(request, slug): book = get_object_or_404(Book, slug=slug) if request.method == "POST": topic_form = TopicForm(request.POST) if topic_form.is_valid(): topic = topic_form.save() topic.status = "Waiting" topic.authors.add(request.user) if request.user not in book.authors.all(): book.authors.add(request.user) if request.POST.get("parent"): topic.parent = Topic.objects.get(id=request.POST.get("parent")) topic.display_order = Topic.objects.filter(book=book, parent=topic.parent, shadow__isnull=True).count() topic.save() data = {"error": False, "response": "Topic created"} else: data = {"error": True, "response": topic_form.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') topics = Topic.objects.filter(book=book.id, parent__isnull=True, shadow__isnull=True) return render(request, "docs/topics/create_topic.html", {"book": book, "topics":topics})
def create_topic(request, slug): book = Book.objects.get(slug=slug) if request.method == "POST": topic_form = TopicForm(request.POST) if topic_form.is_valid(): topic = topic_form.save() topic.status = "Waiting" topic.authors.add(request.user) try: Book.objects.get(slug=slug, authors__in=[request.user]) except ObjectDoesNotExist: book.authors.add(request.user) book.save() if request.POST.get("parent"): topic.parent = Topic.objects.get(id=request.POST.get("parent")) topic.save() data = {"error": False, "response": "Topic created"} else: data = {"error": True, "response": topic_form.errors} return HttpResponse(json.dumps(data)) topics = Topic.objects.filter(book=book.id, parent__isnull=True, shadow__isnull=True) return render_to_response("docs/topics/create_topic.html", {"book": book, "topics":topics, "topic": request.GET.get("topic"), "topic_id": request.GET.get("topic_id")})
def edit_topic(request, book_slug, topic_slug): book = get_object_or_404(Book, slug=book_slug) topic = get_object_or_404(Topic, slug=topic_slug) if request.method == "POST": topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.authors.add(request.user) if request.user not in book.authors.all(): book.authors.add(request.user) if request.user not in topic.authors.all(): topic.authors.add(request.user) if request.POST.get('parent'): new_topic.parent = request.POST.get('parent') new_topic.shadow = topic new_topic.save() data = {"error": False, "response": "Topic has been edited Successfully"} else: data = {"error": True, "response": topic_form.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') topics = Topic.objects.filter(book=book.id, parent__isnull=True, shadow__isnull=True) return render(request, "docs/topics/edit_topic.html", {"book": book, "topics":topics, "topic": topic})
def create_content(request, book_slug, topic_slug): topic = Topic.objects.get(slug=topic_slug) book = Book.objects.get(slug=book_slug) if request.POST.get("content"): if not topic.content: topic.content = request.POST.get("content") topic.keywords = request.POST.get("keywords") topic.updated_on = datetime.datetime.now() topic.save() else: topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.keywords = request.POST.get("keywords") new_topic.authors.add(request.user) if request.user not in book.authors.all(): book.authors.add(request.user) if request.POST.get('parent'): topic_inst = Topic.objects.get(id=request.POST.get('parent')) new_topic.parent = topic_inst new_topic.shadow = topic new_topic.content = request.POST.get("content") new_topic.display_order = Topic.objects.filter(book__slug=book_slug, parent=new_topic.parent, shadow=new_topic.shadow).count() new_topic.save() if request.user not in topic.authors.all(): topic.authors.add(request.user) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def edit_topic(request, book_slug, topic_slug): book = get_object_or_404(Book, slug=book_slug) topic = get_object_or_404(Topic, slug=topic_slug) if request.method == "POST": topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.authors.add(request.user) if request.user not in book.authors.all(): book.authors.add(request.user) if request.user not in topic.authors.all(): topic.authors.add(request.user) if request.POST.get('parent'): new_topic.parent = request.POST.get('parent') new_topic.shadow = topic new_topic.save() data = { "error": False, "response": "Topic has been edited Successfully" } else: data = {"error": True, "response": topic_form.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') topics = Topic.objects.filter(book=book.id, parent__isnull=True, shadow__isnull=True) return render(request, "docs/topics/edit_topic.html", { "book": book, "topics": topics, "topic": topic })
def edit_topic(request, book_slug, topic_slug): book = Book.objects.get(slug=book_slug) topic = Topic.objects.get(slug=topic_slug) if request.method == "POST": topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.authors.add(request.user) try: Book.objects.get(slug=book_slug, authors__in=[request.user]) except ObjectDoesNotExist: book.authors.add(request.user) book.save() try: Topic.objects.get(slug=topic_slug, authors__in=[request.user]) except ObjectDoesNotExist: topic.authors.add(request.user) topic.save() if request.POST.get('parent'): new_topic.parent = request.POST.get('parent') new_topic.shadow = topic new_topic.save() data = {"error": False, "response": "Topic has been edited Successfully"} else: data = {"error": True, "response": topic_form.errors} return HttpResponse(json.dumps(data)) topics = Topic.objects.filter(book=book.id, parent__isnull=True, shadow__isnull=True) return render_to_response("docs/topics/edit_topic.html", {"book": book, "topics":topics, "topic": topic})
def create_content(request, book_slug, topic_slug): topic = get_object_or_404(Topic, slug=topic_slug) book = get_object_or_404(Book, slug=book_slug) if request.method == "POST" and request.POST.get("content"): if not topic.content: topic.content = request.POST.get("content") topic.keywords = request.POST.get("keywords") topic.updated_on = datetime.datetime.now() topic.save() else: topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.keywords = request.POST.get("keywords") new_topic.authors.add(request.user) if request.user not in book.authors.all(): book.authors.add(request.user) if request.POST.get('parent'): topic_inst = Topic.objects.get( id=request.POST.get('parent')) new_topic.parent = topic_inst new_topic.shadow = topic new_topic.content = request.POST.get("content") new_topic.display_order = Topic.objects.filter( book__slug=book_slug, parent=new_topic.parent, shadow=new_topic.shadow).count() new_topic.save() if request.user not in topic.authors.all(): topic.authors.add(request.user) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def create_content(request, book_slug, topic_slug): topic = Topic.objects.get(slug=topic_slug) if request.POST.get("content"): if not topic.content: topic.content = request.POST.get("content") topic.save() else: topic_form = TopicForm(request.POST) if topic_form.is_valid(): new_topic = topic_form.save() new_topic.status = "Waiting" new_topic.authors.add(request.user) try: Book.objects.get(slug=book_slug, authors__in=[request.user]) except ObjectDoesNotExist: book.authors.add(request.user) book.save() try: Topic.objects.get(slug=topic_slug, authors__in=[request.user]) except ObjectDoesNotExist: topic.authors.add(request.user) topic.save() if request.POST.get('parent'): new_topic.parent = request.POST.get('parent') new_topic.shadow = topic new_topic.content = request.POST.get("content") new_topic.save() return HttpResponseRedirect(request.META.get('HTTP_REFERER'))