From: Radek Czajka Date: Tue, 5 Jul 2011 15:05:14 +0000 (+0200) Subject: filtered chunks table, X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/9b3a6ae7c832a9db4e162bc47859b2347b16dac3?ds=inline;hp=-c filtered chunks table, minor fixes --- 9b3a6ae7c832a9db4e162bc47859b2347b16dac3 diff --git a/apps/catalogue/templates/catalogue/book_detail.html b/apps/catalogue/templates/catalogue/book_detail.html index 1c0178c5..aac190ad 100755 --- a/apps/catalogue/templates/catalogue/book_detail.html +++ b/apps/catalogue/templates/catalogue/book_detail.html @@ -99,6 +99,8 @@ {% 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 %} diff --git a/apps/catalogue/templates/catalogue/document_list.html b/apps/catalogue/templates/catalogue/document_list.html index 9a40dfcc..cb458c4f 100644 --- a/apps/catalogue/templates/catalogue/document_list.html +++ b/apps/catalogue/templates/catalogue/document_list.html @@ -2,50 +2,53 @@ {% load i18n %} {% load pagination_tags %} -{% load catalogue %} +{% load set_get_parameter catalogue %} {% block extrabody %} {{ block.super }} {% endblock %} {% block leftcolumn %} -
- - - - - - - - - -
Filtr:
-
- - -
+ - + + + + + + + + + {% autopaginate books 100 %} {% if not books %} {% endif %} - {% for item in books %} + {% for item in books %} {% with item.book as book %} {% ifequal item.book_length 1 %} @@ -56,8 +59,10 @@ $(function() { - - + + {% endwith %} {% else %} diff --git a/apps/catalogue/templatetags/set_get_parameter.py b/apps/catalogue/templatetags/set_get_parameter.py new file mode 100755 index 00000000..b3d44d73 --- /dev/null +++ b/apps/catalogue/templatetags/set_get_parameter.py @@ -0,0 +1,46 @@ +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) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index a44c7e81..9a795a36 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -34,17 +34,35 @@ from django.views.decorators.cache import never_cache 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'), }) diff --git a/apps/dvcs/models.py b/apps/dvcs/models.py index 54492402..177b0d30 100644 --- a/apps/dvcs/models.py +++ b/apps/dvcs/models.py @@ -124,10 +124,10 @@ class Change(models.Model): 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): diff --git a/redakcja/static/css/filelist.css b/redakcja/static/css/filelist.css index 61e6af22..36bffdff 100644 --- a/redakcja/static/css/filelist.css +++ b/redakcja/static/css/filelist.css @@ -9,7 +9,7 @@ body { margin: 0; font-family: verdana, sans-serif; - font-size: 12px; + font-size: 10px; } @@ -58,7 +58,7 @@ body { -#wiki_layout_left_column { +#catalogue_layout_left_column { overflow: visible; float: left; /*max-width: 50%;*/ @@ -67,7 +67,7 @@ body { } -#wiki_layout_right_column { +#catalogue_layout_right_column { float: left; max-width: 35%; margin-left: 5%;
{% trans "No books found." %}
{{ book.title }}({{ chunk.stage }}){% if chunk.user %}{{ chunk.user.first_name }} {{ chunk.user.last_name }}{% endif %}{% if chunk.stage %} + ({{ chunk.stage }}) + {% endif %}{% if chunk.user %}{{ chunk.user.first_name }} {{ chunk.user.last_name }}{% endif %}