Commits

John Costa  committed 6a8e2c2

pep8

  • Participants
  • Parent commits f53849a
  • Branches django-1.5

Comments (0)

Files changed (12)

File fitlog/admin.py

 from django.contrib import admin
 from fitlog.models import *
 
+
 class FitLogAdmin(admin.ModelAdmin):
-    list_display = ['member','log_date','comments']
+    list_display = ['member', 'log_date', 'comments']
 
-admin.site.register(FitLog,FitLogAdmin)
+admin.site.register(FitLog, FitLogAdmin)
 admin.site.register(FitnessType)
 admin.site.register(MuscleGroup)
-admin.site.register(ExerciseType)
+admin.site.register(ExerciseType)

File fitlog/choices.py

 GENDER_CHOICES = (
-         ('M', 'Male'),
-         ('F', 'Female'),
+    ('M', 'Male'),
+    ('F', 'Female'),
 )
 
 WEIGHT_CHOICES = (
-           ('0', '0 lbs'),
-           ('5', '5 lbs'),
-           ('10', '10 lbs'),
-           ('15', '15 lbs'),
-           ('20', '20 lbs'),
-           ('25', '25 lbs'),
-           ('30', '30 lbs'),
-           ('35', '35 lbs'),
-           ('40', '40 lbs'),
-           ('45', '45 lbs'),
-           ('50', '50 lbs'),
-           ('55', '55 lbs'),
-           ('60', '60 lbs'),
-           ('65', '65 lbs'),
-           ('70', '70 lbs'),
-           ('75', '75 lbs'),
-           ('80', '85 lbs'),
-           ('90', '90 lbs'),
-           ('95', '95 lbs'),
-           ('100', '100 lbs'),
-           ('105', '105 lbs'),
-           ('110', '110 lbs'),
-           ('115', '115 lbs'),
-           ('120', '120 lbs'),
-           ('125', '125 lbs'),
-           ('130', '130 lbs'),
-           ('135', '135 lbs'),
-           ('140', '140 lbs'),
-           ('145', '145 lbs'),
-           ('150', '150 lbs'),
-           ('155', '155 lbs'),
-           ('160', '160 lbs'),
-           ('165', '165 lbs'),
-           ('170', '170 lbs'),
-           ('175', '175 lbs'),
-           ('180', '185 lbs'),
-           ('190', '190 lbs'),
-           ('195', '195 lbs'),
-           ('200', '200 lbs'),
-           ('205', '205 lbs'),
-           ('210', '210 lbs'),
-           ('215', '215 lbs'),
-           ('220', '220 lbs'),
-           ('225', '225 lbs'),
-           ('230', '230 lbs'),
-           ('235', '235 lbs'),
-           ('240', '240 lbs'),
-           ('245', '245 lbs'),
-           ('250', '250 lbs'),
-           ('255', '255 lbs'),
-           ('260', '260 lbs'),
-           ('265', '265 lbs'),
-           ('270', '270 lbs'),
-           ('275', '275 lbs'),
-           ('280', '285 lbs'),
-           ('290', '290 lbs'),
-           ('295', '295 lbs'),
-           ('300', '300 lbs'),
-           ('305', '305 lbs'),
-           ('310', '310 lbs'),
-           ('315', '315 lbs'),
-           ('320', '320 lbs'),
-           ('325', '325 lbs'),
-           ('330', '330 lbs'),
-           ('335', '335 lbs'),
-           ('340', '340 lbs'),
-           ('345', '345 lbs'),
-           ('350', '350 lbs'),
-           ('355', '355 lbs'),
-           ('360', '360 lbs'),
-           ('365', '365 lbs'),
-           ('370', '370 lbs'),
-           ('375', '375 lbs'),
-           ('380', '385 lbs'),
-           ('390', '390 lbs'),
-           ('395', '395 lbs'),
-           ('400', '400 lbs'),
-           ('405', '405 lbs'),
-           ('410', '410 lbs'),
-           ('415', '415 lbs'),
-           ('420', '420 lbs'),
-           ('425', '425 lbs'),
-           ('430', '430 lbs'),
-           ('435', '435 lbs'),
-           ('440', '440 lbs'),
-           ('445', '445 lbs'),
-           ('450', '450 lbs'),
-           ('455', '455 lbs'),
-           ('460', '460 lbs'),
-           ('465', '465 lbs'),
-           ('470', '470 lbs'),
-           ('475', '475 lbs'),
-           ('480', '485 lbs'),
-           ('490', '490 lbs'),
-           ('495', '495 lbs'),
-           ('500', '500 lbs'),
-           ('505', '505 lbs'),
-           ('510', '510 lbs'),
-           ('515', '515 lbs'),
-           ('520', '520 lbs'),
-           ('525', '525 lbs'),
-           ('530', '530 lbs'),
-           ('535', '535 lbs'),
-           ('540', '540 lbs'),
-           ('545', '545 lbs'),
-           ('550', '550 lbs'),
-           ('555', '555 lbs'),
-           ('560', '560 lbs'),
-           ('565', '565 lbs'),
-           ('570', '570 lbs'),
-           ('575', '575 lbs'),
-           ('580', '585 lbs'),
-           ('590', '590 lbs'),
-           ('595', '595 lbs'),
-           ('600', '600 lbs'),
-           ('605', '605 lbs'),
-           ('610', '610 lbs'),
-           ('615', '615 lbs'),
-           ('620', '620 lbs'),
-           ('625', '625 lbs'),
-           ('630', '630 lbs'),
-           ('635', '635 lbs'),
-           ('640', '640 lbs'),
-           ('645', '645 lbs'),
-           ('650', '650 lbs'),
-           ('655', '655 lbs'),
-           ('660', '660 lbs'),
-           ('665', '665 lbs'),
-           ('670', '670 lbs'),
-           ('675', '675 lbs'),
-           ('680', '685 lbs'),
-           ('690', '690 lbs'),
-           ('695', '695 lbs'),
-           ('700', '700 lbs'),
-           ('705', '705 lbs'),
-           ('710', '710 lbs'),
-           ('715', '715 lbs'),
-           ('720', '720 lbs'),
-           ('725', '725 lbs'),
-           ('730', '730 lbs'),
-           ('735', '735 lbs'),
-           ('740', '740 lbs'),
-           ('745', '745 lbs'),
-           ('750', '750 lbs'),
-           ('755', '755 lbs'),
-           ('760', '760 lbs'),
-           ('765', '765 lbs'),
-           ('770', '770 lbs'),
-           ('775', '775 lbs'),
-           ('780', '785 lbs'),
-           ('790', '790 lbs'),
-           ('795', '795 lbs'),
-           ('800', '800 lbs'), 
-)
+    ('0', '0 lbs'),
+    ('5', '5 lbs'),
+    ('10', '10 lbs'),
+    ('15', '15 lbs'),
+    ('20', '20 lbs'),
+    ('25', '25 lbs'),
+    ('30', '30 lbs'),
+    ('35', '35 lbs'),
+    ('40', '40 lbs'),
+    ('45', '45 lbs'),
+    ('50', '50 lbs'),
+    ('55', '55 lbs'),
+    ('60', '60 lbs'),
+    ('65', '65 lbs'),
+    ('70', '70 lbs'),
+    ('75', '75 lbs'),
+    ('80', '85 lbs'),
+    ('90', '90 lbs'),
+    ('95', '95 lbs'),
+    ('100', '100 lbs'),
+    ('105', '105 lbs'),
+    ('110', '110 lbs'),
+    ('115', '115 lbs'),
+    ('120', '120 lbs'),
+    ('125', '125 lbs'),
+    ('130', '130 lbs'),
+    ('135', '135 lbs'),
+    ('140', '140 lbs'),
+    ('145', '145 lbs'),
+    ('150', '150 lbs'),
+    ('155', '155 lbs'),
+    ('160', '160 lbs'),
+    ('165', '165 lbs'),
+    ('170', '170 lbs'),
+    ('175', '175 lbs'),
+    ('180', '185 lbs'),
+    ('190', '190 lbs'),
+    ('195', '195 lbs'),
+    ('200', '200 lbs'),
+    ('205', '205 lbs'),
+    ('210', '210 lbs'),
+    ('215', '215 lbs'),
+    ('220', '220 lbs'),
+    ('225', '225 lbs'),
+    ('230', '230 lbs'),
+    ('235', '235 lbs'),
+    ('240', '240 lbs'),
+    ('245', '245 lbs'),
+    ('250', '250 lbs'),
+    ('255', '255 lbs'),
+    ('260', '260 lbs'),
+    ('265', '265 lbs'),
+    ('270', '270 lbs'),
+    ('275', '275 lbs'),
+    ('280', '285 lbs'),
+    ('290', '290 lbs'),
+    ('295', '295 lbs'),
+    ('300', '300 lbs'),
+    ('305', '305 lbs'),
+    ('310', '310 lbs'),
+    ('315', '315 lbs'),
+    ('320', '320 lbs'),
+    ('325', '325 lbs'),
+    ('330', '330 lbs'),
+    ('335', '335 lbs'),
+    ('340', '340 lbs'),
+    ('345', '345 lbs'),
+    ('350', '350 lbs'),
+    ('355', '355 lbs'),
+    ('360', '360 lbs'),
+    ('365', '365 lbs'),
+    ('370', '370 lbs'),
+    ('375', '375 lbs'),
+    ('380', '385 lbs'),
+    ('390', '390 lbs'),
+    ('395', '395 lbs'),
+    ('400', '400 lbs'),
+    ('405', '405 lbs'),
+    ('410', '410 lbs'),
+    ('415', '415 lbs'),
+    ('420', '420 lbs'),
+    ('425', '425 lbs'),
+    ('430', '430 lbs'),
+    ('435', '435 lbs'),
+    ('440', '440 lbs'),
+    ('445', '445 lbs'),
+    ('450', '450 lbs'),
+    ('455', '455 lbs'),
+    ('460', '460 lbs'),
+    ('465', '465 lbs'),
+    ('470', '470 lbs'),
+    ('475', '475 lbs'),
+    ('480', '485 lbs'),
+    ('490', '490 lbs'),
+    ('495', '495 lbs'),
+    ('500', '500 lbs'),
+    ('505', '505 lbs'),
+    ('510', '510 lbs'),
+    ('515', '515 lbs'),
+    ('520', '520 lbs'),
+    ('525', '525 lbs'),
+    ('530', '530 lbs'),
+    ('535', '535 lbs'),
+    ('540', '540 lbs'),
+    ('545', '545 lbs'),
+    ('550', '550 lbs'),
+    ('555', '555 lbs'),
+    ('560', '560 lbs'),
+    ('565', '565 lbs'),
+    ('570', '570 lbs'),
+    ('575', '575 lbs'),
+    ('580', '585 lbs'),
+    ('590', '590 lbs'),
+    ('595', '595 lbs'),
+    ('600', '600 lbs'),
+    ('605', '605 lbs'),
+    ('610', '610 lbs'),
+    ('615', '615 lbs'),
+    ('620', '620 lbs'),
+    ('625', '625 lbs'),
+    ('630', '630 lbs'),
+    ('635', '635 lbs'),
+    ('640', '640 lbs'),
+    ('645', '645 lbs'),
+    ('650', '650 lbs'),
+    ('655', '655 lbs'),
+    ('660', '660 lbs'),
+    ('665', '665 lbs'),
+    ('670', '670 lbs'),
+    ('675', '675 lbs'),
+    ('680', '685 lbs'),
+    ('690', '690 lbs'),
+    ('695', '695 lbs'),
+    ('700', '700 lbs'),
+    ('705', '705 lbs'),
+    ('710', '710 lbs'),
+    ('715', '715 lbs'),
+    ('720', '720 lbs'),
+    ('725', '725 lbs'),
+    ('730', '730 lbs'),
+    ('735', '735 lbs'),
+    ('740', '740 lbs'),
+    ('745', '745 lbs'),
+    ('750', '750 lbs'),
+    ('755', '755 lbs'),
+    ('760', '760 lbs'),
+    ('765', '765 lbs'),
+    ('770', '770 lbs'),
+    ('775', '775 lbs'),
+    ('780', '785 lbs'),
+    ('790', '790 lbs'),
+    ('795', '795 lbs'),
+    ('800', '800 lbs'))
 
 REP_CHOICES = (
-           ('0','0'),
-           ('1','1'),
-           ('2','2'),
-           ('3','3'),
-           ('4','4'), 
-           ('5','5'),
-           ('6','6'), 
-           ('7','7'),
-           ('8','8'),
-           ('9','9'),
-           ('10','10'),
-           ('11','11'),
-           ('12','12'),
-           ('13','13'),
-           ('14','14'),
-           ('15','15'),
-           ('16','16'),
-           ('17','17'),
-           ('18','18'),
-           ('19','19'),
-           ('20','20'),
-           ('21','21'),
-           ('22','22'),
-           ('23','23'),
-           ('24','24'),
-           ('25','25'),
-           ('26','26'),
-           ('27','27'),
-           ('28','28'),
-           ('29','29'),
-           ('30','30'),
-           ('31','31'),
-           ('32','32'),
-           ('33','33'),
-           ('34','34'),
-           ('35','35'),
-           ('36','36'),
-           ('37','37'),
-           ('38','38'),
-           ('39','39'),
-           ('40','40'),
-           ('41','41'),
-           ('42','42'),
-           ('43','43'),
-           ('44','44'),
-           ('45','45'),
-           ('46','46'),
-           ('47','47'),
-           ('48','48'),
-           ('49','49'),
-           ('50','50'),
-           ('51','51'),
-           ('52','52'),
-           ('53','53'),
-           ('54','54'),
-           ('55','55'),
-           ('56','56'),
-           ('57','57'),
-           ('58','58'),
-           ('59','59'),
-           ('60','60'),
-           ('61','61'),
-           ('62','62'),
-           ('63','63'),
-           ('64','64'),
-           ('65','65'),
-           ('66','66'),
-           ('67','67'),
-           ('68','68'),
-           ('69','69'),
-           ('70','70'),
-           ('71','71'),
-           ('72','72'),
-           ('73','73'),
-           ('74','74'),
-           ('75','75'),
-           ('76','76'),
-           ('77','77'),
-           ('78','78'),
-           ('79','79'),
-           ('80','80'),
-           ('81','81'),
-           ('82','82'),
-           ('83','83'),
-           ('84','84'),
-           ('85','85'),
-           ('86','86'),
-           ('87','87'),
-           ('88','88'),
-           ('89','89'),
-           ('90','90'),
-           ('91','91'),
-           ('92','92'),
-           ('93','93'),
-           ('94','94'),
-           ('95','95'),
-           ('96','96'),
-           ('97','97'),
-           ('98','98'),
-           ('99','99'),
-           ('100','100'),
-)
+    ('0', '0'),
+    ('1', '1'),
+    ('2', '2'),
+    ('3', '3'),
+    ('4', '4'),
+    ('5', '5'),
+    ('6', '6'),
+    ('7', '7'),
+    ('8', '8'),
+    ('9', '9'),
+    ('10', '10'),
+    ('11', '11'),
+    ('12', '12'),
+    ('13', '13'),
+    ('14', '14'),
+    ('15', '15'),
+    ('16', '16'),
+    ('17', '17'),
+    ('18', '18'),
+    ('19', '19'),
+    ('20', '20'),
+    ('21', '21'),
+    ('22', '22'),
+    ('23', '23'),
+    ('24', '24'),
+    ('25', '25'),
+    ('26', '26'),
+    ('27', '27'),
+    ('28', '28'),
+    ('29', '29'),
+    ('30', '30'),
+    ('31', '31'),
+    ('32', '32'),
+    ('33', '33'),
+    ('34', '34'),
+    ('35', '35'),
+    ('36', '36'),
+    ('37', '37'),
+    ('38', '38'),
+    ('39', '39'),
+    ('40', '40'),
+    ('41', '41'),
+    ('42', '42'),
+    ('43', '43'),
+    ('44', '44'),
+    ('45', '45'),
+    ('46', '46'),
+    ('47', '47'),
+    ('48', '48'),
+    ('49', '49'),
+    ('50', '50'),
+    ('51', '51'),
+    ('52', '52'),
+    ('53', '53'),
+    ('54', '54'),
+    ('55', '55'),
+    ('56', '56'),
+    ('57', '57'),
+    ('58', '58'),
+    ('59', '59'),
+    ('60', '60'),
+    ('61', '61'),
+    ('62', '62'),
+    ('63', '63'),
+    ('64', '64'),
+    ('65', '65'),
+    ('66', '66'),
+    ('67', '67'),
+    ('68', '68'),
+    ('69', '69'),
+    ('70', '70'),
+    ('71', '71'),
+    ('72', '72'),
+    ('73', '73'),
+    ('74', '74'),
+    ('75', '75'),
+    ('76', '76'),
+    ('77', '77'),
+    ('78', '78'),
+    ('79', '79'),
+    ('80', '80'),
+    ('81', '81'),
+    ('82', '82'),
+    ('83', '83'),
+    ('84', '84'),
+    ('85', '85'),
+    ('86', '86'),
+    ('87', '87'),
+    ('88', '88'),
+    ('89', '89'),
+    ('90', '90'),
+    ('91', '91'),
+    ('92', '92'),
+    ('93', '93'),
+    ('94', '94'),
+    ('95', '95'),
+    ('96', '96'),
+    ('97', '97'),
+    ('98', '98'),
+    ('99', '99'),
+    ('100', '100'))

