implement collection chooser on document listing

pull/2243/merge
Matt Westcott 2016-02-16 16:48:46 +00:00
rodzic 8466055e93
commit 48a817f9c3
3 zmienionych plików z 38 dodań i 1 usunięć

Wyświetl plik

@ -9,6 +9,12 @@
termInput: "#id_q", termInput: "#id_q",
targetOutput: "#document-results" targetOutput: "#document-results"
} }
$(function() {
$('#collection_chooser_collection_id').change(function() {
this.form.submit();
})
});
</script> </script>
{% endblock %} {% endblock %}
@ -23,6 +29,14 @@
{% endif %} {% endif %}
<div class="nice-padding"> <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"> <div id="document-results" class="documents">
{% include "wagtaildocs/documents/results.html" %} {% include "wagtaildocs/documents/results.html" %}
</div> </div>

Wyświetl plik

@ -22,6 +22,10 @@
{% search_other %} {% search_other %}
{% else %} {% else %}
{% url 'wagtaildocs:add' as wagtaildocs_add_document_url %} {% url 'wagtaildocs:add' as wagtaildocs_add_document_url %}
{% 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> <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 %}
{% endif %} {% endif %}

Wyświetl plik

@ -8,6 +8,7 @@ from wagtail.wagtailadmin.forms import SearchForm
from wagtail.wagtailadmin.utils import PermissionPolicyChecker, permission_denied from wagtail.wagtailadmin.utils import PermissionPolicyChecker, permission_denied
from wagtail.wagtailsearch.backends import get_search_backends from wagtail.wagtailsearch.backends import get_search_backends
from wagtail.wagtailadmin import messages from wagtail.wagtailadmin import messages
from wagtail.wagtailcore.models import Collection
from wagtail.wagtaildocs.models import get_document_model from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtaildocs.forms import get_document_form from wagtail.wagtaildocs.forms import get_document_form
@ -34,6 +35,16 @@ def index(request):
ordering = '-created_at' ordering = '-created_at'
documents = documents.order_by(ordering) 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 # Search
query_string = None query_string = None
if 'q' in request.GET: if 'q' in request.GET:
@ -47,6 +58,12 @@ def index(request):
# Pagination # Pagination
paginator, documents = paginate(request, documents) 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 # Create response
if request.is_ajax(): if request.is_ajax():
return render(request, 'wagtaildocs/documents/results.html', { return render(request, 'wagtaildocs/documents/results.html', {
@ -65,6 +82,8 @@ def index(request):
'search_form': form, 'search_form': form,
'popular_tags': Document.popular_tags(), 'popular_tags': Document.popular_tags(),
'user_can_add': permission_policy.user_has_permission(request.user, 'add'), 'user_can_add': permission_policy.user_has_permission(request.user, 'add'),
'collections': collections,
'current_collection': current_collection,
}) })