-def book(request, slug):
- book = get_object_or_404(Book, slug=slug)
-
- # do we need some automation?
- some_wl = False
- first_master = None
- chunks = []
-
- for chunk in book:
- graded = GradedText(chunk.materialize())
- chunk_dict = {
- "chunk": chunk,
- "graded": graded,
- }
- if graded.is_wl():
- some_wl = True
- master = graded.master()
- if first_master is None:
- first_master = master
- elif master != first_master:
- chunk_dict['bad_master'] = master
- chunks.append(chunk_dict)
-
- return direct_to_template(request, "wiki/book_detail.html", extra_context={
- "book": book,
- "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,
- })
-
-