File fitlog/forms.py

-from django.contrib.auth.forms import UserCreationForm, UserChangeForm, SetPasswordForm
-from django.contrib.auth.models import User
-from django.contrib.sites.models import Site
-from django.utils.translation import ugettext_lazy as _
-from django.utils import dateformat
+import datetime
+
 from django import forms
 from django.forms.formsets import BaseFormSet
-from django.contrib.admin.widgets import AdminSplitDateTime, AdminDateWidget
-from django.forms import Textarea,TextInput
-from django.core.mail import send_mail
-from django.conf import settings
-from django.template.loader import render_to_string
 
-import time, datetime
-from datetime import timedelta
+from fitlog.models import (
+    FitLog, ExerciseType, CardioFitLogDetail, BodyWeightLog, WeightLogSet,
+    WeightFitLogDetail)
 
-from fitlog.models import *
 
 class FitLogForm(forms.ModelForm):
-    log_date = forms.DateField(initial=datetime.date.today,help_text="YYYY-MM-DD")
-    total_time = forms.TimeField(help_text="HH:MM:SS",error_messages={'invalid': 'Please enter Time in this format HH:MM:SS (example: 01:25:30 would be 1 hour 25 min and 30 seconds)'} )
-    comments = forms.CharField(widget=forms.Textarea,required=False)
+    log_date = forms.DateField(initial=datetime.date.today,
+                               help_text="YYYY-MM-DD")
+    total_time = forms.TimeField(
+        help_text="HH:MM:SS",
+        error_messages={
+            'invalid': 'Please enter Time in this format HH:MM:SS (example: '
+                       '01:25:30 would be 1 hour 25 min and 30 seconds)'})
+    comments = forms.CharField(widget=forms.Textarea, required=False)
+
     class Meta:
         model = FitLog
