{% load i18n %}
{% load pagination_tags %}
-{% load set_get_parameter catalogue %}
+{% load catalogue %}
{% block extrabody %}
{{ block.super }}
<script type="text/javascript" charset="utf-8">
$(function() {
$("select.filter").change(function() {
- window.location.href = this.value;
+ document.filter[this.name].value = this.value;
+ document.filter.submit();
});
+
+ $('#book-search').keypress(function(e)
+ {
+ if (e.which == 13)
+ {
+ document.filter[this.name] = this.value;
+ document.filter.submit();
+ }
+ });
+
});
</script>
{% endblock %}
{% block leftcolumn %}
- <form method="get" action="#">
+ <form name='filter' action=''>
+ <input type='hidden' name="title" value="{{ request.GET.title }}" />
+ <input type='hidden' name="stage" value="{{ request.GET.stage }}" />
+ <input type='hidden' name="user" value="{{ request.GET.user }}" />
+ </form>
+
<table id="file-list">
<thead><tr>
<th></th>
<th></th>
- <th></th>
+ <th id='th-book-search' style='width:300px;'>
+ <form action='#'>
+ <input name="title" class='filter' style='width:300px;' value="{{ request.GET.title }}" />
+ </form>
+ </th>
<th><select name="stage" class="filter">
- <option value="{% set_get_parameter stage=,page= %}">- {% trans "filter by stage" %} -</option>
- <option {% if request.GET.stage == '' %}selected="selected"
- {% endif %}value="{% set_get_parameter stage='',page= %}">- {% trans "empty" %} -</option>
+ <option value=''>- {% trans "filter by stage" %} -</option>
+ <option {% if request.GET.stage == '-' %}selected="selected"
+ {% endif %}value="-">- {% trans "none" %} -</option>
{% for stage in stages %}
<option {% if request.GET.stage == stage.slug %}selected="selected"
- {% endif %}value="{% set_get_parameter stage=stage.slug,page= %}">{{ stage.name }}</option>
+ {% endif %}value="{{ stage.slug }}">{{ stage.name }}</option>
{% endfor %}
</select></th>
{% if not viewed_user %}
<th><select name="user" class="filter">
- <option value="{% set_get_parameter user=,page= %}">- {% trans "filter by user" %} -</option>
- <option {% if request.GET.user == '' %}selected="selected"
- {% endif %}value="{% set_get_parameter user='',page= %}">- {% trans "empty" %} -</option>
+ <option value=''>- {% trans "filter by user" %} -</option>
+ <option {% if request.GET.user == '-' %}selected="selected"
+ {% endif %}value="-">- {% trans "none" %} -</option>
{% for user in users %}
<option {% if request.GET.user == user.username %}selected="selected"
- {% endif %}value="{% set_get_parameter user=user.username,page= %}">{{ user.first_name }} {{ user.last_name }} ({{ user.count }})</option>
+ {% endif %}value="{{ user.username }}">{{ user.first_name }} {{ user.last_name }} ({{ user.count }})</option>
{% endfor %}
</select></th>
{% endif %}
<tr><td colspan="3">{% paginate %}</td></tr>
</tbody>
</table>
- </form>
{% endblock leftcolumn %}
{% block rightcolumn %}
logger = logging.getLogger("fnp.catalogue")
-def slug_filter(qs, value, filter_field, model, model_field='slug', unset=''):
+def foreign_filter(qs, value, filter_field, model, model_field='slug', unset='-'):
if value == unset:
return qs.filter(**{filter_field: None})
- if value is None:
+ if not value:
return qs
try:
obj = model._default_manager.get(**{model_field: value})
return qs.filter(**{filter_field: obj})
+def search_filter(qs, value, filter_field):
+ if not value:
+ return qs
+ return qs.filter(**{"%s__icontains" % filter_field: value})
+
+
@active_tab('all')
@never_cache
def document_list(request, filters=None):
chunks = Chunk.objects.order_by('book__title', 'book', 'number')
- chunks = slug_filter(chunks, request.GET.get('user', None), 'user', User, 'username')
- chunks = slug_filter(chunks, request.GET.get('stage', None), 'stage', Chunk.tag_model, 'slug')
+ chunks = foreign_filter(chunks, request.GET.get('user', None), 'user', User, 'username')
+ chunks = foreign_filter(chunks, request.GET.get('stage', None), 'stage', Chunk.tag_model, 'slug')
+ chunks = search_filter(chunks, request.GET.get('title', None), 'book__title')
chunks_list = helpers.ChunksList(chunks)
+ users = User.objects.annotate(count=Count('chunk')).filter(count__gt=0).order_by('-count', 'last_name', 'first_name')
+ #users = User.objects.annotate(count=Count('chunk')).order_by('-count', 'last_name', 'first_name')
+
+
return direct_to_template(request, 'catalogue/document_list.html', extra_context={
'books': chunks_list,
'last_books': sorted(request.session.get("wiki_last_books", {}).items(),
key=lambda x: x[1]['time'], reverse=True),
'stages': Chunk.tag_model.objects.all(),
- 'users': User.objects.annotate(count=Count('chunk')).order_by('-count', 'last_name', 'first_name'),
+ 'users': users,
})