Private
Public Access
1
0

Merge tag 'v4.21' into develop

added image width height to image model for FB
This commit is contained in:
Sander Roosendaal
2017-10-10 09:26:00 +02:00
5 changed files with 94 additions and 3 deletions

View File

@@ -584,6 +584,8 @@ class GraphImage(models.Model):
filename = models.CharField(default='',max_length=150,blank=True,null=True) filename = models.CharField(default='',max_length=150,blank=True,null=True)
creationdatetime = models.DateTimeField() creationdatetime = models.DateTimeField()
workout = models.ForeignKey(Workout) workout = models.ForeignKey(Workout)
width = models.IntegerField(default=1200)
height = models.IntegerField(default=600)
def __str__(self): def __str__(self):
return self.filename return self.filename

View File

@@ -9,8 +9,12 @@
{% block og_description %}{{ workout.name }} {% block og_description %}{{ workout.name }}
{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %} {{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %}
{% block og_image %} {% block og_image %}
<meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h1>{{ workout.name }}</h1> <h1>{{ workout.name }}</h1>

View File

@@ -14,7 +14,11 @@
{% block og_image %} {% block og_image %}
{% for graph in graphs1 %} {% for graph in graphs1 %}
<meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% block image_src %} {% block image_src %}

View File

@@ -10,6 +10,8 @@ from rowers.tasks import (
from rowers.models import GraphImage from rowers.models import GraphImage
from PIL import Image
import numpy as np import numpy as np
import yaml import yaml
import argparse import argparse
@@ -181,10 +183,16 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
title,hrpwrdata, title,hrpwrdata,
plotnr,imagename) plotnr,imagename)
try:
width,height = Image.open(fullpathimagename).size
except:
width = 1200
height = 600
i = GraphImage(workout=w, i = GraphImage(workout=w,
creationdatetime=timezone.now(), creationdatetime=timezone.now(),
filename=fullpathimagename) filename=fullpathimagename,
width=width,height=height)
i.save() i.save()
return i.id return i.id

View File

@@ -8,6 +8,7 @@ import pytz
import operator import operator
import warnings import warnings
import urllib import urllib
from PIL import Image
from numbers import Number from numbers import Number
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.db.models import Q from django.db.models import Q
@@ -4594,6 +4595,15 @@ def workout_view(request,id=0):
raise Http404("Not allowed to view this workout") raise Http404("Not allowed to view this workout")
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
r = Rower.objects.get(id=row.user.id) r = Rower.objects.get(id=row.user.id)
u = User.objects.get(id=r.user.id) u = User.objects.get(id=r.user.id)
@@ -5229,6 +5239,15 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
form = WorkoutForm(instance=row) form = WorkoutForm(instance=row)
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
# check if user is owner of this workout # check if user is owner of this workout
if (checkworkoutuser(request.user,row)==False): if (checkworkoutuser(request.user,row)==False):
@@ -5670,6 +5689,15 @@ def workout_advanced_view(request,id=0,message="",successmessage=""):
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
form = WorkoutForm(instance=row) form = WorkoutForm(instance=row)
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
# check if user is owner of this workout # check if user is owner of this workout
if (checkworkoutuser(request.user,row)==False): if (checkworkoutuser(request.user,row)==False):
@@ -6113,6 +6141,15 @@ def workout_export_view(request,id=0, message="", successmessage=""):
form = WorkoutForm(instance=row) form = WorkoutForm(instance=row)
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
# check if user is owner of this workout # check if user is owner of this workout
if (checkworkoutuser(request.user,row)==False): if (checkworkoutuser(request.user,row)==False):
@@ -6253,6 +6290,15 @@ def workout_comment_view(request,id=0):
form = WorkoutCommentForm() form = WorkoutCommentForm()
g = GraphImage.objects.filter(workout=w).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=w).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
if (len(g)<=3): if (len(g)<=3):
return render(request, return render(request,
@@ -6372,6 +6418,16 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
# check if user is owner of this workout # check if user is owner of this workout
comments = WorkoutComment.objects.filter(workout=row) comments = WorkoutComment.objects.filter(workout=row)
@@ -6593,6 +6649,15 @@ def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
# check if user is owner of this workout # check if user is owner of this workout
comments = WorkoutComment.objects.filter(workout=row) comments = WorkoutComment.objects.filter(workout=row)
@@ -7774,6 +7839,14 @@ def graphs_view(request):
def graph_show_view(request,id): def graph_show_view(request,id):
try: try:
g = GraphImage.objects.get(id=id) g = GraphImage.objects.get(id=id)
try:
width,height = Image.open(g.filename).size
g.width = width
g.height = height
g.save()
except:
pass
w = Workout.objects.get(id=g.workout.id) w = Workout.objects.get(id=g.workout.id)
r = Rower.objects.get(id=w.user.id) r = Rower.objects.get(id=w.user.id)