From df9806a2007b58b6ae7623b7900864c014d33e74 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Sun, 3 Sep 2017 14:47:20 +0200
Subject: [PATCH 1/2] added timezone to workout model
---
rowers/models.py | 42 +++++++++++++++++++++++++++---
rowers/templates/workout_form.html | 8 +++---
rowers/views.py | 6 +++++
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/rowers/models.py b/rowers/models.py
index fb82d2e9..047d315c 100644
--- a/rowers/models.py
+++ b/rowers/models.py
@@ -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):
diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html
index 3a48dac7..bf47f4c3 100644
--- a/rowers/templates/workout_form.html
+++ b/rowers/templates/workout_form.html
@@ -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 @@
-
- {% localtime on %}
- | Date/Time: | {{ workout.startdatetime }} |
+{% localtime on %}
+Date/Time: | {{ workout.startdatetime|localtime}} |
+{% endlocaltime %}
| Distance: | {{ workout.distance }}m |
@@ -69,7 +70,6 @@
|
|
- {% endlocaltime %}