-        exclude = ('member','create_date','last_update')
-        
+        exclude = ('member', 'create_date', 'last_update')
+
     def save(self, member):
-        fit_log= super(FitLogForm, self).save(commit=False)
-        fit_log.member = member       
-        fit_log.save() 
+        fit_log = super(FitLogForm, self).save(commit=False)
+        fit_log.member = member
+        fit_log.save()
         return fit_log
-    
+
+
 class CardioLogForm(forms.ModelForm):
-    exercise_type = forms.ModelChoiceField(queryset=ExerciseType.cardio_objects.all(),empty_label=" -- Select One --")
+    exercise_type = forms.ModelChoiceField(
+        queryset=ExerciseType.cardio_objects.all(),
+        empty_label=" -- Select One --")
     distance = forms.DecimalField(help_text="Miles (ie 1.0, 3.1,etc)")
-    total_time = forms.TimeField(help_text="HH:MM:SS",error_messages={'invalid': 'Please enter Time in correct format "1:30:00" would be 1 hour, 30 minutes and no seconds'})
-    comments = forms.CharField(widget=forms.Textarea,required=False)
-    
+    total_time = forms.TimeField(
+        help_text="HH:MM:SS",
+        error_messages={'invalid': 'Please enter Time in correct format '
+                                   '"1:30:00" would be 1 hour, 30 minutes and '
+                                   'no seconds'})
+    comments = forms.CharField(widget=forms.Textarea, required=False)
+
     class Meta:
         model = CardioFitLogDetail
-        fields = ('exercise_type','total_time','distance','comments')
-        
+        fields = ('exercise_type', 'total_time', 'distance', 'comments')
+
     def save(self, fit_log):
-        cardio_log= super(CardioLogForm, self).save(commit=False)
-        cardio_log.fit_log = fit_log       
-        cardio_log.save() 
-        return cardio_log 
-    
+        cardio_log = super(CardioLogForm, self).save(commit=False)
+        cardio_log.fit_log = fit_log
+        cardio_log.save()
+        return cardio_log
+
+
 class WeightLogForm(forms.ModelForm):
