1 # -*- coding: utf-8 -*-
3 # This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from __future__ import absolute_import
8 from django.db.models import Q
9 from django import template
10 from django.utils.translation import ugettext_lazy as _
11 from catalogue.models import Document
13 register = template.Library()
17 ('publishable', _('publishable'), Q(book___new_publishable=True)),
18 ('changed', _('changed'), Q(_changed=True)),
19 ('published', _('published'), Q(book___published=True)),
20 ('unpublished', _('unpublished'), Q(book___published=False)),
21 ('empty', _('empty'), Q(head=None)),
23 _states_options = [s[:2] for s in _states]
24 _states_dict = dict([(s[0], s[2]) for s in _states])
27 @register.inclusion_tag('catalogue/book_list/book_list.html', takes_context=True)
28 def document_list(context, user=None, organization=None):
29 request = context['request']
32 # filters = {"user": user}
33 # new_context = {"viewed_user": user}
37 # "users": User.objects.annotate(
38 # count=Count('chunk')).filter(count__gt=0).order_by(
39 # '-count', 'last_name', 'first_name'),
40 # "other_users": User.objects.annotate(
41 # count=Count('chunk')).filter(count=0).order_by(
42 # 'last_name', 'first_name'),
45 docs = Document.objects.filter(deleted=False)
48 Q(owner_user=user) | Q(owner_organization__membership__user=user) | Q(assigned_to=user)).distinct()
49 if organization is not None:
50 docs = docs.filter(owner_organization=organization)
57 # "stages": Chunk.tag_model.objects.all(),
58 # "states": _states_options,
64 @register.inclusion_tag('catalogue/book_list/book.html', takes_context=True)
65 def document_short_html(context, doc):
66 user = context['request'].user
68 'am_owner':doc.can_edit(user),