Commit dbc5e43b98b386a5d6b31c09290539255b6054db

Authored by Zambom
1 parent 12a840b7

Adding datetime for mural viewed

goals/migrations/0003_auto_20170227_2014.py 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2017-02-27 23:14
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.db import migrations, models
  6 +
  7 +
  8 +class Migration(migrations.Migration):
  9 +
  10 + dependencies = [
  11 + ('goals', '0002_auto_20170224_1721'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.AlterField(
  16 + model_name='goalitem',
  17 + name='description',
  18 + field=models.CharField(blank=True, max_length=255, verbose_name='Description'),
  19 + ),
  20 + ]
... ...
mural/migrations/0009_muralvisualizations_date_viewed.py 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2017-02-27 23:14
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.db import migrations, models
  6 +
  7 +
  8 +class Migration(migrations.Migration):
  9 +
  10 + dependencies = [
  11 + ('mural', '0008_auto_20170224_0023'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.AddField(
  16 + model_name='muralvisualizations',
  17 + name='date_viewed',
  18 + field=models.DateTimeField(blank=True, null=True, verbose_name='Date/Time Viewed'),
  19 + ),
  20 + ]
... ...
mural/models.py
... ... @@ -118,6 +118,7 @@ class MuralVisualizations(models.Model):
118 118 post = models.ForeignKey(Mural, verbose_name = _('Post'), related_name = 'visualization_post', null = True)
119 119 comment = models.ForeignKey(Comment, verbose_name = _('Comment'), related_name = 'visualization_comment', null = True)
120 120 user = models.ForeignKey(User, verbose_name = _('User'), related_name = "visualization_user", null = True)
  121 + date_viewed = models.DateTimeField(_('Date/Time Viewed'), null = True, blank = True)
121 122  
122 123 """
123 124 Model to handle users favorite posts
... ...
mural/views.py
... ... @@ -23,6 +23,7 @@ from log.models import Log
23 23 from log.mixins import LogMixin
24 24 from log.decorators import log_decorator, log_decorator_ajax
25 25 import time
  26 +from datetime import datetime
26 27  
27 28 from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites, Comment
28 29 from .forms import GeneralPostForm, CategoryPostForm, SubjectPostForm, ResourcePostForm, CommentForm
... ... @@ -77,9 +78,9 @@ class GeneralIndex(LoginRequiredMixin, LogMixin, generic.ListView):
77 78 self.totals['category'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & ((Q(user__is_staff = True) & (Q(post__categorypost__isnull = False) | Q(comment__post__categorypost__isnull = False))) | Q(post__categorypost__space__coordinators = user) | Q(comment__post__categorypost__space__coordinators = user) | Q(post__categorypost__space__subject_category__students = user) | Q(comment__post__categorypost__space__subject_category__students = user) | Q(post__categorypost__space__subject_category__professor = user) | Q(comment__post__categorypost__space__subject_category__professor = user))).distinct().count()
78 79 self.totals['subject'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & ((Q(user__is_staff = True) & (Q(post__subjectpost__isnull = False) | Q(comment__post__subjectpost__isnull = False))) | Q(post__subjectpost__space__professor = user) | Q(comment__post__subjectpost__space__professor = user) | Q(post__subjectpost__space__students = user) | Q(comment__post__subjectpost__space__students = user))).distinct().count()
79 80  
80   - general_visualizations.update(viewed = True)
  81 + general_visualizations.update(viewed = True, date_viewed = datetime.now())
81 82  
82   - MuralVisualizations.objects.filter(user = user, viewed = False, comment__post__generalpost__isnull = False).update(viewed = True)
  83 + MuralVisualizations.objects.filter(user = user, viewed = False, comment__post__generalpost__isnull = False).update(viewed = True, date_viewed = datetime.now())
83 84  
84 85 return general.order_by("-most_recent")
85 86  
... ... @@ -315,7 +316,7 @@ def load_category_posts(request, category):
315 316 if has_page is None:
316 317 views = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(comment__post__categorypost__space__id = category) | Q(post__categorypost__space__id = category)))
317 318 n_views = views.count()
318   - views.update(viewed = True)
  319 + views.update(viewed = True, date_viewed = datetime.now())
319 320  
320 321 paginator = Paginator(posts.order_by("-most_recent"), 10)
321 322  
... ... @@ -604,7 +605,7 @@ def load_subject_posts(request, subject):
604 605 if has_page is None:
605 606 views = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(comment__post__subjectpost__space__id = subject) | Q(post__subjectpost__space__id = subject)))
606 607 n_views = views.count()
607   - views.update(viewed = True)
  608 + views.update(viewed = True, date_viewed = datetime.now())
608 609  
609 610 paginator = Paginator(posts.order_by("-most_recent"), 10)
610 611  
... ... @@ -941,7 +942,7 @@ class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView):
941 942 posts = posts.exclude(id__in = showing)
942 943  
943 944 if not page: #Don't need this if is pagination
944   - MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space = subject) | Q(comment__post__subjectpost__space = subject))).update(viewed = True)
  945 + MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space = subject) | Q(comment__post__subjectpost__space = subject))).update(viewed = True, date_viewed = datetime.now())
945 946  
946 947 return posts.order_by("-most_recent")
947 948  
... ... @@ -1054,7 +1055,7 @@ class ResourceView(LoginRequiredMixin, LogMixin, generic.ListView):
1054 1055 posts = posts.exclude(id__in = showing)
1055 1056  
1056 1057 if not page: #Don't need this if is pagination
1057   - MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__resource = resource) | Q(comment__post__subjectpost__resource = resource))).update(viewed = True)
  1058 + MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__resource = resource) | Q(comment__post__subjectpost__resource = resource))).update(viewed = True, date_viewed = datetime.now())
1058 1059  
1059 1060 return posts.order_by("-most_recent")
1060 1061  
... ...