-    exercise_type = forms.ModelChoiceField(queryset=ExerciseType.weight_objects.all(),empty_label=" -- Select One --")
-    comments = forms.CharField(widget=forms.Textarea,required=False)
+    exercise_type = forms.ModelChoiceField(
+        queryset=ExerciseType.weight_objects.all(),
+        empty_label=" -- Select One --")
+    comments = forms.CharField(widget=forms.Textarea, required=False)
+
     class Meta:
         model = WeightFitLogDetail
         exclude = ('fit_log',)
-        
+
     def save(self, fit_log):
-        weight_log= super(WeightLogForm, self).save(commit=False)
-        weight_log.fit_log = fit_log       
-        weight_log.save() 
+        weight_log = super(WeightLogForm, self).save(commit=False)
+        weight_log.fit_log = fit_log
+        weight_log.save()
         return weight_log
-    
+
+
 class WeightLogSetForm(forms.ModelForm):
     class Meta:
         model = WeightLogSet
-        exclude = ('weight_log_detail','sequence')
-        
-    def save(self, weight_log,sequence=None):
-        weight_log_set= super(WeightLogSetForm, self).save(commit=False)
+        exclude = ('weight_log_detail', 'sequence')
+
+    def save(self, weight_log, sequence=None):
+        weight_log_set = super(WeightLogSetForm, self).save(commit=False)
         weight_log_set.weight_log_detail = weight_log
         if sequence:
-            weight_log_set.sequence = sequence      
-        weight_log_set.save() 
+            weight_log_set.sequence = sequence
+        weight_log_set.save()
         return weight_log_set
-    
-    
+
+
 class WeightLogSetFormSet(BaseFormSet):
 
     def save(self, weight_log):
-        count = 1 
+        count = 1
         for form in self.forms:
-            if (('weight' in form.cleaned_data) and ('reps' in form.cleaned_data)):
-                form.save(weight_log,count)
-                count = count + 1    
-                
+            if (('weight' in form.cleaned_data) and (
+                    'reps' in form.cleaned_data)):
+                form.save(weight_log, count)
+                count = count + 1
+
+
 class BodyWeightForm(forms.ModelForm):
-    weight_date = forms.DateField(initial=datetime.date.today,help_text="YYYY-MM-DD") 
+    weight_date = forms.DateField(initial=datetime.date.today,
+                                  help_text="YYYY-MM-DD")
+
     class Meta:
         model = BodyWeightLog
         exclude = ('member')
-        
-    def save(self,member):
+
+    def save(self, member):
         weight_log = super(BodyWeightForm, self).save(commit=False)
         weight_log.member = member
         weight_log.save()
-        return weight_log
+        return weight_log

File fitlog/managers.py

 from django.db import models
 
+
 class FitLogManager(models.Manager):
-    def by_member(self,member):
-        return self.select_related().filter(member=member).order_by('-create_date')
-    
+    def by_member(self, member):
+        return self.select_related().filter(member=member).order_by(
+            '-create_date')
+
     def latest(self):
         return self.select_related().all().order_by('-create_date')[:10]
-    
+
     def number_of_logs(self):
         return self.count()
 
+
 class CardioManager(models.Manager):
     def get_query_set(self):
-        return super(CardioManager,self).get_query_set().filter(fitness_type__name__iexact="Cardio")
+        return super(CardioManager, self).get_query_set().filter(
+            fitness_type__name__iexact="Cardio")
+
 
 class WeightManager(models.Manager):
     def get_query_set(self):
-        return super(WeightManager,self).get_query_set().select_related().filter(fitness_type__name__iexact="Weight Training")
+        return super(WeightManager, self).get_query_set(
+        ).select_related().filter(fitness_type__name__iexact="Weight Training")
+
 
 class BodyWeightLogManager(models.Manager):
-    def by_member(self,member):
-        return self.select_related().filter(member=member).order_by('-weight_date')
+    def by_member(self, member):
+        return self.select_related().filter(member=member).order_by(
+            '-weight_date')

File fitlog/migrations/0001_initial.py

-
 from south.db import db
 from django.db import models
 from fitlog.models import *
 
+
 class Migration:
-    
+
     def forwards(self, orm):
-        
+
         # Adding model 'MuscleGroup'
         db.create_table('fitlog_musclegroup', (
             ('id', models.AutoField(primary_key=True)),
             ('name', models.CharField(max_length=100)),
         ))
         db.send_create_signal('fitlog', ['MuscleGroup'])
-        
+
         # Adding model 'WeightLogSet'
         db.create_table('fitlog_weightlogset', (
             ('weight_log_detail', models.ForeignKey(orm.WeightFitLogDetail)),
             ('sequence', models.SmallIntegerField()),
         ))
         db.send_create_signal('fitlog', ['WeightLogSet'])
-        
+
         # Adding model 'FitLog'
         db.create_table('fitlog_fitlog', (
             ('total_time', models.IntegerField()),
             ('id', models.AutoField(primary_key=True)),
         ))
         db.send_create_signal('fitlog', ['FitLog'])
-        
+
         # Adding model 'CardioFitLogDetail'
         db.create_table('fitlog_cardiofitlogdetail', (
             ('total_time', models.IntegerField()),
             ('id', models.AutoField(primary_key=True)),
         ))
         db.send_create_signal('fitlog', ['CardioFitLogDetail'])
-        
+
         # Adding model 'UserProfile'
         db.create_table('fitlog_userprofile', (
             ('gender', models.CharField(max_length=1)),
             ('user', models.ForeignKey(orm['auth.User'], unique=True)),
         ))
         db.send_create_signal('fitlog', ['UserProfile'])
-        
+
         # Adding model 'WeightFitLogDetail'
         db.create_table('fitlog_weightfitlogdetail', (
             ('exercise_type', models.ForeignKey(orm.ExerciseType)),
             ('comments', models.CharField(max_length=500, blank=True)),
         ))
         db.send_create_signal('fitlog', ['WeightFitLogDetail'])
-        
+
         # Adding model 'FitnessType'
         db.create_table('fitlog_fitnesstype', (
             ('id', models.AutoField(primary_key=True)),
             ('name', models.CharField(max_length=50)),
         ))
         db.send_create_signal('fitlog', ['FitnessType'])
-        
+
         # Adding model 'ExerciseType'
         db.create_table('fitlog_exercisetype', (
             ('fitness_type', models.ForeignKey(orm.FitnessType)),
             ('id', models.AutoField(primary_key=True)),
             ('name', models.CharField(max_length=50)),
-            ('muscle_group', models.ForeignKey(orm.MuscleGroup, null=True, blank=True)),
+            ('muscle_group', models.ForeignKey(orm.MuscleGroup, null=True,
+                                               blank=True)),
         ))
         db.send_create_signal('fitlog', ['ExerciseType'])
-        
+
         # Adding model 'Team'
         db.create_table('fitlog_team', (
             ('description', models.TextField(max_length=255, blank=True)),
             ('name', models.CharField(max_length=50)),
         ))
         db.send_create_signal('fitlog', ['Team'])
-        
-    
-    
+
     def backwards(self, orm):
-        
+
         # Deleting model 'MuscleGroup'
         db.delete_table('fitlog_musclegroup')
-        
+
         # Deleting model 'WeightLogSet'
         db.delete_table('fitlog_weightlogset')
-        
+
         # Deleting model 'FitLog'
         db.delete_table('fitlog_fitlog')
