Private
Public Access
1
0

first version with blog posts

This commit is contained in:
Sander Roosendaal
2018-10-24 20:10:53 +02:00
parent f519cdca62
commit 055f128639
7 changed files with 166 additions and 27 deletions

View File

@@ -92,6 +92,16 @@
<li class="grid_5">
<p class="midden">and more</p>
</li>
<li class="grid_5">
<div class="midden">
<img src="/static/img/horizontal_line.png"
alt="horizontal line">
</div>
</li>
</ul>
<ul class="main-content" id="id_blogs">
</ul>
<ul class="main-content">
<li>
&nbsp;
</li>
@@ -119,21 +129,47 @@
<p class="midden">
Compatible with:
<img src="/static/img/stravasquare.png" alt="Strava icon" width="30" height="30">
<img src="/static/img/sporttrackssquare.png" alt="SportTracks icon" width="30" height="30">
<img src="/static/img/c2square.jpg" alt="C2 icon" width="30" height="30">
<img src="/static/img/nksquare.png" alt="NK icon" width="30" height="30">
<img src="/static/img/cnsquare.png" alt="CrewNerd icon" width="30" height="30">
<img src="/static/img/rimsquare.png" alt="RiM icon" width="30" height="30">
<img src="/static/img/rpsquare.png" alt="RowPro icon" width="30" height="30">
<img src="/static/img/essquare.png" alt="ErgStick icon" width="30" height="30">
<img src="/static/img/bcsquare.png" alt="BoatCoach icon" width="30" height="30">
<img src="/static/img/pssquare.png" alt="PainSled icon" width="30" height="30">
<img src="/static/img/coxmate.png" alt="CoxMate icon" width="30" height="30">
<img src="/static/img/ritmo_logo.gif" alt="RitmoTime icon" width="30" height="30">
</p>
<p class="midden">
Compatible with:
<img src="/static/img/stravasquare.png" alt="Strava icon" width="30" height="30">
<img src="/static/img/sporttrackssquare.png" alt="SportTracks icon" width="30" height="30">
<img src="/static/img/c2square.jpg" alt="C2 icon" width="30" height="30">
<img src="/static/img/nksquare.png" alt="NK icon" width="30" height="30">
<img src="/static/img/cnsquare.png" alt="CrewNerd icon" width="30" height="30">
<img src="/static/img/rimsquare.png" alt="RiM icon" width="30" height="30">
<img src="/static/img/rpsquare.png" alt="RowPro icon" width="30" height="30">
<img src="/static/img/essquare.png" alt="ErgStick icon" width="30" height="30">
<img src="/static/img/bcsquare.png" alt="BoatCoach icon" width="30" height="30">
<img src="/static/img/pssquare.png" alt="PainSled icon" width="30" height="30">
<img src="/static/img/coxmate.png" alt="CoxMate icon" width="30" height="30">
<img src="/static/img/ritmo_logo.gif" alt="RitmoTime icon" width="30" height="30">
</p>
{% 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 = '';
console.log(data);
$.each(data, function(key, blog) {
console.log(blog.title);
html += '<li class="frontitem">';
html += '<h3 class="midden">'+blog.title+'</h3>';
html += '<a href="'+blog.link+'">';
html += '<p class="midden"><img src="'+blog.image+'" height=150px;></p>';
html += '</a>';
html += blog.excerpt+'</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

@@ -135,7 +135,7 @@ def courselength(course):
def jsdict(dict,key):
s = dict.get(key)
return mark_safe(json.dumps(s))
@register.filter
def lookup(dict, key):
s = dict.get(key)

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,73 @@ 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:5]:
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 = cgi.escape(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)
# html = render_to_string('frontpageblogs.html',
# {
# 'blogposts':blogposts,
# }
# )
# return JSONResponse({'html':html})
@login_required()
def deactivate_user(request):
pk = request.user.id