diff --git a/wagtail/wagtaildocs/templates/wagtaildocs/documents/index.html b/wagtail/wagtaildocs/templates/wagtaildocs/documents/index.html index eb0e0dfc56..943c25e937 100644 --- a/wagtail/wagtaildocs/templates/wagtaildocs/documents/index.html +++ b/wagtail/wagtaildocs/templates/wagtaildocs/documents/index.html @@ -9,6 +9,12 @@ termInput: "#id_q", targetOutput: "#document-results" } + + $(function() { + $('#collection_chooser_collection_id').change(function() { + this.form.submit(); + }) + }); {% endblock %} @@ -23,6 +29,14 @@ {% endif %}
{% blocktrans %}You haven't uploaded any documents. Why not upload one now?{% endblocktrans %}
+ {% if current_collection %} +{% blocktrans %}You haven't uploaded any documents in this collection. Why not upload one now?{% endblocktrans %}
+ {% else %} +{% blocktrans %}You haven't uploaded any documents. Why not upload one now?{% endblocktrans %}
+ {% endif %} {% endif %} {% endif %} diff --git a/wagtail/wagtaildocs/views/documents.py b/wagtail/wagtaildocs/views/documents.py index 1691ebf56a..51018f813d 100644 --- a/wagtail/wagtaildocs/views/documents.py +++ b/wagtail/wagtaildocs/views/documents.py @@ -8,6 +8,7 @@ from wagtail.wagtailadmin.forms import SearchForm from wagtail.wagtailadmin.utils import PermissionPolicyChecker, permission_denied from wagtail.wagtailsearch.backends import get_search_backends from wagtail.wagtailadmin import messages +from wagtail.wagtailcore.models import Collection from wagtail.wagtaildocs.models import get_document_model from wagtail.wagtaildocs.forms import get_document_form @@ -34,6 +35,16 @@ def index(request): ordering = '-created_at' documents = documents.order_by(ordering) + # Filter by collection + current_collection = None + collection_id = request.GET.get('collection_id') + if collection_id: + try: + current_collection = Collection.objects.get(id=collection_id) + documents = documents.filter(collection=current_collection) + except (ValueError, Collection.DoesNotExist): + pass + # Search query_string = None if 'q' in request.GET: @@ -47,6 +58,12 @@ def index(request): # Pagination paginator, documents = paginate(request, documents) + collections = permission_policy.collections_user_has_any_permission_for( + request.user, ['add', 'change'] + ) + if len(collections) < 2: + collections = None + # Create response if request.is_ajax(): return render(request, 'wagtaildocs/documents/results.html', { @@ -65,6 +82,8 @@ def index(request): 'search_form': form, 'popular_tags': Document.popular_tags(), 'user_can_add': permission_policy.user_has_permission(request.user, 'add'), + 'collections': collections, + 'current_collection': current_collection, })