1
Fork 0

Add date formatting

This commit is contained in:
Jake Howard 2016-02-20 23:06:49 +00:00
parent 30214dd834
commit 9d3450463e
5 changed files with 20 additions and 9 deletions

View file

@ -49,7 +49,8 @@ class BlogViewTestCase(TestCase):
"title": "Test Blog Post", "title": "Test Blog Post",
"ID": 1, "ID": 1,
"content": "<p>Test blog post content</p>", "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): def test_accessable(self, m):

View file

@ -1,4 +1,4 @@
import requests import requests, iso8601
from django.conf import settings from django.conf import settings
API_PATH = "https://public-api.wordpress.com/rest/v1.1/sites/{0}/posts/slug:{1}" API_PATH = "https://public-api.wordpress.com/rest/v1.1/sites/{0}/posts/slug:{1}"
@ -19,3 +19,7 @@ def get_post(slug):
return return
data = response.json() data = response.json()
return data if "ID" in data else False return data if "ID" in data else False
def reformat_date(iso_date):
return iso8601.parse_date(iso_date).strftime("%x %I:%M")

View file

@ -1,5 +1,5 @@
from project.common.views import CustomTemplate from project.common.views import CustomTemplate
from .utils import get_post from .utils import get_post, reformat_date
from django.http import Http404 from django.http import Http404
@ -9,6 +9,7 @@ class BlogView(CustomTemplate):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['blog'] = self.blog_data context['blog'] = self.blog_data
context['blog']['date'] = reformat_date(self.blog_data['date'])
return context return context
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):

View file

@ -8,6 +8,7 @@ git+https://github.com/RealOrangeOne/django-client-reverse
django-flat-theme==1.1.3 django-flat-theme==1.1.3
djangorestframework==3.3.2 djangorestframework==3.3.2
flake8==2.5.0 flake8==2.5.0
iso8601==0.1.11
markdown2==2.3.0 markdown2==2.3.0
max-django-mail-templated==1.2 max-django-mail-templated==1.2
requests==2.9.1 requests==2.9.1

View file

@ -3,12 +3,16 @@
{% block pageTitle %}{{ html_title }}{% endblock %} {% block pageTitle %}{{ html_title }}{% endblock %}
{% block content %} {% block content %}
<div class="container">
<div class="container">
<div class="row"> <div class="row">
<div class="col-sm-8"> <div class="col-xs-4 pull-right">
{{ blog.content | safe}} <h5>Published: {{ blog.date }}</h5>
</div> </div>
</div> </div>
</div> </div>
<div class="container">
{{ blog.content | safe }}
</div>
{% endblock %} {% endblock %}