import librarian.html
import librarian.text
-from apiclient import api_call
from catalogue import forms
from catalogue import helpers
from catalogue.helpers import active_tab
-from catalogue.models import Book, Chunk
+from catalogue.models import Book, Chunk, BookPublishRecord, ChunkPublishRecord
from catalogue import xml_tools
#
logger = logging.getLogger("fnp.catalogue")
+def slug_filter(qs, value, filter_field, model, model_field='slug', unset=''):
+ if value == unset:
+ return qs.filter(**{filter_field: None})
+ if value is None:
+ return qs
+ try:
+ obj = model._default_manager.get(**{model_field: value})
+ except model.DoesNotExist:
+ return qs.none()
+ else:
+ return qs.filter(**{filter_field: obj})
+
+
@active_tab('all')
@never_cache
-def document_list(request):
- chunks_list = helpers.ChunksList(Chunk.objects.order_by(
- 'book__title', 'book', 'number'))
-
- return direct_to_template(request, 'catalogue/document_list.html', extra_context={
- 'books': chunks_list,
- #'books': [helpers.BookChunks(b) for b in Book.objects.all().select_related()],
- 'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
- key=lambda x: x[1]['time'], reverse=True),
- })
+def document_list(request, filters=None):
+ chunks = Chunk.objects.order_by('book__title', 'book', 'number')
+ chunks = slug_filter(chunks, request.GET.get('user', None), 'user', User, 'username')
+ chunks = slug_filter(chunks, request.GET.get('stage', None), 'stage', Chunk.tag_model, 'slug')
-@active_tab('unassigned')
-@never_cache
-def unassigned(request):
- chunks_list = helpers.ChunksList(Chunk.objects.filter(
- user=None).order_by('book__title', 'book__id', 'number'))
+ chunks_list = helpers.ChunksList(chunks)
return direct_to_template(request, 'catalogue/document_list.html', extra_context={
'books': chunks_list,
'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
key=lambda x: x[1]['time'], reverse=True),
+ 'stages': Chunk.tag_model.objects.all(),
+ 'users': User.objects.annotate(count=Count('chunk')).order_by('-count', 'last_name', 'first_name'),
})
'books': chunks_list,
'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
key=lambda x: x[1]['time'], reverse=True),
+ 'viewed_user': user,
+ 'stages': Chunk.tag_model.objects.all(),
})
my = login_required(active_tab('my')(user))
def publish(request, slug):
book = get_object_or_404(Book, slug=slug)
try:
- ret = api_call(request.user, "books", {"book_xml": book.materialize()})
+ book.publish(request.user)
except BaseException, e:
return http.HttpResponse(e)
else:
- book.last_published = datetime.now()
- book.save()
return http.HttpResponseRedirect(book.get_absolute_url())