Merge branch 'feature/timezones2' into develop
This commit is contained in:
@@ -12,7 +12,7 @@ from django.core.validators import validate_email
|
||||
import os
|
||||
import twitter
|
||||
import re
|
||||
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
from sqlalchemy import create_engine
|
||||
import sqlalchemy as sa
|
||||
@@ -21,6 +21,7 @@ from django.utils import timezone
|
||||
import datetime
|
||||
from django.core.exceptions import ValidationError
|
||||
from rowers.rows import validate_file_extension
|
||||
from collections import OrderedDict
|
||||
|
||||
import types
|
||||
|
||||
@@ -388,7 +389,11 @@ def checkworkoutuser(user,workout):
|
||||
except Rower.DoesNotExist:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
timezones = (
|
||||
(x,x) for x in pytz.common_timezones
|
||||
)
|
||||
|
||||
# Workout
|
||||
class Workout(models.Model):
|
||||
workouttypes = types.workouttypes
|
||||
@@ -408,6 +413,9 @@ class Workout(models.Model):
|
||||
verbose_name = 'Boat Type')
|
||||
starttime = models.TimeField(blank=True,null=True)
|
||||
startdatetime = models.DateTimeField(blank=True,null=True)
|
||||
timezone = models.CharField(default='UTC',
|
||||
choices=timezones,
|
||||
max_length=100)
|
||||
distance = models.IntegerField(default=0,blank=True)
|
||||
duration = models.TimeField(default=1,blank=True)
|
||||
weightcategory = models.CharField(default="hwt",max_length=10)
|
||||
@@ -574,7 +582,7 @@ class WorkoutForm(ModelForm):
|
||||
duration = forms.TimeInput(format='%H:%M:%S.%f')
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = ['name','date','starttime','duration','distance','workouttype','notes','privacy','rankingpiece','boattype']
|
||||
fields = ['name','date','starttime','timezone','duration','distance','workouttype','notes','privacy','rankingpiece','boattype']
|
||||
widgets = {
|
||||
'date': DateInput(),
|
||||
'notes': forms.Textarea,
|
||||
@@ -585,9 +593,37 @@ class WorkoutForm(ModelForm):
|
||||
super(WorkoutForm, self).__init__(*args, **kwargs)
|
||||
# this line to be removed
|
||||
del self.fields['privacy']
|
||||
# self.fields['timezone'] = forms.ChoiceField(choices=[
|
||||
# (x,x) for x in pytz.common_timezones
|
||||
# ],
|
||||
# initial='UTC',
|
||||
# label='Time Zone')
|
||||
|
||||
if self.instance.workouttype != 'water':
|
||||
del self.fields['boattype']
|
||||
|
||||
fieldorder = (
|
||||
'name',
|
||||
'date',
|
||||
'starttime',
|
||||
'timezone',
|
||||
'duration',
|
||||
'distance',
|
||||
'workouttype',
|
||||
'notes',
|
||||
'rankingpiece',
|
||||
'boattype'
|
||||
)
|
||||
|
||||
fields = OrderedDict()
|
||||
for key in fieldorder:
|
||||
try:
|
||||
fields[key] = self.fields.pop(key)
|
||||
except KeyError:
|
||||
pass
|
||||
for key, valye in self.fields.items():
|
||||
fields[key] = value
|
||||
self.fields = fields
|
||||
|
||||
# Used for the rowing physics calculations
|
||||
class AdvancedWorkoutForm(ModelForm):
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{% load staticfiles %}
|
||||
{% load rowerfilters %}
|
||||
{% load tz %}
|
||||
{% get_current_timezone as TIME_ZONE %}
|
||||
|
||||
{% block title %}Change Workout {% endblock %}
|
||||
|
||||
@@ -42,11 +43,11 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% localtime on %}
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<th>Date/Time:</th><td>{{ workout.startdatetime }}</td>
|
||||
{% localtime on %}
|
||||
<th>Date/Time:</th><td>{{ workout.startdatetime|localtime}}</td>
|
||||
{% endlocaltime %}
|
||||
</tr><tr>
|
||||
<th>Distance:</th><td>{{ workout.distance }}m</td>
|
||||
</tr><tr>
|
||||
@@ -69,7 +70,6 @@
|
||||
<td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endlocaltime %}
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
<table width=100%>
|
||||
{{ form.as_table }}
|
||||
|
||||
@@ -371,6 +371,7 @@ class DataTest(TestCase):
|
||||
'name':'test',
|
||||
'date':'2016-05-01',
|
||||
'starttime':'07:53:00',
|
||||
'timezone':'UTC',
|
||||
'duration':'0:55:00.1',
|
||||
'distance':8000,
|
||||
'notes':'Aap noot \n mies',
|
||||
@@ -595,6 +596,7 @@ class ViewTest(TestCase):
|
||||
'name':'aap',
|
||||
'date':'2016-11-05',
|
||||
'starttime':'09:07:14',
|
||||
'timezone':'Europe/Berlin',
|
||||
'duration':'1:00:00.5',
|
||||
'distance':'15000',
|
||||
'workouttype':'rower',
|
||||
|
||||
@@ -3,6 +3,7 @@ import colorsys
|
||||
import timestring
|
||||
import zipfile
|
||||
import bleach
|
||||
import pytz
|
||||
import operator
|
||||
import warnings
|
||||
import urllib
|
||||
@@ -6255,6 +6256,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
duration = form.cleaned_data['duration']
|
||||
distance = form.cleaned_data['distance']
|
||||
notes = form.cleaned_data['notes']
|
||||
thetimezone = form.cleaned_data['timezone']
|
||||
try:
|
||||
boattype = request.POST['boattype']
|
||||
except KeyError:
|
||||
@@ -6272,6 +6274,9 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
startdatetime = datetime.datetime.strptime(startdatetime,
|
||||
"%Y-%m-%d %H:%M:%S")
|
||||
startdatetime = timezone.make_aware(startdatetime)
|
||||
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
|
||||
print startdatetime
|
||||
|
||||
# check if user is owner of this workout
|
||||
if checkworkoutuser(request.user,row):
|
||||
row.name = name
|
||||
@@ -6285,6 +6290,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
row.boattype = boattype
|
||||
row.privacy = privacy
|
||||
row.rankingpiece = rankingpiece
|
||||
row.timezone = thetimezone
|
||||
try:
|
||||
row.save()
|
||||
except IntegrityError:
|
||||
|
||||
Reference in New Issue
Block a user