mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-04-25 15:34:43 +00:00
Merge branch 'UtkucanBykl-233'
This commit is contained in:
commit
37decfbd4f
3 changed files with 27 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
- new setting 'CACHE_TIMEOUT' to cache certain result such as "notifications.unread().count".
|
||||
(a timeout value of 0 won’t cache anything).
|
||||
- #263 Fix vunerability in views
|
||||
- #233 Adds methods to convert to human readable type
|
||||
|
||||
## 1.7.0
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,16 @@ class Notification(AbstractNotification):
|
|||
class Meta(AbstractNotification.Meta):
|
||||
abstract = False
|
||||
swappable = swappable_setting('notifications', 'Notification')
|
||||
|
||||
def naturalday(self):
|
||||
"""
|
||||
Shortcut for the ``humanize``.
|
||||
Take a parameter humanize_type. This parameter control the which humanize method use.
|
||||
Return ``today``, ``yesterday`` ,``now``, ``2 seconds ago``etc.
|
||||
"""
|
||||
from django.contrib.humanize.templatetags.humanize import naturalday
|
||||
return naturalday(self.timestamp)
|
||||
|
||||
def naturaltime(self):
|
||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||
return naturaltime(self.timestamp)
|
||||
|
|
@ -74,6 +74,19 @@ class NotificationTest(TestCase):
|
|||
delta = timezone.now() - notification.timestamp
|
||||
self.assertTrue(delta.seconds < 60)
|
||||
|
||||
def test_humanize_naturalday_timestamp(self):
|
||||
from_user = User.objects.create(username="from2", password="pwd", email="example@example.com")
|
||||
to_user = User.objects.create(username="to2", password="pwd", email="example@example.com")
|
||||
notify.send(from_user, recipient=to_user, verb='commented', action_object=from_user)
|
||||
notification = Notification.objects.get(recipient=to_user)
|
||||
self.assertEqual(notification.naturalday(), 'today')
|
||||
|
||||
def test_humanize_naturaltime_timestamp(self):
|
||||
from_user = User.objects.create(username="from2", password="pwd", email="example@example.com")
|
||||
to_user = User.objects.create(username="to2", password="pwd", email="example@example.com")
|
||||
notify.send(from_user, recipient=to_user, verb='commented', action_object=from_user)
|
||||
notification = Notification.objects.get(recipient=to_user)
|
||||
self.assertEqual(notification.naturaltime(), 'now')
|
||||
|
||||
class NotificationManagersTest(TestCase):
|
||||
''' Django notifications Manager automated tests '''
|
||||
|
|
|
|||
Loading…
Reference in a new issue