-        
+
         # Deleting model 'CardioFitLogDetail'
         db.delete_table('fitlog_cardiofitlogdetail')
-        
+
         # Deleting model 'UserProfile'
         db.delete_table('fitlog_userprofile')
-        
+
         # Deleting model 'WeightFitLogDetail'
         db.delete_table('fitlog_weightfitlogdetail')
-        
+
         # Deleting model 'FitnessType'
         db.delete_table('fitlog_fitnesstype')
-        
+
         # Deleting model 'ExerciseType'
         db.delete_table('fitlog_exercisetype')
-        
+
         # Deleting model 'Team'
         db.delete_table('fitlog_team')
-        
-    
-    
+
     models = {
         'fitlog.musclegroup': {
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'reps': ('models.SmallIntegerField', [], {}),
             'sequence': ('models.SmallIntegerField', [], {}),
             'weight': ('models.SmallIntegerField', [], {}),
-            'weight_log_detail': ('models.ForeignKey', ['WeightFitLogDetail'], {})
+            'weight_log_detail': ('models.ForeignKey',
+                                  ['WeightFitLogDetail'], {})
         },
         'fitlog.fitlog': {
-            'comments': ('models.TextField', [], {'max_length': '5000', 'blank': 'True'}),
-            'create_date': ('models.DateTimeField', [], {'auto_now_add': 'True'}),
+            'comments': ('models.TextField', [], {'max_length': '5000',
+                                                  'blank': 'True'}),
+            'create_date': ('models.DateTimeField', [],
+                            {'auto_now_add': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'last_update': ('models.DateTimeField', [], {'auto_now': 'True'}),
             'log_date': ('models.DateField', [], {}),
             'total_time': ('models.IntegerField', [], {})
         },
         'fitlog.cardiofitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
-            'distance': ('models.DecimalField', [], {'max_digits': '5', 'decimal_places': '1'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
+            'distance': ('models.DecimalField', [], {'max_digits': '5',
+                                                     'decimal_places': '1'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'user': ('models.ForeignKey', ['User'], {'unique': 'True'})
         },
         'fitlog.weightfitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'})
         'fitlog.exercisetype': {
             'fitness_type': ('models.ForeignKey', ['FitnessType'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
-            'muscle_group': ('models.ForeignKey', ['MuscleGroup'], {'null': 'True', 'blank': 'True'}),
+            'muscle_group': ('models.ForeignKey', ['MuscleGroup'],
+                             {'null': 'True', 'blank': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         },
         'fitlog.team': {
-            'description': ('models.TextField', [], {'max_length': '255', 'blank': 'True'}),
+            'description': ('models.TextField', [], {'max_length': '255',
+                                                     'blank': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         }
     }
-    
+
     complete_apps = ['fitlog']

File fitlog/migrations/0002_timechange.py

-
 from south.db import db
 from django.db import models
-import time
 from fitlog.models import *
 
+
 class Migration:
-    
+
     def forwards(self, orm):
-        
+
         # rename columns
-        db.rename_column('fitlog_fitlog','total_time','total_time_orig')
-        db.rename_column('fitlog_cardiofitlogdetail','total_time','total_time_orig')
-        
+        db.rename_column('fitlog_fitlog', 'total_time', 'total_time_orig')
+        db.rename_column('fitlog_cardiofitlogdetail', 'total_time',
+                         'total_time_orig')
+
         # Changing field 'FitLog.total_time'
-        db.add_column('fitlog_fitlog', 'total_time', models.TimeField(blank=True, null=True))
-        
+        db.add_column('fitlog_fitlog', 'total_time',
+                      models.TimeField(blank=True, null=True))
+
         # Changing field 'CardioFitLogDetail.total_time'
-        db.add_column('fitlog_cardiofitlogdetail', 'total_time', models.TimeField(blank=True, null=True))
-        
-    
-    
+        db.add_column('fitlog_cardiofitlogdetail', 'total_time',
+                      models.TimeField(blank=True, null=True))
+
     def backwards(self, orm):
-        
+
         # delete the new columns
         db.delete_column('fitlog_fitlog', 'total_time')
         db.delete_column('fitlog_cardiofitlogdetail', 'total_time')
-        
+
         # rename the originals back to what they were
-        db.rename_column('fitlog_fitlog','total_time_orig','total_time')
-        db.rename_column('fitlog_cardiofitlogdetail','total_time_orig','total_time')
-    
-    
+        db.rename_column('fitlog_fitlog', 'total_time_orig', 'total_time')
+        db.rename_column('fitlog_cardiofitlogdetail', 'total_time_orig',
+                         'total_time')
+
     models = {
         'fitlog.musclegroup': {
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'reps': ('models.SmallIntegerField', [], {}),
             'sequence': ('models.SmallIntegerField', [], {}),
             'weight': ('models.SmallIntegerField', [], {}),
-            'weight_log_detail': ('models.ForeignKey', ['WeightFitLogDetail'], {})
+            'weight_log_detail': ('models.ForeignKey', ['WeightFitLogDetail'],
+                                  {})
         },
         'fitlog.fitlog': {
-            'comments': ('models.TextField', [], {'max_length': '5000', 'blank': 'True'}),
-            'create_date': ('models.DateTimeField', [], {'auto_now_add': 'True'}),
+            'comments': ('models.TextField', [], {'max_length': '5000',
+                                                  'blank': 'True'}),
+            'create_date': ('models.DateTimeField', [],
+                            {'auto_now_add': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'last_update': ('models.DateTimeField', [], {'auto_now': 'True'}),
             'log_date': ('models.DateField', [], {}),
             'total_time': ('models.TimeField', [], {})
         },
         'fitlog.cardiofitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
-            'distance': ('models.DecimalField', [], {'max_digits': '5', 'decimal_places': '1'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
+            'distance': ('models.DecimalField', [], {'max_digits': '5',
+                                                     'decimal_places': '1'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'user': ('models.ForeignKey', ['User'], {'unique': 'True'})
         },
         'fitlog.weightfitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'})
         'fitlog.exercisetype': {
             'fitness_type': ('models.ForeignKey', ['FitnessType'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
-            'muscle_group': ('models.ForeignKey', ['MuscleGroup'], {'null': 'True', 'blank': 'True'}),
+            'muscle_group': ('models.ForeignKey', ['MuscleGroup'],
+                             {'null': 'True', 'blank': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         },
         'fitlog.team': {
-            'description': ('models.TextField', [], {'max_length': '255', 'blank': 'True'}),
+            'description': ('models.TextField', [],
+                            {'max_length': '255', 'blank': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         }
     }
-    
+
     complete_apps = ['fitlog']

File fitlog/migrations/0003_bodyweight.py

-
 from south.db import db
 from django.db import models
 from fitlog.models import *
 
+
 class Migration:
-    
+
     def forwards(self, orm):
-        
+
         # Adding model 'BodyWeightLog'
         db.create_table('fitlog_bodyweightlog', (
             ('member', models.ForeignKey(orm['auth.User'])),
             ('comments', models.TextField(max_length=5000, blank=True)),
         ))
         db.send_create_signal('fitlog', ['BodyWeightLog'])
-        
-    
-    
+
     def backwards(self, orm):
-        
+
         # Deleting model 'BodyWeightLog'
         db.delete_table('fitlog_bodyweightlog')
-        
-    
-    
+
     models = {
         'fitlog.musclegroup': {
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'reps': ('models.SmallIntegerField', [], {}),
             'sequence': ('models.SmallIntegerField', [], {}),
             'weight': ('models.SmallIntegerField', [], {}),
-            'weight_log_detail': ('models.ForeignKey', ['WeightFitLogDetail'], {})
+            'weight_log_detail': ('models.ForeignKey', ['WeightFitLogDetail'],
+                                  {})
         },
         'fitlog.fitlog': {
-            'comments': ('models.TextField', [], {'max_length': '5000', 'blank': 'True'}),
-            'create_date': ('models.DateTimeField', [], {'auto_now_add': 'True'}),
+            'comments': ('models.TextField', [], {'max_length': '5000',
+                                                  'blank': 'True'}),
+            'create_date': ('models.DateTimeField', [],
+                            {'auto_now_add': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'last_update': ('models.DateTimeField', [], {'auto_now': 'True'}),
             'log_date': ('models.DateField', [], {}),
             'total_time': ('models.TimeField', [], {})
         },
         'fitlog.cardiofitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
-            'distance': ('models.DecimalField', [], {'max_digits': '5', 'decimal_places': '1'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
+            'distance': ('models.DecimalField', [], {'max_digits': '5',
+                                                     'decimal_places': '1'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'total_time': ('models.TimeField', [], {})
         },
         'fitlog.bodyweightlog': {
-            'comments': ('models.TextField', [], {'max_length': '5000', 'blank': 'True'}),
+            'comments': ('models.TextField', [], {'max_length': '5000',
+                                                  'blank': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'member': ('models.ForeignKey', ['User'], {}),
-            'weight': ('models.DecimalField', [], {'max_digits': '5', 'decimal_places': '1'}),
+            'weight': ('models.DecimalField', [], {'max_digits': '5',
+                                                   'decimal_places': '1'}),
             'weight_date': ('models.DateField', [], {})
         },
         'auth.user': {
             'id': ('models.AutoField', [], {'primary_key': 'True'})
         },
         'fitlog.team': {
-            'description': ('models.TextField', [], {'max_length': '255', 'blank': 'True'}),
+            'description': ('models.TextField', [], {'max_length': '255',
+                                                     'blank': 'True'}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         },
         'fitlog.weightfitlogdetail': {
-            'comments': ('models.CharField', [], {'max_length': '500', 'blank': 'True'}),
+            'comments': ('models.CharField', [], {'max_length': '500',
+                                                  'blank': 'True'}),
             'exercise_type': ('models.ForeignKey', ['ExerciseType'], {}),
             'fit_log': ('models.ForeignKey', ['FitLog'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'})
         'fitlog.exercisetype': {
             'fitness_type': ('models.ForeignKey', ['FitnessType'], {}),
             'id': ('models.AutoField', [], {'primary_key': 'True'}),
-            'muscle_group': ('models.ForeignKey', ['MuscleGroup'], {'null': 'True', 'blank': 'True'}),
+            'muscle_group': ('models.ForeignKey', ['MuscleGroup'],
+                             {'null': 'True', 'blank': 'True'}),
             'name': ('models.CharField', [], {'max_length': '50'})
         },
         'fitlog.userprofile': {
             'user': ('models.ForeignKey', ['User'], {'unique': 'True'})
         }
     }
-    
+
     complete_apps = ['fitlog']

File fitlog/models.py

 from django.db import models
 from django.contrib.auth.models import User
+
 from fitlog.utils import addDateTimes
-
 from fitlog.choices import WEIGHT_CHOICES, REP_CHOICES, GENDER_CHOICES
 from fitlog.managers import (
     FitLogManager, CardioManager, WeightManager, BodyWeightLogManager)
 
+
 class UserProfile(models.Model):
-     
+
   # This is the only required field
-  user = models.ForeignKey(User, unique=True)
-  gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
-  
-  def __unicode__(self):
-      return u'%s' % self.user.username
+    user = models.ForeignKey(User, unique=True)
+    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
+
+    def __unicode__(self):
+        return u'%s' % self.user.username
+
 
 class Team(models.Model):
     name = models.CharField(max_length=50)
-    description = models.TextField(max_length=255,blank=True)
-    
+    description = models.TextField(max_length=255, blank=True)
+
+
 class FitLog(models.Model):
     member = models.ForeignKey(User)
     create_date = models.DateTimeField(auto_now_add=True)
     log_date = models.DateField()
     total_time = models.TimeField(blank=True, null=True)
     title = models.CharField(max_length=255)
-    comments = models.TextField(max_length=5000,blank=True)
-    
+    comments = models.TextField(max_length=5000, blank=True)
+
     objects = FitLogManager()
-    
+
     def __init__(self, *args, **kwargs):
-        super(FitLog,self).__init__(*args,**kwargs)
+        super(FitLog, self).__init__(*args, **kwargs)
         self.__total_exercises = None
         self.__total_sets = None
         self.__total_reps = None
         self.__training_volume = None
         self.__cardio_min = None
         self.__cardio_distance = None
-        self.__calculated = False        
-    
+        self.__calculated = False
+
     def __calculate_totals(self):
         if not self.__calculated:
             if self.weightfitlogdetail_set:
             else:
                 self.__total_exercises = 0
 
-
-
             if self.weightfitlogdetail_set:
                 wl = self.weightfitlogdetail_set.all()
                 for w in wl:
                             self.__total_reps = 0
                         if not self.__training_volume:
                             self.__training_volume = 0
-                                    
-                        self.__total_sets = self.__total_sets + 1                            
+
+                        self.__total_sets = self.__total_sets + 1
                         self.__total_reps = self.__total_reps + wd.reps
                         if wd.reps and wd.weight:
-                            self.__training_volume = self.__training_volume + (wd.reps * wd.weight )                        
-    
+                            self.__training_volume = self.__training_volume + (
+                                wd.reps * wd.weight)
+
             if self.cardiofitlogdetail_set:
                 cl = self.cardiofitlogdetail_set.all()
                 for c in cl:
                             self.__cardio_min = 0
                         if not self.__cardio_distance:
                             self.__cardio_distance = 0
-                                                                
-                        self.__cardio_min = addDateTimes(self.__cardio_min,c.total_time)
-                        self.__cardio_distance = self.__cardio_distance + c.distance
-                
+
+                        self.__cardio_min = addDateTimes(self.__cardio_min,
+                                                         c.total_time)
+                        self.__cardio_distance = (self.__cardio_distance +
+                                                  c.distance)
+
             self.__calculated = True
-            
-    
+
     @property
     def total_exercises(self):
         if not self.__total_exercises:
             self.__calculate_totals()
         return self.__total_exercises
-    
+
     @property
     def total_sets(self):
         if not self.__total_sets:
-            self.__calculate_totals()    
+            self.__calculate_totals()
         return self.__total_sets
-    
+
     @property
     def total_reps(self):
         if not self.__total_reps:
-            self.__calculate_totals()    
+            self.__calculate_totals()
         return self.__total_reps
-    
+
     @property
     def training_volume(self):
         if not self.__training_volume:
-            self.__calculate_totals()    
+            self.__calculate_totals()
         return self.__training_volume
-    
+
     @property
     def cardio_min(self):
         if not self.__cardio_min:
-            self.__calculate_totals()    
+            self.__calculate_totals()
         return self.__cardio_min
-    
+
     @property
     def cardio_distance(self):
         if not self.__cardio_distance:
-            self.__calculate_totals()    
+            self.__calculate_totals()
         return self.__cardio_distance
-    
+
+
 class FitnessType(models.Model):
     name = models.CharField(max_length=50)
-    
+
     def __unicode__(self):
-      return self.name
+        return self.name
+
 
 class MuscleGroup(models.Model):
     name = models.CharField(max_length=100)
-    
+
     def __unicode__(self):
-      return self.name
+        return self.name
+
 
 class ExerciseType(models.Model):
     fitness_type = models.ForeignKey(FitnessType)
-    muscle_group = models.ForeignKey(MuscleGroup,blank=True,null=True)
+    muscle_group = models.ForeignKey(MuscleGroup, blank=True, null=True)
     name = models.CharField(max_length=50)
-    
+
     cardio_objects = CardioManager()
     weight_objects = WeightManager()
-    
+
     def __unicode__(self):
         if self.muscle_group:
-            name = "[%s]  %s" % (self.muscle_group.name,self.name)
+            name = "[%s]  %s" % (self.muscle_group.name, self.name)
         else:
             name = "%s " % (self.name)
         return name
-    
+
+
 class FitLogDetail(models.Model):
     fit_log = models.ForeignKey(FitLog)
     exercise_type = models.ForeignKey(ExerciseType)
-    comments = models.CharField(max_length=500,blank=True)
-    
+    comments = models.CharField(max_length=500, blank=True)
+
     class Meta:
         abstract = True
-    
+
+
 class CardioFitLogDetail(FitLogDetail):
     total_time = models.TimeField(blank=True, null=True)
-    distance = models.DecimalField(max_digits=5,decimal_places=1)
- 
+    distance = models.DecimalField(max_digits=5, decimal_places=1)
+
+
 #TODO PERFORMANCE : Make this better..
 class WeightFitLogDetail(FitLogDetail):
     __weights = None
-    
+
     def __get_weightlogset(self):
         if not self.__weights:
             self.__weights = self.weightlogset_set.all()
         return self.__weights
-    
+
     def get_weights(self):
         weights = self.__get_weightlogset()
         out = None
                 out = "%s" % w.weight
             else:
                 out = out + "/%s" % w.weight
-            
+
         return out
-    
+
     def get_reps(self):
         weights = self.__get_weightlogset()
         out = None
     reps = models.SmallIntegerField(choices=REP_CHOICES)
 
 
-
 class BodyWeightLog(models.Model):
     member = models.ForeignKey(User)
-    weight = models.DecimalField(max_digits=5,decimal_places=1)
+    weight = models.DecimalField(max_digits=5, decimal_places=1)
     weight_date = models.DateField()
-    comments = models.TextField(max_length=5000,blank=True)
-    
+    comments = models.TextField(max_length=5000, blank=True)
+
     objects = BodyWeightLogManager()
-    

File fitlog/templatetags/fitlog_tags.py

 
 register = Library()
 
-@register.inclusion_tag('fitlog/tags/list_logs.html',takes_context=True)
+
+@register.inclusion_tag('fitlog/tags/list_logs.html', takes_context=True)
 def list_recent_logs(context):
-    fit_logs = FitLog.objects.latest()   
+    fit_logs = FitLog.objects.latest()
     return {'fit_logs': fit_logs, "request": context.get('request')}
 
-@register.inclusion_tag('fitlog/tags/list_logs.html',takes_context=True)
-def list_user_logs(context,username):
+
+@register.inclusion_tag('fitlog/tags/list_logs.html', takes_context=True)
+def list_user_logs(context, username):
     try:
         user = User.objects.get(username=username)
-        fit_logs = FitLog.objects.by_member(user)   
-        return {'fit_logs': fit_logs, "request":context.get('request')}
+        fit_logs = FitLog.objects.by_member(user)
+        return {'fit_logs': fit_logs, "request": context.get('request')}
     except User.DoesNotExist:
         pass
-    return {"request":context.get('request')}
+    return {"request": context.get('request')}
 
-@register.inclusion_tag('fitlog/tags/stats.html',takes_context=True)
+
+@register.inclusion_tag('fitlog/tags/stats.html', takes_context=True)
 def stats(context):
     num_logs = FitLog.objects.number_of_logs()
-    num_members = User.objects.filter(is_active=True).count()  
-    return {'num_logs' : num_logs,'num_members':num_members,
-            "request":context.get('request')}
+    num_members = User.objects.filter(is_active=True).count()
+    return {'num_logs': num_logs, 'num_members': num_members,
+            "request": context.get('request')}
+
 
 @register.inclusion_tag('fitlog/tags/weight_training_list.html')
-def weight_training_list(fitlog): 
-    return { 'fitlog' : fitlog}
+def weight_training_list(fitlog):
+    return {'fitlog': fitlog}
+
 
 @register.inclusion_tag('fitlog/tags/cardio_list.html')
-def cardio_list(fitlog): 
-    return { 'fitlog' : fitlog}
+def cardio_list(fitlog):
+    return {'fitlog': fitlog}
+
 
 @register.inclusion_tag('fitlog/tags/fitlog_detail.html')
-def view_fitlog_detail(fitlog): 
-    return { 'fitlog' : fitlog}
+def view_fitlog_detail(fitlog):
+    return {'fitlog': fitlog}

File fitlog/urls.py

         name="add_bodyweight_log"),
     url(r'^bodyweight-log/$', views.bodyweight_log, name="bodyweight_log"),
     url(r'^edit-fitlog/(?P<fitlog_id>\w+)$', views.edit_fitlog,
-         name="edit_fitlog"),
+        name="edit_fitlog"),
     url(r'^add-cardio/(?P<fitlog_id>\w+)$', views.add_cardio,
-         name='add_cardio'),
+        name='add_cardio'),
     url(r'^add-weight-training/(?P<fitlog_id>\w+)$',
-         views.add_weight_training_log, name='add_weight_training_log'),
+        views.add_weight_training_log, name='add_weight_training_log'),
     url(r'^fitlog/(?P<fitlog_id>\w+)$', views.view_fitlog,
-         name='view_fitlog'),
+        name='view_fitlog'),
     url(r'^changelog/$', TemplateView.as_view(
-         template_name='fitlog/changelog.html'), name='changelog'),
+        template_name='fitlog/changelog.html'), name='changelog'),
 )
 
 # for login/logout
         name='auth_login'),
     url(r'^logout/$', auth_views.logout, {'template_name': 'logout.html'},
         name='auth_logout'),
-)
+)

File fitlog/utils.py

 from datetime import time
 
-def addDateTimes(time_1,time_2):
+
+def addDateTimes(time_1, time_2):
     """
         Take in two datetime.time objects, add them up and return the total
-        
-        >>> addDateTimes(datetime.time(hour=1,minute=1,second=1),datetime.time(hour=1,minute=1,second=1))
+
+        >>> datetime1 = datetime.time(hour=1,minute=1,second=1)
+        >>> datetime2 = datetime.time(hour=1,minute=1,second=1)
+        >>> addDateTimes(datetime1, datetime2)
         datetime.time(2,2,2)
-        
+
     """
     if time_1 and not time_2:
         return time_1
         t2_m = time_2.minute
         t1_s = time_1.second
         t2_s = time_2.second
-        
+
         t_h = t1_h + t2_h
         t_m = t1_m + t2_m
         t_s = t1_s + t2_s
-        
-        s_r = t_s/60
-        s = t_s%60
-        
+
+        s_r = t_s / 60
+        s = t_s % 60
+
         t_m = t_m + s_r
         m_r = t_m / 60
-        m = t_m%60
-        
+        m = t_m % 60
+
         h = t_h + m_r
-        
-        return_time = time(hour=h,minute=m,second=s)
-        return return_time
+
+        return_time = time(hour=h, minute=m, second=s)
+        return return_time

File fitlog/views.py

 from django.shortcuts import get_object_or_404, render_to_response
 from django.template import RequestContext
 
-from fitlog.models import FitLog,BodyWeightLog
+from fitlog.models import FitLog, BodyWeightLog
 from fitlog.forms import (
     FitLogForm, CardioLogForm, WeightLogForm, WeightLogSetForm,
-    WeightLogSetFormSet,BodyWeightForm)
+    WeightLogSetFormSet, BodyWeightForm)
 
 
 def render_response(request, template_name, template_params={}):
-    return render_to_response(template_name, 
-        context_instance=RequestContext(request, template_params))
+    return render_to_response(
+        template_name, context_instance=RequestContext(
+            request, template_params))
+
 
 def home(request):
     return render_response(request, 'fitlog/home.html', {})
-    
+
+
 @login_required
 def mylogs(request):
     return render_response(request, 'fitlog/my_logs.html', {})
-  
-@login_required    
+
+
+@login_required
 def add_log(request):
-    
+
     user = request.user
-        
+
     if request.method == 'POST':
         form = FitLogForm(request.POST)
         if form.is_valid():
             fit_log = form.save(user)
-            return HttpResponseRedirect(reverse('view_fitlog', args=(fit_log.id,)))
-    else :
-        form = FitLogForm()             
-    return render_response(request, 'fitlog/add_log.html', {'form':form,})
+            return HttpResponseRedirect(reverse('view_fitlog',
+                                                args=(fit_log.id, )))
+    else:
+        form = FitLogForm()
+    return render_response(request, 'fitlog/add_log.html', {'form': form})
+
 
 @login_required
-def add_cardio(request,fitlog_id):
+def add_cardio(request, fitlog_id):
     user = request.user
     fit_log = get_object_or_404(FitLog, id=fitlog_id, member=user)
-            
+
     if request.method == 'POST':
         form = CardioLogForm(request.POST)
         if form.is_valid():
             form.save(fit_log)
-            return HttpResponseRedirect(reverse('view_fitlog', args=(fit_log.id,)))
-    else :
-        form = CardioLogForm()             
-    return render_response(request, 'fitlog/add_cardio.html', {'form':form,'fitlog':fit_log})
+            return HttpResponseRedirect(reverse('view_fitlog',
+                                                args=(fit_log.id, )))
+    else:
+        form = CardioLogForm()
+    return render_response(request, 'fitlog/add_cardio.html',
+                           {'form': form, 'fitlog': fit_log})
+
 
 @login_required
-def add_weight_training_log(request,fitlog_id):
+def add_weight_training_log(request, fitlog_id):
     user = request.user
     fit_log = get_object_or_404(FitLog, id=fitlog_id, member=user)
-    form_set = formset_factory(WeightLogSetForm, extra=5, formset=WeightLogSetFormSet)
-            
+    form_set = formset_factory(
+        WeightLogSetForm, extra=5, formset=WeightLogSetFormSet)
+
     if request.method == 'POST':
         form = WeightLogForm(request.POST)
-        weight_form_set = form_set(request.POST)  
+        weight_form_set = form_set(request.POST)
         if form.is_valid() and weight_form_set.is_valid():
             weight_log = form.save(fit_log)
             weight_form_set.save(weight_log)
-            return HttpResponseRedirect(reverse('view_fitlog', args=(fit_log.id,)))
-    else :
+            return HttpResponseRedirect(reverse(
+                'view_fitlog', args=(fit_log.id, )))
+    else:
         form = WeightLogForm()
-        weight_form_set = form_set()         
-    return render_response(request, 'fitlog/add_weight_training.html', {'form':form,'fitlog':fit_log,'weight_form_set':weight_form_set})
+        weight_form_set = form_set()
+    return render_response(request, 'fitlog/add_weight_training.html',
+                           {'form': form, 'fitlog': fit_log,
+                            'weight_form_set': weight_form_set})
+
 
 @login_required
-def view_fitlog(request,fitlog_id):
-    fit_log = get_object_or_404(FitLog, id=fitlog_id)            
-    return render_response(request, 'fitlog/fitlog.html', {'fitlog':fit_log,})
+def view_fitlog(request, fitlog_id):
+    fit_log = get_object_or_404(FitLog, id=fitlog_id)
+    return render_response(request, 'fitlog/fitlog.html', {'fitlog': fit_log})
+
 
 @login_required
-def edit_fitlog(request,fitlog_id):    
+def edit_fitlog(request, fitlog_id):
     user = request.user
-    fit_log = get_object_or_404(FitLog, id=fitlog_id,member=user)
-            
+    fit_log = get_object_or_404(FitLog, id=fitlog_id, member=user)
+
     if request.method == 'POST':
-        form = FitLogForm(request.POST,instance=fit_log)
+        form = FitLogForm(request.POST, instance=fit_log)
         if form.is_valid():
             form.save(user)
-            return HttpResponseRedirect(reverse('view_fitlog', args=(fit_log.id,)))
-    else :        
-        form = FitLogForm(instance=fit_log)             
-    return render_response(request, 'fitlog/edit_fitlog.html', {'form':form,'fitlog':fit_log})
+            return HttpResponseRedirect(reverse('view_fitlog',
+                                                args=(fit_log.id, )))
+    else:
+        form = FitLogForm(instance=fit_log)
+    return render_response(request, 'fitlog/edit_fitlog.html',
+                           {'form': form, 'fitlog': fit_log})
+
 
 @login_required
 def bodyweight_log(request):
     bodyweight_log = BodyWeightLog.objects.by_member(request.user)
-    return render_response(request, 'fitlog/bodyweight_log.html', {'bodyweight_log':bodyweight_log,})
+    return render_response(request, 'fitlog/bodyweight_log.html',
+                           {'bodyweight_log': bodyweight_log, })
 
-@login_required    
+
+@login_required
 def add_bodyweight_log(request):
-    
+
     user = request.user
-        
+
     if request.method == 'POST':
         form = BodyWeightForm(request.POST)
         if form.is_valid():
             fit_log = form.save(user)
             return HttpResponseRedirect(reverse('bodyweight_log'))
-    else :
-        form = BodyWeightForm()             
-    return render_response(request, 'fitlog/add_bodyweight_log.html', {'form':form,})
+    else:
+        form = BodyWeightForm()
+    return render_response(request, 'fitlog/add_bodyweight_log.html',
+                           {'form': form, })