added timezone to workout model
This commit is contained in:
@@ -12,7 +12,7 @@ from django.core.validators import validate_email
|
|||||||
import os
|
import os
|
||||||
import twitter
|
import twitter
|
||||||
import re
|
import re
|
||||||
|
import pytz
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
@@ -21,6 +21,7 @@ from django.utils import timezone
|
|||||||
import datetime
|
import datetime
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from rowers.rows import validate_file_extension
|
from rowers.rows import validate_file_extension
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
@@ -389,6 +390,10 @@ def checkworkoutuser(user,workout):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
timezones = (
|
||||||
|
(x,x) for x in pytz.common_timezones
|
||||||
|
)
|
||||||
|
|
||||||
# Workout
|
# Workout
|
||||||
class Workout(models.Model):
|
class Workout(models.Model):
|
||||||
workouttypes = types.workouttypes
|
workouttypes = types.workouttypes
|
||||||
@@ -408,6 +413,9 @@ class Workout(models.Model):
|
|||||||
verbose_name = 'Boat Type')
|
verbose_name = 'Boat Type')
|
||||||
starttime = models.TimeField(blank=True,null=True)
|
starttime = models.TimeField(blank=True,null=True)
|
||||||
startdatetime = models.DateTimeField(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)
|
distance = models.IntegerField(default=0,blank=True)
|
||||||
duration = models.TimeField(default=1,blank=True)
|
duration = models.TimeField(default=1,blank=True)
|
||||||
weightcategory = models.CharField(default="hwt",max_length=10)
|
weightcategory = models.CharField(default="hwt",max_length=10)
|
||||||
@@ -574,7 +582,7 @@ class WorkoutForm(ModelForm):
|
|||||||
duration = forms.TimeInput(format='%H:%M:%S.%f')
|
duration = forms.TimeInput(format='%H:%M:%S.%f')
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workout
|
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 = {
|
widgets = {
|
||||||
'date': DateInput(),
|
'date': DateInput(),
|
||||||
'notes': forms.Textarea,
|
'notes': forms.Textarea,
|
||||||
@@ -585,10 +593,38 @@ class WorkoutForm(ModelForm):
|
|||||||
super(WorkoutForm, self).__init__(*args, **kwargs)
|
super(WorkoutForm, self).__init__(*args, **kwargs)
|
||||||
# this line to be removed
|
# this line to be removed
|
||||||
del self.fields['privacy']
|
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':
|
if self.instance.workouttype != 'water':
|
||||||
del self.fields['boattype']
|
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
|
# Used for the rowing physics calculations
|
||||||
class AdvancedWorkoutForm(ModelForm):
|
class AdvancedWorkoutForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
{% load rowerfilters %}
|
{% load rowerfilters %}
|
||||||
{% load tz %}
|
{% load tz %}
|
||||||
|
{% get_current_timezone as TIME_ZONE %}
|
||||||
|
|
||||||
{% block title %}Change Workout {% endblock %}
|
{% block title %}Change Workout {% endblock %}
|
||||||
|
|
||||||
@@ -42,11 +43,11 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% localtime on %}
|
|
||||||
<table width=100%>
|
<table width=100%>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date/Time:</th><td>{{ workout.startdatetime }}</td>
|
{% localtime on %}
|
||||||
|
<th>Date/Time:</th><td>{{ workout.startdatetime|localtime}}</td>
|
||||||
|
{% endlocaltime %}
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<th>Distance:</th><td>{{ workout.distance }}m</td>
|
<th>Distance:</th><td>{{ workout.distance }}m</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
@@ -69,7 +70,6 @@
|
|||||||
<td>
|
<td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{% endlocaltime %}
|
|
||||||
<form enctype="multipart/form-data" action="" method="post">
|
<form enctype="multipart/form-data" action="" method="post">
|
||||||
<table width=100%>
|
<table width=100%>
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import colorsys
|
|||||||
import timestring
|
import timestring
|
||||||
import zipfile
|
import zipfile
|
||||||
import bleach
|
import bleach
|
||||||
|
import pytz
|
||||||
import operator
|
import operator
|
||||||
import warnings
|
import warnings
|
||||||
import urllib
|
import urllib
|
||||||
@@ -6255,6 +6256,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
duration = form.cleaned_data['duration']
|
duration = form.cleaned_data['duration']
|
||||||
distance = form.cleaned_data['distance']
|
distance = form.cleaned_data['distance']
|
||||||
notes = form.cleaned_data['notes']
|
notes = form.cleaned_data['notes']
|
||||||
|
thetimezone = form.cleaned_data['timezone']
|
||||||
try:
|
try:
|
||||||
boattype = request.POST['boattype']
|
boattype = request.POST['boattype']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -6272,6 +6274,9 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
startdatetime = datetime.datetime.strptime(startdatetime,
|
startdatetime = datetime.datetime.strptime(startdatetime,
|
||||||
"%Y-%m-%d %H:%M:%S")
|
"%Y-%m-%d %H:%M:%S")
|
||||||
startdatetime = timezone.make_aware(startdatetime)
|
startdatetime = timezone.make_aware(startdatetime)
|
||||||
|
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
|
||||||
|
print startdatetime
|
||||||
|
|
||||||
# check if user is owner of this workout
|
# check if user is owner of this workout
|
||||||
if checkworkoutuser(request.user,row):
|
if checkworkoutuser(request.user,row):
|
||||||
row.name = name
|
row.name = name
|
||||||
@@ -6285,6 +6290,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
row.boattype = boattype
|
row.boattype = boattype
|
||||||
row.privacy = privacy
|
row.privacy = privacy
|
||||||
row.rankingpiece = rankingpiece
|
row.rankingpiece = rankingpiece
|
||||||
|
row.timezone = thetimezone
|
||||||
try:
|
try:
|
||||||
row.save()
|
row.save()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
|
|||||||
Reference in New Issue
Block a user