half way through cleaning up and commenting the code
This commit is contained in:
@@ -18,6 +18,8 @@ from sqlite3 import OperationalError
|
||||
from django.utils import timezone
|
||||
import datetime
|
||||
|
||||
from rowers.rows import validate_file_extension
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
TWEET_ACCESS_TOKEN_KEY,
|
||||
TWEET_ACCESS_TOKEN_SECRET,
|
||||
@@ -47,12 +49,12 @@ database_url = 'mysql://{user}:{password}@{host}:{port}/{database_name}'.format(
|
||||
if settings.DEBUG or user=='':
|
||||
database_url = 'sqlite:///db.sqlite3'
|
||||
|
||||
|
||||
# Create your models here.
|
||||
# For future Team functionality
|
||||
class Team(models.Model):
|
||||
name = models.CharField(max_length=150)
|
||||
notes = models.CharField(blank=True,max_length=200)
|
||||
|
||||
# Extension of User with rowing specific data
|
||||
class Rower(models.Model):
|
||||
weightcategories = (
|
||||
('hwt','heavy-weight'),
|
||||
@@ -95,6 +97,7 @@ class Rower(models.Model):
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
# Saving a chart as a favorite chart
|
||||
class FavoriteChart(models.Model):
|
||||
y1params = (
|
||||
('hr','Heart Rate'),
|
||||
@@ -181,6 +184,7 @@ class FavoriteForm(ModelForm):
|
||||
fields = ['xparam','yparam1','yparam2',
|
||||
'plottype','workouttype','reststrokes']
|
||||
|
||||
# To generate favorite chart forms on the fly
|
||||
class BaseFavoriteFormSet(BaseFormSet):
|
||||
def clean(self):
|
||||
if any(self.errors):
|
||||
@@ -208,7 +212,8 @@ class BaseFavoriteFormSet(BaseFormSet):
|
||||
|
||||
if not yparam2:
|
||||
yparam2 = 'None'
|
||||
|
||||
|
||||
# Workout
|
||||
class Workout(models.Model):
|
||||
workouttypes = (
|
||||
('water','On-water'),
|
||||
@@ -273,7 +278,7 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
|
||||
if os.path.isfile(instance.csvfilename+'.gz'):
|
||||
os.remove(instance.csvfilename+'.gz')
|
||||
|
||||
|
||||
# Delete stroke data from the database when a workout is deleted
|
||||
@receiver(models.signals.post_delete,sender=Workout)
|
||||
def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
||||
if instance.id:
|
||||
@@ -288,7 +293,12 @@ def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
||||
print "Database Locked"
|
||||
conn.close()
|
||||
engine.dispose()
|
||||
|
||||
|
||||
# Model of StrokeData table
|
||||
# the definition here is used only to enable easy Django migration
|
||||
# when the StrokeData are expanded.
|
||||
# No Django Instances of this model are managed. Strokedata table is
|
||||
# accesssed directly with SQL commands
|
||||
class StrokeData(models.Model):
|
||||
class Meta:
|
||||
db_table = 'strokedata'
|
||||
@@ -329,7 +339,8 @@ class StrokeData(models.Model):
|
||||
finish = models.FloatField(default=0,null=True)
|
||||
wash = models.FloatField(default=0,null=True)
|
||||
peakforceangle = models.FloatField(default=0,null=True)
|
||||
|
||||
|
||||
# A wrapper around the png files
|
||||
class GraphImage(models.Model):
|
||||
filename = models.CharField(default='',max_length=150,blank=True,null=True)
|
||||
creationdatetime = models.DateTimeField()
|
||||
@@ -338,7 +349,7 @@ class GraphImage(models.Model):
|
||||
def __str__(self):
|
||||
return self.filename
|
||||
|
||||
# delete related file object
|
||||
# delete related file object when image is deleted
|
||||
@receiver(models.signals.post_delete,sender=GraphImage)
|
||||
def auto_delete_image_on_delete(sender,instance, **kwargs):
|
||||
if instance.filename:
|
||||
@@ -347,11 +358,11 @@ def auto_delete_image_on_delete(sender,instance, **kwargs):
|
||||
else:
|
||||
print "couldn't find the file "+instance.filename
|
||||
|
||||
|
||||
# Date input utility
|
||||
class DateInput(forms.DateInput):
|
||||
input_type = 'date'
|
||||
|
||||
|
||||
# Form to update Workout data
|
||||
class WorkoutForm(ModelForm):
|
||||
duration = forms.TimeInput(format='%H:%M:%S.%f')
|
||||
class Meta:
|
||||
@@ -368,16 +379,20 @@ class WorkoutForm(ModelForm):
|
||||
if self.instance.workouttype != 'water':
|
||||
del self.fields['boattype']
|
||||
|
||||
# Used for the rowing physics calculations
|
||||
class AdvancedWorkoutForm(ModelForm):
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = ['boattype','weightvalue']
|
||||
|
||||
# Simple form to set rower's Functional Threshold Power
|
||||
class RowerPowerForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
fields = ['ftp']
|
||||
|
||||
# Form to set rower's Heart Rate zones, including test routines
|
||||
# to enable consistency
|
||||
class RowerForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
@@ -519,6 +534,8 @@ class RowerForm(ModelForm):
|
||||
if an>=max:
|
||||
raise forms.ValidationError("AN should be lower than Max")
|
||||
|
||||
# An announcement that goes to the right of the workouts list
|
||||
# optionally sends a tweet to our twitter account
|
||||
class SiteAnnouncement(models.Model):
|
||||
created = models.DateField(default=timezone.now)
|
||||
announcement = models.TextField(max_length=140)
|
||||
|
||||
Reference in New Issue
Block a user