mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-05-20 10:21:53 +00:00
Change 'readed' field to unread.
Add a better manager/queryset. (required django-model-utils).
This commit is contained in:
parent
55c4701d1b
commit
d8567930b4
5 changed files with 25 additions and 16 deletions
|
|
@ -1,9 +0,0 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class NotificationManager(models.Manager):
|
||||
def unread_count(self, user):
|
||||
return self.filter(recipient=user, readed=False).count()
|
||||
|
||||
def mark_all_as_read(self, recipient):
|
||||
return self.filter(recipient=recipient, readed=False).update(readed=True)
|
||||
|
|
@ -6,15 +6,28 @@ from django.contrib.contenttypes import generic
|
|||
from django.db import models
|
||||
from django.utils.timezone import utc
|
||||
from .utils import id2slug
|
||||
from notifications.managers import NotificationManager
|
||||
|
||||
from notifications.signals import notify
|
||||
|
||||
from model_utils import managers
|
||||
|
||||
try:
|
||||
from django.utils import timezone
|
||||
now = timezone.now
|
||||
except ImportError:
|
||||
now = datetime.datetime.now
|
||||
|
||||
class NotificationQuerySet(models.query.QuerySet):
|
||||
def unread(self):
|
||||
return self.filter(unread=True)
|
||||
|
||||
# Should we return self on these?
|
||||
def mark_all_as_read(self):
|
||||
self.update(unread=False)
|
||||
|
||||
def mark_all_as_unread(self):
|
||||
self.update(unread=True)
|
||||
|
||||
class Notification(models.Model):
|
||||
"""
|
||||
Action model describing the actor acting out a verb (on an optional
|
||||
|
|
@ -43,9 +56,9 @@ class Notification(models.Model):
|
|||
|
||||
<a href="http://oebfare.com/">brosner</a> commented on <a href="http://github.com/pinax/pinax">pinax/pinax</a> 2 hours ago
|
||||
|
||||
"""
|
||||
"""
|
||||
recipient = models.ForeignKey(User, blank=False, related_name='notifications')
|
||||
readed = models.BooleanField(default=False, blank=False)
|
||||
unread = models.BooleanField(default=True, blank=False)
|
||||
|
||||
actor_content_type = models.ForeignKey(ContentType, related_name='notify_actor')
|
||||
actor_object_id = models.CharField(max_length=255)
|
||||
|
|
@ -71,7 +84,7 @@ class Notification(models.Model):
|
|||
|
||||
public = models.BooleanField(default=True)
|
||||
|
||||
objects = NotificationManager()
|
||||
objects = managers.PassThroughManager.for_queryset_class(NotificationQuerySet)()
|
||||
|
||||
class Meta:
|
||||
ordering = ('-timestamp', )
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<div class="act">
|
||||
<div class="body">
|
||||
<div class="title">
|
||||
<i class="{% if action.readed %}icon-mail{% else %}icon-mail-alt{% endif %}"></i>
|
||||
<i class="{% if action.unread %}icon-mail-alt{% else %}icon-mail{% endif %}"></i>
|
||||
{% if action.actor.get_absolute_url %}
|
||||
<a href="{{ action.actor.get_absolute_url }}">{{ action.actor }}</a>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ from django.template import Node
|
|||
|
||||
register = Library()
|
||||
|
||||
# TODO: Simplify this: it's a really simple tag!
|
||||
|
||||
class InboxCountNode(Node):
|
||||
"For use in the notifications_unread tag"
|
||||
def __init__(self, asvar=None):
|
||||
|
|
@ -21,7 +23,7 @@ class InboxCountNode(Node):
|
|||
if user.is_anonymous():
|
||||
count = ''
|
||||
else:
|
||||
count = Notification.objects.unread_count(user)
|
||||
count = user.notifications.unread().count()
|
||||
except (KeyError, AttributeError):
|
||||
count = ''
|
||||
if self.asvar:
|
||||
|
|
|
|||
5
setup.py
5
setup.py
|
|
@ -1,13 +1,16 @@
|
|||
from distutils.core import setup
|
||||
from notifications import __version__
|
||||
|
||||
setup(name='django-notifications-hq',
|
||||
setup(name='django-notifications',
|
||||
version=__version__,
|
||||
description='GitHub notifications alike app for Django.',
|
||||
long_description=open('README.rst').read(),
|
||||
author='Brant Young',
|
||||
author_email='brant.young@gmail.com',
|
||||
url='http://github.com/brantyoung/django-notifications',
|
||||
install_requires=[
|
||||
'django-model-utils>=1.1.0'
|
||||
],
|
||||
packages=['notifications',
|
||||
'notifications.templatetags'],
|
||||
package_data={'notifications': [
|
||||
|
|
|
|||
Loading…
Reference in a new issue