Skip to content

Commit

Permalink
Merge pull request #15 from hacklabr/develop
Browse files Browse the repository at this point in the history
Develop into master
  • Loading branch information
frclba authored Apr 29, 2020
2 parents 3294f98 + 880f35f commit 716c286
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
16 changes: 0 additions & 16 deletions discussion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,3 @@ def create_or_update_revision(self, instance):
self.comment = instance
self.text = instance.text
super(CommentHistory, self).create_or_update_revision(instance)


class UnreadNotification(models.Model):

user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name='user', on_delete=models.CASCADE)
counter = models.IntegerField(null=True, blank=True)

def save(self, *args, **kwargs):
if not self.pk:
# This is a new unread counter
# All AnswerNotification and TopicNotification will be used to create the first unread counter for this user
# However, counting only the unread TopicNotification instances is enough, since every AnswerNotification also has a row in the TopicNotification table
self.counter = TopicNotification.objects.filter(
user=self.user,
is_read=False).count()
super(UnreadNotification, self).save(*args, **kwargs)
14 changes: 2 additions & 12 deletions discussion/signals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from discussion.models import Comment, CommentHistory, TopicNotification, TopicLike, TopicUse, CommentLike, UnreadNotification
from discussion.models import Comment, CommentHistory, TopicNotification, TopicLike, TopicUse, CommentLike
from courses_notifications.models import unread_notification_increment


@receiver(post_save, sender=Comment)
Expand Down Expand Up @@ -194,17 +195,6 @@ def comment_reaction_created_or_updated(instance, **kwargs):
# unread_notification_increment(one_user)


def unread_notification_increment(user):
# Only increment the counter if the user already has a UnreadNotification instance
try:
unread = UnreadNotification.objects.get(user=user)
unread.counter += 1
unread.save()
except UnreadNotification.DoesNotExist:
pass



def topic_viewed(request, topic):
# Todo test detail views
user = request.user
Expand Down
13 changes: 2 additions & 11 deletions discussion/static/js/discussion-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'ngAnimate',
'duScroll',
'LocalStorageModule',
'shared'
'shared',
'djangular'
]);

// Set new default values for 'duScroll'
Expand Down Expand Up @@ -55,14 +56,4 @@
otherwise('/');
}
]);

app.run(function($http, localStorageService) {
$http.defaults.headers.common.Authorization = 'Token ' + localStorageService.get('ujs-ocupa|token');
});

app.service('CurrentUser', ['localStorageService', function (localStorageService) {
console.log(localStorageService.get('ujs-ocupa|currentProfile'));
return localStorageService.get('ujs-ocupa|currentProfile');
}]);

})(angular);

0 comments on commit 716c286

Please sign in to comment.