- return render(request, "catalogue/book_detail.html", {
- "book": book,
- "publishable": publishable,
- "publishable_error": publish_error,
- "form": form,
- "editable": editable,
+
+@login_required
+def book_schedule(request, pk):
+ book = get_object_or_404(Document, pk=pk, deleted=False)
+ if not book.can_edit(request.user):
+ return HttpResponseForbidden("Not authorized.")
+ if request.method == 'POST':
+ Plan.objects.filter(document=book).delete()
+ for i, (s, name) in enumerate(STAGES):
+ user_id = request.POST.get('s%d-user' % i)
+ deadline = request.POST.get('s%d-deadline' % i) or None
+ Plan.objects.create(document=book, stage=s, user_id=user_id, deadline=deadline)
+
+ book.set_stage(request.POST.get('stage', ''))
+ return redirect('catalogue_user')
+
+ current = {}
+ for p in Plan.objects.filter(document=book):
+ current[p.stage] = (getattr(p.user, 'pk', None), (p.deadline.isoformat() if p.deadline else None))
+
+ schedule = [(i, s, current.get(s, ())) for i, (s, name) in enumerate(STAGES)]
+
+ if book.owner_organization:
+ people = [m.user for m in book.owner_organization.membership_set.exclude(status='pending')]
+ else:
+ people = [book.owner_user]
+ return render(request, 'catalogue/book_schedule.html', {
+ 'book': book,
+ 'schedule': schedule,
+ 'people': people,