Merge branch 'UtkucanBykl-233'

This commit is contained in:
Alvaro Mariano 2023-05-22 21:05:37 -03:00
commit 37decfbd4f
3 changed files with 27 additions and 0 deletions

View file

@ -5,6 +5,7 @@
- new setting 'CACHE_TIMEOUT' to cache certain result such as "notifications.unread().count".
(a timeout value of 0 wont cache anything).
- #263 Fix vunerability in views
- #233 Adds methods to convert to human readable type
## 1.7.0

View file

@ -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)

View file

@ -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 '''