diff --git a/project/blog/tests.py b/project/blog/tests.py index 5dab360..6cd6fce 100644 --- a/project/blog/tests.py +++ b/project/blog/tests.py @@ -49,7 +49,8 @@ class BlogViewTestCase(TestCase): "title": "Test Blog Post", "ID": 1, "content": "

Test blog post content

", - "slug": "test-post" + "slug": "test-post", + "date": "2000-01-01T18:05:00+00:00" } def test_accessable(self, m): diff --git a/project/blog/utils.py b/project/blog/utils.py index e6987ce..a2af234 100644 --- a/project/blog/utils.py +++ b/project/blog/utils.py @@ -1,4 +1,4 @@ -import requests +import requests, iso8601 from django.conf import settings API_PATH = "https://public-api.wordpress.com/rest/v1.1/sites/{0}/posts/slug:{1}" @@ -19,3 +19,7 @@ def get_post(slug): return data = response.json() return data if "ID" in data else False + + +def reformat_date(iso_date): + return iso8601.parse_date(iso_date).strftime("%x %I:%M") diff --git a/project/blog/views.py b/project/blog/views.py index 2578942..63c8439 100644 --- a/project/blog/views.py +++ b/project/blog/views.py @@ -1,5 +1,5 @@ from project.common.views import CustomTemplate -from .utils import get_post +from .utils import get_post, reformat_date from django.http import Http404 @@ -9,6 +9,7 @@ class BlogView(CustomTemplate): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['blog'] = self.blog_data + context['blog']['date'] = reformat_date(self.blog_data['date']) return context def dispatch(self, request, *args, **kwargs): diff --git a/requirements.txt b/requirements.txt index 00ddf1e..7c2b0b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ git+https://github.com/RealOrangeOne/django-client-reverse django-flat-theme==1.1.3 djangorestframework==3.3.2 flake8==2.5.0 +iso8601==0.1.11 markdown2==2.3.0 max-django-mail-templated==1.2 requests==2.9.1 diff --git a/templates/blog/posts.html b/templates/blog/posts.html index 7c0ff69..c8180e2 100644 --- a/templates/blog/posts.html +++ b/templates/blog/posts.html @@ -3,12 +3,16 @@ {% block pageTitle %}{{ html_title }}{% endblock %} {% block content %} - -
-
-
- {{ blog.content | safe}} +
+
+
+
Published: {{ blog.date }}
+
-
+ +
+ {{ blog.content | safe }} +
+ {% endblock %}