0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

implement collection chooser on document listing

This commit is contained in:
Matt Westcott 2016-02-16 16:48:46 +00:00
parent 8466055e93
commit 48a817f9c3
3 changed files with 38 additions and 1 deletions

View File

@ -9,6 +9,12 @@
termInput: "#id_q",
targetOutput: "#document-results"
}
$(function() {
$('#collection_chooser_collection_id').change(function() {
this.form.submit();
})
});
</script>
{% endblock %}
@ -23,6 +29,14 @@
{% endif %}
<div class="nice-padding">
{% if collections %}
<form class="image-search search-bar" action="{% url 'wagtaildocs:index' %}" method="GET">
<ul class="fields">
{% include "wagtailadmin/shared/collection_chooser.html" %}
</ul>
</form>
{% endif %}
<div id="document-results" class="documents">
{% include "wagtaildocs/documents/results.html" %}
</div>

View File

@ -22,6 +22,10 @@
{% search_other %}
{% else %}
{% url 'wagtaildocs:add' as wagtaildocs_add_document_url %}
<p>{% blocktrans %}You haven't uploaded any documents. Why not <a href="{{ wagtaildocs_add_document_url }}">upload one now</a>?{% endblocktrans %}</p>
{% if current_collection %}
<p>{% blocktrans %}You haven't uploaded any documents in this collection. Why not <a href="{{ wagtaildocs_add_document_url }}">upload one now</a>?{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans %}You haven't uploaded any documents. Why not <a href="{{ wagtaildocs_add_document_url }}">upload one now</a>?{% endblocktrans %}</p>
{% endif %}
{% endif %}
{% endif %}

View File

@ -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,
})