+ "chunks": chunks,
+ "some_wl": some_wl,
+ "first_master": first_master,
+ })
+
+
+def chunk_add(request, slug, chunk):
+ try:
+ doc = Chunk.get(slug, chunk)
+ except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist):
+ raise Http404
+
+ if request.method == "POST":
+ form = forms.ChunkAddForm(request.POST, instance=doc)
+ if form.is_valid():
+ if request.user.is_authenticated():
+ creator = request.user
+ else:
+ creator = None
+ doc.split(creator=creator,
+ slug=form.cleaned_data['slug'],
+ comment=form.cleaned_data['comment'],
+ )
+
+ return http.HttpResponseRedirect(doc.book.get_absolute_url())
+ else:
+ form = forms.ChunkAddForm(initial={
+ "slug": str(doc.number + 1),
+ "comment": "cz. %d" % (doc.number + 1, ),
+ })
+
+ return direct_to_template(request, "wiki/chunk_add.html", extra_context={
+ "chunk": doc,
+ "form": form,
+ })
+
+
+def chunk_edit(request, slug, chunk):
+ try:
+ doc = Chunk.get(slug, chunk)
+ except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist):
+ raise Http404
+ if request.method == "POST":
+ form = forms.ChunkForm(request.POST, instance=doc)
+ if form.is_valid():
+ form.save()
+ return http.HttpResponseRedirect(doc.book.get_absolute_url())
+ else:
+ form = forms.ChunkForm(instance=doc)
+ return direct_to_template(request, "wiki/chunk_edit.html", extra_context={
+ "chunk": doc,
+ "form": form,
+ })
+
+
+def book_append(request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if request.method == "POST":
+ form = forms.BookAppendForm(request.POST)
+ if form.is_valid():
+ append_to = form.cleaned_data['append_to']
+ append_to.append(book)
+ return http.HttpResponseRedirect(append_to.get_absolute_url())
+ else:
+ form = forms.BookAppendForm()
+ return direct_to_template(request, "wiki/book_append_to.html", extra_context={
+ "book": book,
+ "form": form,
+ })
+
+
+def book_edit(request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if request.method == "POST":
+ form = forms.BookForm(request.POST, instance=book)
+ if form.is_valid():
+ form.save()
+ return http.HttpResponseRedirect(book.get_absolute_url())
+ else:
+ form = forms.BookForm(instance=book)
+ return direct_to_template(request, "wiki/book_edit.html", extra_context={
+ "book": book,
+ "form": form,