Private
Public Access
1
0

Merge branch 'feature/blogposts' into develop

This commit is contained in:
Sander Roosendaal
2018-10-25 08:25:01 +02:00
7 changed files with 160 additions and 27 deletions

View File

@@ -92,6 +92,10 @@
<li class="grid_5">
<p class="midden">and more</p>
</li>
</ul>
<ul class="main-content" id="id_blogs">
</ul>
<ul class="main-content">
<li>
&nbsp;
</li>
@@ -137,3 +141,37 @@
{% endblock %}
{% block scripts %}
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
<script>
$( document ).ready(function() {
console.log('loading script');
$.getJSON(window.location.protocol + '//'+window.location.host + '/getblogs', function(data) {
var html = '';
if (data.length != 0) {
html += '<li class="grid_5"><div class="midden"><img src="/static/img/horizontal_line.png" alt="horizontal line"></div></li> '
html += '<li class="grid_5"><h2 class="midden">Recent articles on the Analytics blog</h2></li>';
html += '<li></li>';
};
$.each(data, function(key, blog) {
console.log(blog.title);
html += '<li class="frontitem">';
html += '<a style="text-decoration: none; color: black;" href="'+blog.link+'">';
html += '<h3 class="midden">'+blog.title+'</h3>';
html += '<p class="midden"><img src="'+blog.image+'" height=150px;></p>';
html += '<p>'+blog.excerpt+'</p>';
html += '</a>';
html += '</li>';
});
if (data.length != 0) {
html += '<li></li>';
};
$("#id_blogs").html(html);
});
});
</script>
{% endblock %}

View File

@@ -0,0 +1,17 @@
{% load staticfiles %}
{% load rowerfilters %}
{% for blog in blogposts %}
<li class="frontitem">
<h3 class="midden">{{ blog.title|safe }}</h3>
<p class="midden">
<img src={{ blog.image }} height=150px;>
</p>
{{ blog.excerpt|safe }}
<p class="midden">
<a href={{ blog.link }}>
read more
</a>
</p>
</li>
{% endfor %}

View File

@@ -25,8 +25,12 @@ from pyparsing import ParseException
from uuid import uuid4
import codecs
import isodate
import re
import cgi
from django.shortcuts import render
from django.template.loader import render_to_string
from django.views.generic.edit import UpdateView,DeleteView
@@ -654,6 +658,65 @@ def get_thumbnails(request,id):
return JSONResponse(charts)
def get_blog_posts(request):
response = requests.get(
'https://analytics.rowsandall.com/wp-json/wp/v2/posts')
if response.status_code == 200:
blogs_json = response.json()
# with open('blogs.txt','w') as o:
# o.write(json.dumps(blogs_json,indent=2,sort_keys=True))
else:
blogs_json = []
blogposts = []
for postdata in blogs_json[0:3]:
try:
featuredmedia = postdata['featured_media']
url = 'https://analytics.rowsandall.com/wp-json/wp/v2/media/%d' % featuredmedia
response = requests.get(url)
if response.status_code == 200:
image_json = response.json()
image_url = image_json[
'media_details'
][
'sizes'
][
'thumbnail'
][
'source_url'
]
except KeyError:
image_url = ''
title = postdata['title']['rendered'].encode(
'ascii','xmlcharrefreplace')
excerpt = postdata['excerpt']['rendered'].encode(
'ascii','xmlcharrefreplace')
ptester = re.compile('\<p\>(\w.*)\<\/p\>')
excerpt_first = ptester.match(excerpt).group(1)
thedict = {
'title': title,
'author': '',
'image': image_url,
'excerpt': excerpt_first,
'link': postdata['link'],
}
blogposts.append(thedict)
return JSONResponse(blogposts)
@login_required()
def deactivate_user(request):
pk = request.user.id

View File

@@ -58,6 +58,7 @@ urlpatterns += [
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^$',rootview),
url(r'^getblogs$',rowersviews.get_blog_posts),
url(r'^login/',auth_views.login, name='login'),
url(r'^logout/$',auth_views.logout,
{'next_page': '/'},

View File

@@ -1,4 +1,5 @@
from django.shortcuts import render, redirect, render_to_response
from django.template.loader import render_to_string
from django.template import RequestContext
from django.conf import settings
from rowers.forms import LoginForm
@@ -6,10 +7,10 @@ from django.http import HttpResponse
from rowingdata import main as rmain
import requests
import json
import random
def rootview(request):
magicsentence = rmain()
loginform = LoginForm()
@@ -56,15 +57,6 @@ def rootview(request):
'text':'Rowsandall.com is the ideal platform for remote rowing coaching. As a coach, you can easily manage your athletes, set up plans and monitor execution and technique'
}
response = requests.get(
'https://analytics.rowsandall.com/wp-json/wp/v2/posts')
if response.status_code == 200:
blogs_json = response.json()
# with open('blogs.txt','w') as o:
# o.write(json.dumps(blogs_json,indent=2,sort_keys=True))
else:
blogs_json = []
allofferings = [

View File

@@ -324,6 +324,28 @@ th.rotate > div > span {
z-index: -1;
}
.vignet2 {
border-radius: 50%;
width: 200px;
height: 200px;
display: block;
overflow: hidden;
padding: 5px;
margin: 5px;
-webkit-box-shadow: inset 0px 0px 85px rgba(0,0,0,0.4);
-moz-box-shadow: inset 0px 0px 85px rgba(0,0,0,0.4);
box-shadow: inset 0px 0px 85px rgba(0,0,0,0.4);
line-height: 0; /* ensure no space between bottom */
}
.vignet2 img {
position: center;
z-index: -1;
}
.button {
font: 1.1em/1.5em sans-serif;
text-decoration: none;