Skip to content

Commit d45a35d

Browse files
committed
Remove nice_datetime utility and timestamp on template.
1 parent 04994e0 commit d45a35d

3 files changed

Lines changed: 2 additions & 47 deletions

File tree

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
from datetime import timedelta
2-
31
from django.core.paginator import Paginator
42
from django.template import Library
5-
from django.utils import timezone
6-
7-
from project.newsletter.models import Post
83

94
register = Library()
105

@@ -15,19 +10,3 @@ def is_ellipsis(value):
1510
Determine if the value is an ellipsis
1611
"""
1712
return value == Paginator.ELLIPSIS
18-
19-
20-
@register.inclusion_tag("inclusion_tags/nice_datetime.html")
21-
def nice_datetime(post: Post, is_unread: bool):
22-
"""
23-
Format the datetime in the locale the user prefers with styling.
24-
"""
25-
now = timezone.now()
26-
week_ago = timezone.now() - timedelta(days=7)
27-
timestamp = post.publish_date
28-
is_recent = week_ago <= timestamp <= now
29-
return {
30-
"is_unread": is_unread,
31-
"is_recent": is_recent,
32-
"timestamp": timestamp,
33-
}
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
1-
from datetime import timedelta
2-
31
from django.core.paginator import Paginator
4-
from django.test import SimpleTestCase, TestCase
5-
from django.utils import timezone
2+
from django.test import SimpleTestCase
63

7-
from project.newsletter.models import Post
8-
from project.newsletter.templatetags.newsletter_utils import is_ellipsis, nice_datetime
4+
from project.newsletter.templatetags.newsletter_utils import is_ellipsis
95

106

117
class TestIsEllipsis(SimpleTestCase):
128
def test_is_ellipsis(self):
139
self.assertTrue(is_ellipsis(Paginator.ELLIPSIS))
1410
self.assertFalse(is_ellipsis("..."))
15-
16-
17-
class TestNiceDatetime(TestCase):
18-
def test_nice_datetime(self):
19-
post = Post(created=timezone.now())
20-
actual = nice_datetime(post, is_unread=True)
21-
22-
self.assertEqual(
23-
actual, {"timestamp": post.created, "is_recent": True, "is_unread": True}
24-
)
25-
26-
post.publish_at = timezone.now() - timedelta(days=7, minutes=1)
27-
actual = nice_datetime(post, is_unread=False)
28-
self.assertEqual(
29-
actual,
30-
{"timestamp": post.publish_at, "is_recent": False, "is_unread": False},
31-
)

project/templates/posts/includes/list_item.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{% load martortags %}
2-
{% load newsletter_utils %}
32

43
<h3 class="ui header">{{ post.title }}</h3>
54

6-
75
<div class="ui grid middle aligned">
86
<div class="left floated six wide column">
9-
{% nice_datetime post=post is_unread=post.is_unread %}
107
</div>
118
<div class="right floated six wide column">
129
<span class="ui small text">

0 commit comments

Comments
 (0)