Commit ac4841d3cfce094cfed16829d51f4d2e8bffd2fc

Authored by Zambom
1 parent aa7c77b1

Adding category notification view update

amadeus/static/js/mural_category.js
... ... @@ -42,6 +42,34 @@ $('.mural-category').on('shown.bs.collapse', function(e) {
42 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 73 without.hide();
46 74 } else {
47 75 more.hide();
... ...
mural/templates/mural/list_category.html
... ... @@ -17,7 +17,7 @@
17 17 <div id="core-subjects-options-div">
18 18 <ul class="core-subjects-options">
19 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 21 <a href=""><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a>
22 22 </ul>
23 23 </div>
... ...
mural/views.py
... ... @@ -223,6 +223,7 @@ def load_category_posts(request, category):
223 223 favorites = request.GET.get('favorite', False)
224 224 mines = request.GET.get('mine', False)
225 225 showing = request.GET.get('showing', '')
  226 + n_views = 0
226 227  
227 228 if not favorites:
228 229 if mines:
... ... @@ -239,7 +240,14 @@ def load_category_posts(request, category):
239 240 showing = showing.split(',')
240 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 252 try:
245 253 page_number = int(request.GET.get('page', 1))
... ... @@ -255,7 +263,7 @@ def load_category_posts(request, category):
255 263  
256 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 268 class CategoryIndex(LoginRequiredMixin, generic.ListView):
261 269 login_url = reverse_lazy("users:login")
... ...