diff --git a/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/black.sassc b/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/black.sassc index 1c9fafd..d3c3892 100644 Binary files a/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/black.sassc and b/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/black.sassc differ diff --git a/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/red.sassc b/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/red.sassc index 4e79cdc..18dbdce 100644 Binary files a/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/red.sassc and b/amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/red.sassc differ diff --git a/amadeus/static/js/mural_category.js b/amadeus/static/js/mural_category.js index 8c4d513..9eaf308 100644 --- a/amadeus/static/js/mural_category.js +++ b/amadeus/static/js/mural_category.js @@ -14,7 +14,10 @@ $('.mural-category').on('shown.bs.collapse', function(e) { var post_section = $(this).find('.posts'), without = $(this).find('.no-subjects'), - loading = $(this).find('.loading-posts'); + loading = $(this).find('.loading-posts'), + more = $(this).find('.more-posts'), + filters = $(this).find('.post-filters'), + mural = post_section.parent().parent(); if (post_section.children().length == 0) { var url = $(this).find('.mural').data('url'); @@ -28,13 +31,111 @@ $('.mural-category').on('shown.bs.collapse', function(e) { if (data.count > 0) { post_section.append(data.posts); + mural.data('pages', data.num_pages); + mural.data('page', data.num_page); + + setTimeout(function () { postHeightLimits() }, 100); + + if (data.num_page < data.num_pages) { + more.show(); + } else { + more.hide(); + } + without.hide(); } else { + more.hide(); + without.show(); } } }); } + + more.click(function () { + var url = mural.data('url'), + pageNum = mural.data('page'), + numberPages = mural.data('pages'), + favorites = mural.data('fav'), + mine = mural.data('mine'), + showing = new_posts.join(','); + + if (pageNum == numberPages) { + return false + } + + pageNum = pageNum + 1; + + more.hide(); + + loading.show(); + + $.ajax({ + url: url, + data: {'page': pageNum, 'favorite': favorites, 'mine': mine, 'showing': showing}, + dataType: 'json', + success: function (data) { + loading.hide(); + + post_section.append(data.posts); + + mural.data('pages', data.num_pages); + mural.data('page', data.num_page); + + setTimeout(function () { postHeightLimits() }, 100); + + if (data.num_page < data.num_pages) { + more.show(); + } else { + more.hide(); + } + } + }); + }); + + filters.submit(function () { + var favorite = $(this).find("input[name='favorite']").is(':checked') ? "True" : "", + mine = $(this).find("input[name='mine']").is(':checked') ? "True" : "", + url = mural.data('url'); + + post_section.html(''); + + more.hide(); + loading.show(); + + $.ajax({ + url: url, + data: {'favorite': favorite, 'mine': mine}, + dataType: 'json', + success: function (data) { + loading.hide(); + + if (data.count > 0) { + post_section.append(data.posts); + + mural.data('pages', data.num_pages); + mural.data('page', data.num_page); + + if (data.num_page < data.num_pages) { + more.show(); + } else { + more.hide(); + } + + setTimeout(function () { postHeightLimits() }, 100); + + without.hide(); + } else { + without.show(); + } + + mural.data('fav', favorite); + mural.data('mine', mine); + } + }); + + return false; + }); } }); diff --git a/mural/templates/mural/list_category.html b/mural/templates/mural/list_category.html index 186ff5d..5924a22 100644 --- a/mural/templates/mural/list_category.html +++ b/mural/templates/mural/list_category.html @@ -80,9 +80,19 @@ -
+ + + + + diff --git a/mural/views.py b/mural/views.py index a47dce0..5da2b50 100644 --- a/mural/views.py +++ b/mural/views.py @@ -219,11 +219,27 @@ def load_category_posts(request, category): 'request': request, } + user = request.user + favorites = request.GET.get('favorite', False) + mines = request.GET.get('mine', False) showing = request.GET.get('showing', '') - - posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category).order_by("-most_recent") - paginator = Paginator(posts, 10) + if not favorites: + if mines: + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, mural_ptr__user = user) + else: + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category) + else: + if mines: + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user) + else: + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, favorites_post__isnull = False, favorites_post__user = user) + + if showing: #Exclude ajax creation posts results + showing = showing.split(',') + posts = posts.exclude(id__in = showing) + + paginator = Paginator(posts.order_by("-most_recent"), 2) try: page_number = int(request.GET.get('page', 1)) -- libgit2 0.21.2