Add date formatting
This commit is contained in:
parent
30214dd834
commit
9d3450463e
5 changed files with 20 additions and 9 deletions
|
@ -49,7 +49,8 @@ class BlogViewTestCase(TestCase):
|
|||
"title": "Test Blog Post",
|
||||
"ID": 1,
|
||||
"content": "<p>Test blog post content</p>",
|
||||
"slug": "test-post"
|
||||
"slug": "test-post",
|
||||
"date": "2000-01-01T18:05:00+00:00"
|
||||
}
|
||||
|
||||
def test_accessable(self, m):
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,12 +3,16 @@
|
|||
{% block pageTitle %}{{ html_title }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
{{ blog.content | safe}}
|
||||
<div class="col-xs-4 pull-right">
|
||||
<h5>Published: {{ blog.date }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
{{ blog.content | safe }}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue