X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f4921ca797953ddab6b35786864b2dd523190503..9249e6ddc35e7cc7077fa5035fbc27397fbb70a9:/apps/wiki/views.py?ds=inline diff --git a/apps/wiki/views.py b/apps/wiki/views.py index a68fa35d..7bff1a05 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -7,12 +7,15 @@ from lxml import etree from django.conf import settings +from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required +from django.db.models import Count from django.views.generic.simple import direct_to_template from django.views.decorators.http import require_POST, require_GET from django.core.urlresolvers import reverse from wiki.helpers import (JSONResponse, JSONFormInvalid, JSONServerError, - ajax_require_permission, recursive_groupby) + ajax_require_permission, recursive_groupby, active_tab) +from wiki import helpers from django import http from django.shortcuts import get_object_or_404, redirect from django.http import Http404 @@ -41,15 +44,72 @@ import operator MAX_LAST_DOCS = 10 +@active_tab('all') @never_cache def document_list(request): return direct_to_template(request, 'wiki/document_list.html', extra_context={ - 'books': Book.objects.all(), + 'books': [helpers.BookChunks(b) for b in Book.objects.all()], 'last_books': sorted(request.session.get("wiki_last_books", {}).items(), key=lambda x: x[1]['time'], reverse=True), }) +@active_tab('unassigned') +@never_cache +def unassigned(request): + chunks = Chunk.objects.filter(user=None).order_by('book__title', 'book', 'number') + books = [] + book = None + for chunk in chunks: + if chunk.book != book: + book = chunk.book + books.append(helpers.ChoiceChunks(book, [chunk])) + else: + books[-1].chunks.append(chunk) + + return direct_to_template(request, 'wiki/document_list.html', extra_context={ + 'books': books, + 'last_books': sorted(request.session.get("wiki_last_books", {}).items(), + key=lambda x: x[1]['time'], reverse=True), + }) + + +@never_cache +def user(request, username=None): + if username is None: + if request.user.is_authenticated(): + user = request.user + else: + raise Http404 + else: + user = get_object_or_404(User, username=username) + + chunks = Chunk.objects.filter(user=user).order_by('book__title', 'number') + books = [] + book = None + for chunk in chunks: + if chunk.book != book: + book = chunk.book + books.append(helpers.ChoiceChunks(book, [chunk])) + else: + books[-1].chunks.append(chunk) + + return direct_to_template(request, 'wiki/document_list.html', extra_context={ + 'books': books, + 'last_books': sorted(request.session.get("wiki_last_books", {}).items(), + key=lambda x: x[1]['time'], reverse=True), + }) +my = login_required(active_tab('my')(user)) + + +@active_tab('users') +def users(request): + return direct_to_template(request, 'wiki/user_list.html', extra_context={ + 'users': User.objects.all().annotate(count=Count('document')).order_by( + '-count', 'last_name', 'first_name'), + }) + + @never_cache def editor(request, slug, chunk=None, template_name='wiki/document_details.html'): try: @@ -118,7 +178,10 @@ def editor_readonly(request, slug, chunk=None, template_name='wiki/document_deta }) -def create_missing(request, slug): +@active_tab('create') +def create_missing(request, slug=None): + if slug is None: + slug = '' slug = slug.replace(' ', '-') if request.method == "POST": @@ -148,6 +211,7 @@ def create_missing(request, slug): }) +@active_tab('upload') def upload(request): if request.method == "POST": form = forms.DocumentsUploadForm(request.POST, request.FILES)