Commit ac4841d3cfce094cfed16829d51f4d2e8bffd2fc
1 parent
aa7c77b1
Exists in
master
and in
3 other branches
Adding category notification view update
Showing
3 changed files
with
39 additions
and
3 deletions
Show diff stats
amadeus/static/js/mural_category.js
@@ -42,6 +42,34 @@ $('.mural-category').on('shown.bs.collapse', function(e) { | @@ -42,6 +42,34 @@ $('.mural-category').on('shown.bs.collapse', function(e) { | ||
42 | more.hide(); | 42 | more.hide(); |
43 | } | 43 | } |
44 | 44 | ||
45 | + $('.mural_badge').each(function () { | ||
46 | + var actual = $(this).text(); | ||
47 | + | ||
48 | + if (actual != "+99") { | ||
49 | + actual = parseInt(actual, 10) - data.unviewed; | ||
50 | + | ||
51 | + if (actual <= 0) { | ||
52 | + $(this).hide(); | ||
53 | + } else { | ||
54 | + $(this).text(actual); | ||
55 | + } | ||
56 | + } | ||
57 | + }); | ||
58 | + | ||
59 | + $('.cat_badge').each(function () { | ||
60 | + var actual = $(this).text(); | ||
61 | + | ||
62 | + if (actual != "+99") { | ||
63 | + actual = parseInt(actual, 10) - data.unviewed; | ||
64 | + | ||
65 | + if (actual < 0) { | ||
66 | + actual = 0; | ||
67 | + } | ||
68 | + | ||
69 | + $(this).text(actual); | ||
70 | + } | ||
71 | + }); | ||
72 | + | ||
45 | without.hide(); | 73 | without.hide(); |
46 | } else { | 74 | } else { |
47 | more.hide(); | 75 | more.hide(); |
mural/templates/mural/list_category.html
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | <div id="core-subjects-options-div"> | 17 | <div id="core-subjects-options-div"> |
18 | <ul class="core-subjects-options"> | 18 | <ul class="core-subjects-options"> |
19 | <a href="{% url 'mural:manage_general' %}"><li>{% trans "General" %} ({{ totals.general }})</li></a> | 19 | <a href="{% url 'mural:manage_general' %}"><li>{% trans "General" %} ({{ totals.general }})</li></a> |
20 | - <a href="{% url 'mural:manage_category' %}"><li class="active">{% trans "Per Category" %} ({{ totals.category }})</li></a> | 20 | + <a href="{% url 'mural:manage_category' %}"><li class="active">{% trans "Per Category" %} (<span class="cat_badge">{{ totals.category }}</span>)</li></a> |
21 | <a href=""><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a> | 21 | <a href=""><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a> |
22 | </ul> | 22 | </ul> |
23 | </div> | 23 | </div> |
mural/views.py
@@ -223,6 +223,7 @@ def load_category_posts(request, category): | @@ -223,6 +223,7 @@ def load_category_posts(request, category): | ||
223 | favorites = request.GET.get('favorite', False) | 223 | favorites = request.GET.get('favorite', False) |
224 | mines = request.GET.get('mine', False) | 224 | mines = request.GET.get('mine', False) |
225 | showing = request.GET.get('showing', '') | 225 | showing = request.GET.get('showing', '') |
226 | + n_views = 0 | ||
226 | 227 | ||
227 | if not favorites: | 228 | if not favorites: |
228 | if mines: | 229 | if mines: |
@@ -239,7 +240,14 @@ def load_category_posts(request, category): | @@ -239,7 +240,14 @@ def load_category_posts(request, category): | ||
239 | showing = showing.split(',') | 240 | showing = showing.split(',') |
240 | posts = posts.exclude(id__in = showing) | 241 | posts = posts.exclude(id__in = showing) |
241 | 242 | ||
242 | - paginator = Paginator(posts.order_by("-most_recent"), 2) | 243 | + has_page = request.GET.get('page', None) |
244 | + | ||
245 | + if has_page is None: | ||
246 | + views = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(comment__post__categorypost__space__id = category) | Q(post__categorypost__space__id = category))) | ||
247 | + n_views = views.count() | ||
248 | + views.update(viewed = True) | ||
249 | + | ||
250 | + paginator = Paginator(posts.order_by("-most_recent"), 10) | ||
243 | 251 | ||
244 | try: | 252 | try: |
245 | page_number = int(request.GET.get('page', 1)) | 253 | page_number = int(request.GET.get('page', 1)) |
@@ -255,7 +263,7 @@ def load_category_posts(request, category): | @@ -255,7 +263,7 @@ def load_category_posts(request, category): | ||
255 | 263 | ||
256 | response = render_to_string("mural/_list_view.html", context, request) | 264 | response = render_to_string("mural/_list_view.html", context, request) |
257 | 265 | ||
258 | - return JsonResponse({"posts": response, "count": posts.count(), "num_pages": paginator.num_pages, "num_page": page_obj.number}) | 266 | + return JsonResponse({"posts": response, "unviewed": n_views, "count": posts.count(), "num_pages": paginator.num_pages, "num_page": page_obj.number}) |
259 | 267 | ||
260 | class CategoryIndex(LoginRequiredMixin, generic.ListView): | 268 | class CategoryIndex(LoginRequiredMixin, generic.ListView): |
261 | login_url = reverse_lazy("users:login") | 269 | login_url = reverse_lazy("users:login") |