{% block rightcolumn %}
{% render_comment_list for book %}
-{% render_comment_form for book %}
+{% with book.get_absolute_url as next %}
+ {% render_comment_form for book %}
+{% endwith %}
{% endblock rightcolumn %}
{% load i18n %}
{% load pagination_tags %}
-{% load catalogue %}
+{% load set_get_parameter catalogue %}
{% block extrabody %}
{{ block.super }}
<script type="text/javascript" charset="utf-8">
$(function() {
- function search(event) {
- event.preventDefault();
- var expr = new RegExp(slugify($('#file-list-filter').val()), 'i');
- $('#file-list tbody tr').hide().filter(function(index) {
- return expr.test(slugify( $('a', this).attr('data-id') ));
- }).show();
- }
-
- $('#file-list-find-button').click(search).hide();
- $('#file-list-filter').bind('keyup change DOMAttrModified', search);
+ $("select.filter").change(function() {
+ window.location.href = this.value;
+ });
});
</script>
{% endblock %}
{% block leftcolumn %}
- <form method="get" action="#">
- <table>
- <thead>
- <tr><th>Filtr:</th>
- <th><input autocomplete="off" name="filter" id="file-list-filter" type="text" size="40" /></th>
- <th><input type="reset" value="{% trans "Clear filter" %}" id="file-list-reset-button"/></th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </form>
-
-
- <form method="get" action="#">
+ <form method="get" action="#">
<table id="file-list">
- <tbody>
+ <thead><tr>
+ <th></th>
+ <th></th>
+ <th></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>
+ {% 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>
+ {% endfor %}
+ </select></th>
+ <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>
+ {% 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>
+ {% endfor %}
+ </select></th>
+ </tr></thead>
+
+ <tbody>
{% autopaginate books 100 %}
{% if not books %}
<tr><td>{% trans "No books found." %}</td></tr>
{% endif %}
- {% for item in books %}
+ {% for item in books %}
{% with item.book as book %}
{% ifequal item.book_length 1 %}
<td><a target="_blank"
href="{% url wiki_editor book.slug %}">
{{ book.title }}</a></td>
- <td>({{ chunk.stage }})</td>
- <td>{% if chunk.user %}<a href="{% url catalogue_user chunk.user.username %}">{{ chunk.user.first_name }} {{ chunk.user.last_name }}</a>{% endif %}</td>
+ <td>{% if chunk.stage %}
+ ({{ chunk.stage }})
+ {% endif %}</td>
+ <td>{% if chunk.user %}{{ chunk.user.first_name }} {{ chunk.user.last_name }}{% endif %}</td>
</tr>
{% endwith %}
{% else %}
--- /dev/null
+from re import split
+
+from django import template
+
+register = template.Library()
+
+
+"""
+In template:
+ {% set_get_paramater param1='const_value',param2=,param3=variable %}
+results with changes to query string:
+ param1 is set to `const_value' string
+ param2 is unset, if exists,
+ param3 is set to the value of variable in context
+
+Using 'django.core.context_processors.request' is required.
+
+"""
+
+
+class SetGetParameter(template.Node):
+ def __init__(self, values):
+ self.values = values
+
+ def render(self, context):
+ request = template.Variable('request').resolve(context)
+ params = request.GET.copy()
+ for key, value in self.values.items():
+ if value == '':
+ if key in params:
+ del(params[key])
+ else:
+ params[key] = template.Variable(value).resolve(context)
+ return '?%s' % params.urlencode()
+
+
+@register.tag
+def set_get_parameter(parser, token):
+ parts = split(r'\s+', token.contents, 2)
+
+ values = {}
+ for pair in parts[1].split(','):
+ s = pair.split('=')
+ values[s[0]] = s[1]
+
+ return SetGetParameter(values)
logger = logging.getLogger("fnp.catalogue")
+def slug_filter(qs, value, filter_field, model, model_field='slug', unset=''):
+ if value == unset:
+ return qs.filter(**{filter_field: None})
+ if value is None:
+ return qs
+ try:
+ obj = model._default_manager.get(**{model_field: value})
+ except model.DoesNotExist:
+ return qs.none()
+ else:
+ return qs.filter(**{filter_field: obj})
+
+
@active_tab('all')
@never_cache
-def document_list(request):
- chunks_list = helpers.ChunksList(Chunk.objects.order_by(
- 'book__title', 'book', 'number'))
+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_list = helpers.ChunksList(chunks)
return direct_to_template(request, 'catalogue/document_list.html', extra_context={
'books': chunks_list,
- #'books': [helpers.BookChunks(b) for b in Book.objects.all().select_related()],
'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'),
})
changes = self.tree.change_set.exclude(parent=None).filter(
revision__lte=self.revision).order_by('revision')
- text = u''
+ text = ''
for change in changes:
text = change.apply_to(text)
- return text
+ return text.decode('utf-8')
def make_child(self, patch, description, author=None,
author_name=None, author_email=None, tags=None):
body {
margin: 0;
font-family: verdana, sans-serif;
- font-size: 12px;
+ font-size: 10px;
}
-#wiki_layout_left_column {
+#catalogue_layout_left_column {
overflow: visible;
float: left;
/*max-width: 50%;*/
}
-#wiki_layout_right_column {
+#catalogue_layout_right_column {
float: left;
max-width: 35%;
margin-left: 5%;