added timezone to workout model
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):
|
||||
|
||||
Reference in New Issue
Block a user