Self hosted FLOSS fitness/workout, nutrition and weight tracker
Renane creation_date to date in weight app
Roland Geiderf28036780a33
diff --git a/wger/core/demo.py b/wger/core/demo.pyindex 688baa429..138f8a1b9 100644--- a/wger/core/demo.py+++ b/wger/core/demo.py@@ -188,13 +188,13 @@ def create_demo_entries(user):# (Body) weight entries#temp = []- existing_entries = [i.creation_date for i in WeightEntry.objects.filter(user=user)]+ existing_entries = [i.date for i in WeightEntry.objects.filter(user=user)]for i in range(1, 20):creation_date = datetime.date.today() - datetime.timedelta(days=i)if creation_date not in existing_entries:entry = WeightEntry(user=user,weight=80 + 0.5 * i + random.randint(1, 3),- creation_date=creation_date)+ date=creation_date)temp.append(entry)WeightEntry.objects.bulk_create(temp)diff --git a/wger/core/models.py b/wger/core/models.pyindex 8e15a2b8d..f371d4edd 100644--- a/wger/core/models.py+++ b/wger/core/models.py@@ -434,12 +434,12 @@ by the US Department of Agriculture. It is extremely complete, with around'''if (not WeightEntry.objects.filter(user=self.user).exists()or (datetime.date.today()- - WeightEntry.objects.filter(user=self.user).latest().creation_date+ - WeightEntry.objects.filter(user=self.user).latest().date> datetime.timedelta(days=3))):entry = WeightEntry()entry.weight = weightentry.user = self.user- entry.creation_date = datetime.date.today()+ entry.date = datetime.date.today()entry.save()# Update the last entrydiff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.htmlindex cdd5afd60..03b48db14 100644--- a/wger/core/templates/user/overview.html+++ b/wger/core/templates/user/overview.html@@ -112,7 +112,7 @@{% for weight in weight_entries %}<tr><td>- {{weight.creation_date}}+ {{weight.date}}</td><td>{{weight.weight}} {% trans_weight_unit 'kg' current_user %}diff --git a/wger/core/tests/test_index.py b/wger/core/tests/test_index.pyindex 38109c2a2..1ed6bbded 100644--- a/wger/core/tests/test_index.py+++ b/wger/core/tests/test_index.py@@ -79,7 +79,7 @@ class DashboardTestCase(WorkoutManagerTestCase):#self.client.post(reverse('weight:add'),{'weight': 100,- 'creation_date': '2012-01-01',+ 'date': '2012-01-01','user': 1},)response = self.client.get(reverse('core:dashboard'))diff --git a/wger/core/tests/test_preferences.py b/wger/core/tests/test_preferences.pyindex 9bf7aa302..89fc9047b 100644--- a/wger/core/tests/test_preferences.py+++ b/wger/core/tests/test_preferences.py@@ -105,7 +105,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):entry = user.userprofile.user_bodyweight(80)count_after = WeightEntry.objects.filter(user=user).count()self.assertEqual(count_before, count_after - 1)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())def test_bodyweight_new_2(self):'''@@ -114,13 +114,13 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):user = User.objects.get(pk=2)count_before = WeightEntry.objects.filter(user=user).count()last_entry = WeightEntry.objects.filter(user=user).latest()- last_entry.creation_date = datetime.date.today() - datetime.timedelta(weeks=1)+ last_entry.date = datetime.date.today() - datetime.timedelta(weeks=1)last_entry.save()entry = user.userprofile.user_bodyweight(80)count_after = WeightEntry.objects.filter(user=user).count()self.assertEqual(count_before, count_after - 1)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())def test_bodyweight_no_entries(self):'''@@ -133,7 +133,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):entry = user.userprofile.user_bodyweight(80)count_after = WeightEntry.objects.filter(user=user).count()self.assertEqual(count_before, count_after - 1)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())def test_bodyweight_edit(self):'''@@ -141,7 +141,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):'''user = User.objects.get(pk=2)last_entry = WeightEntry.objects.filter(user=user).latest()- last_entry.creation_date = datetime.date.today() - datetime.timedelta(days=3)+ last_entry.date = datetime.date.today() - datetime.timedelta(days=3)last_entry.save()count_before = WeightEntry.objects.filter(user=user).count()@@ -149,7 +149,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):count_after = WeightEntry.objects.filter(user=user).count()self.assertEqual(count_before, count_after)self.assertEqual(entry.pk, last_entry.pk)- self.assertEqual(entry.creation_date, last_entry.creation_date)+ self.assertEqual(entry.date, last_entry.date)self.assertEqual(entry.weight, 100)def test_bodyweight_edit_2(self):@@ -158,7 +158,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):'''user = User.objects.get(pk=2)last_entry = WeightEntry.objects.filter(user=user).latest()- last_entry.creation_date = datetime.date.today()+ last_entry.date = datetime.date.today()last_entry.save()count_before = WeightEntry.objects.filter(user=user).count()@@ -166,7 +166,7 @@ class UserBodyweightTestCase(WorkoutManagerTestCase):count_after = WeightEntry.objects.filter(user=user).count()self.assertEqual(count_before, count_after)self.assertEqual(entry.pk, last_entry.pk)- self.assertEqual(entry.creation_date, last_entry.creation_date)+ self.assertEqual(entry.date, last_entry.date)self.assertEqual(entry.weight, 100)@@ -181,7 +181,7 @@ class PreferencesCalculationsTestCase(WorkoutManagerTestCase):self.user_login('test')user = User.objects.get(pk=2)entry = WeightEntry()- entry.creation_date = datetime.datetime.today()+ entry.date = datetime.datetime.today()entry.user = userentry.weight = 100entry.save()diff --git a/wger/core/tests/test_temporary_users.py b/wger/core/tests/test_temporary_users.pyindex 7150cafc8..7910588b3 100644--- a/wger/core/tests/test_temporary_users.py+++ b/wger/core/tests/test_temporary_users.py@@ -86,7 +86,7 @@ class DemoUserTestCase(WorkoutManagerTestCase):creation_date = datetime.date.today() - datetime.timedelta(days=i)entry = WeightEntry(user=user,weight=80 + 0.5 * i + random.randint(1, 3),- creation_date=creation_date)+ date=creation_date)temp.append(entry)WeightEntry.objects.bulk_create(temp)create_demo_entries(user)diff --git a/wger/core/views/misc.py b/wger/core/views/misc.pyindex de7dae505..14c1459d4 100644--- a/wger/core/views/misc.py+++ b/wger/core/views/misc.py@@ -103,7 +103,7 @@ def dashboard(request):# Load the last logged weight entry, if one existstry:- weight = WeightEntry.objects.filter(user=request.user).latest('creation_date')+ weight = WeightEntry.objects.filter(user=request.user).latest('date')except ObjectDoesNotExist:weight = Falsetemplate_data['weight'] = weightdiff --git a/wger/core/views/user.py b/wger/core/views/user.pyindex 75f647e78..26355fdd7 100644--- a/wger/core/views/user.py+++ b/wger/core/views/user.py@@ -434,7 +434,7 @@ class UserDetailView(WgerPermissionMixin, DetailView):'last_log': logs.last()})context['workouts'] = outcontext['weight_entries'] = WeightEntry.objects.filter(user=self.object)\- .order_by('-creation_date')[:5]+ .order_by('-date')[:5]context['nutrition_plans'] = NutritionPlan.objects.filter(user=self.object)\.order_by('-creation_date')[:5]context['session'] = WorkoutSession.objects.filter(user=self.object).order_by('-date')[:10]diff --git a/wger/manager/management/commands/email-weight-reminder.py b/wger/manager/management/commands/email-weight-reminder.pyindex d4b75fc21..ff83e5007 100644--- a/wger/manager/management/commands/email-weight-reminder.py+++ b/wger/manager/management/commands/email-weight-reminder.py@@ -49,7 +49,7 @@ class Command(BaseCommand):today = datetime.datetime.now().date()try:- last_entry = WeightEntry.objects.filter(user=profile.user).latest().creation_date+ last_entry = WeightEntry.objects.filter(user=profile.user).latest().datedatediff = (today - last_entry).daysif datediff >= profile.num_days_weight_reminder:diff --git a/wger/manager/tests/test_email_weight_reminder.py b/wger/manager/tests/test_email_weight_reminder.pyindex c6c673514..6a4e68705 100644--- a/wger/manager/tests/test_email_weight_reminder.py+++ b/wger/manager/tests/test_email_weight_reminder.py@@ -59,7 +59,7 @@ class EmailWeightReminderTestCase(WorkoutManagerTestCase):user.save()weightEntry = WeightEntry.objects.filter(user=user).get(pk=3)- weightEntry.creation_date = datetime.now().date() - timedelta(days=2)+ weightEntry.date = datetime.now().date() - timedelta(days=2)weightEntry.save()user.userprofile.num_days_weight_reminder = 1@@ -74,7 +74,7 @@ class EmailWeightReminderTestCase(WorkoutManagerTestCase):user.save()weightEntry = WeightEntry.objects.filter(user=user).get(pk=3)- weightEntry.creation_date = datetime.now().date() - timedelta(days=1)+ weightEntry.date = datetime.now().date() - timedelta(days=1)weightEntry.save()user.userprofile.num_days_weight_reminder = 1@@ -89,7 +89,7 @@ class EmailWeightReminderTestCase(WorkoutManagerTestCase):user.save()weightEntry = WeightEntry.objects.filter(user=user).latest()- weightEntry.creation_date = datetime.now().date()+ weightEntry.date = datetime.now().date()weightEntry.save()user.userprofile.num_days_weight_reminder = 3diff --git a/wger/nutrition/tests/test_bmi.py b/wger/nutrition/tests/test_bmi.pyindex 46392d847..ded112b82 100644--- a/wger/nutrition/tests/test_bmi.py+++ b/wger/nutrition/tests/test_bmi.py@@ -97,7 +97,7 @@ class BmiTestCase(WorkoutManagerTestCase):# Existing weight entry is from today, is updatedentry2.delete()- entry1.creation_date = datetime.date.today()+ entry1.date = datetime.date.today()entry1.save()response = self.client.post(reverse('nutrition:bmi:calculate'),{'height': 180,@@ -115,4 +115,4 @@ class BmiTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)entry = WeightEntry.objects.filter(user=user).latest()self.assertEqual(entry.weight, 80)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())diff --git a/wger/nutrition/tests/test_calories_calculator.py b/wger/nutrition/tests/test_calories_calculator.pyindex 305f8a41e..82e7a653a 100644--- a/wger/nutrition/tests/test_calories_calculator.py+++ b/wger/nutrition/tests/test_calories_calculator.py@@ -81,7 +81,7 @@ class CaloriesCalculatorTestCase(WorkoutManagerTestCase):# Existing weight entry is from today, is updatedentry2.delete()- entry1.creation_date = datetime.date.today()+ entry1.date = datetime.date.today()entry1.save()response = self.client.post(reverse('nutrition:bmi:calculate'),{'height': 180,@@ -99,7 +99,7 @@ class CaloriesCalculatorTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)entry = WeightEntry.objects.filter(user=user).latest()self.assertEqual(entry.weight, 80)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())def test_bmr(self):'''@@ -138,7 +138,7 @@ class CaloriesCalculatorTestCase(WorkoutManagerTestCase):# Existing weight entry is from today, is updatedentry2.delete()- entry1.creation_date = datetime.date.today()+ entry1.date = datetime.date.today()entry1.save()response = self.client.post(reverse('nutrition:calories:bmr'),{'age': 30,@@ -160,4 +160,4 @@ class CaloriesCalculatorTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)entry = WeightEntry.objects.filter(user=user).latest()self.assertEqual(entry.weight, 80)- self.assertEqual(entry.creation_date, datetime.date.today())+ self.assertEqual(entry.date, datetime.date.today())diff --git a/wger/weight/api/resources.py b/wger/weight/api/resources.pyindex 02284fad5..5aca8c513 100644--- a/wger/weight/api/resources.py+++ b/wger/weight/api/resources.py@@ -38,5 +38,5 @@ class WeightEntryResource(ModelResource):authentication = ApiKeyAuthentication()authorization = UserObjectsOnlyAuthorization()filtering = {'id': ALL,- 'creation_date': ALL,+ 'date': ALL,'weight': ALL}diff --git a/wger/weight/api/views.py b/wger/weight/api/views.pyindex de4c6d971..1dd14b158 100644--- a/wger/weight/api/views.py+++ b/wger/weight/api/views.py@@ -29,7 +29,7 @@ class WeightEntryViewSet(viewsets.ModelViewSet):serializer_class = WeightEntrySerializeris_private = Trueordering_fields = '__all__'- filter_fields = ('creation_date',+ filter_fields = ('date','weight')def get_queryset(self):diff --git a/wger/weight/fixtures/test-weight-data.json b/wger/weight/fixtures/test-weight-data.jsonindex e88311470..f340e017b 100644--- a/wger/weight/fixtures/test-weight-data.json+++ b/wger/weight/fixtures/test-weight-data.json@@ -5,7 +5,7 @@"fields": {"user": 2,"weight": 77,- "creation_date": "2012-10-01"+ "date": "2012-10-01"}},{@@ -14,7 +14,7 @@"fields": {"user": 2,"weight": 77.2,- "creation_date": "2012-10-10"+ "date": "2012-10-10"}},{@@ -23,7 +23,7 @@"fields": {"user": 2,"weight": 80.6,- "creation_date": "2012-11-01"+ "date": "2012-11-01"}},{@@ -32,7 +32,7 @@"fields": {"user": 2,"weight": 80,- "creation_date": "2013-01-01"+ "date": "2013-01-01"}},{@@ -41,7 +41,7 @@"fields": {"user": 2,"weight": 81,- "creation_date": "2013-01-10"+ "date": "2013-01-10"}},{@@ -50,7 +50,7 @@"fields": {"user": 2,"weight": 82,- "creation_date": "2013-01-20"+ "date": "2013-01-20"}},{@@ -59,7 +59,7 @@"fields": {"user": 2,"weight": 83,- "creation_date": "2013-01-30"+ "date": "2013-01-30"}}]diff --git a/wger/weight/forms.py b/wger/weight/forms.pyindex 6771cd488..95a597e32 100644--- a/wger/weight/forms.py+++ b/wger/weight/forms.py@@ -40,7 +40,7 @@ class WeightCsvImportForm(Form):class WeightForm(ModelForm):- creation_date = DateField(input_formats=DATE_FORMATS, widget=Html5DateInput())+ date = DateField(input_formats=DATE_FORMATS, widget=Html5DateInput())class Meta:model = WeightEntrydiff --git a/wger/weight/helpers.py b/wger/weight/helpers.pyindex 6c27acd67..d8e71b90c 100644--- a/wger/weight/helpers.py+++ b/wger/weight/helpers.py@@ -51,7 +51,7 @@ def parse_weight_csv(request, cleaned_data):parsed_date = datetime.datetime.strptime(row[0], cleaned_data['date_format'])parsed_weight = decimal.Decimal(row[1].replace(',', '.'))- weight_list.append(WeightEntry(creation_date=parsed_date,+ weight_list.append(WeightEntry(date=parsed_date,weight=parsed_weight,user=request.user))diff --git a/wger/weight/migrations/0002_auto_20150604_2139.py b/wger/weight/migrations/0002_auto_20150604_2139.pynew file mode 100644index 000000000..c77fa2272--- /dev/null+++ b/wger/weight/migrations/0002_auto_20150604_2139.py@@ -0,0 +1,27 @@+# -*- coding: utf-8 -*-+from __future__ import unicode_literals++from django.db import models, migrations+++class Migration(migrations.Migration):++ dependencies = [+ ('weight', '0001_initial'),+ ]++ operations = [+ migrations.AlterModelOptions(+ name='weightentry',+ options={'verbose_name': 'Weight entry', 'get_latest_by': 'date', 'ordering': ['date']},+ ),+ migrations.RenameField(+ model_name='weightentry',+ old_name='creation_date',+ new_name='date',+ ),+ migrations.AlterUniqueTogether(+ name='weightentry',+ unique_together=set([('date', 'user')]),+ ),+ ]diff --git a/wger/weight/models.py b/wger/weight/models.pyindex 4df8b34c5..21ca5ecac 100644--- a/wger/weight/models.py+++ b/wger/weight/models.py@@ -28,7 +28,7 @@ class WeightEntry(models.Model):'''Model for a weight point'''- creation_date = models.DateField(verbose_name=_('Date'))+ date = models.DateField(verbose_name=_('Date'))weight = models.DecimalField(verbose_name=_('Weight'),max_digits=5,decimal_places=2,@@ -50,15 +50,15 @@ class WeightEntry(models.Model):Metaclass to set some other properties'''verbose_name = _('Weight entry')- ordering = ["creation_date", ]- get_latest_by = "creation_date"- unique_together = ("creation_date", "user")+ ordering = ["date", ]+ get_latest_by = "date"+ unique_together = ("date", "user")def __str__(self):'''Return a more human-readable representation'''- return u"{0}: {1:.2f} kg".format(self.creation_date, self.weight)+ return u"{0}: {1:.2f} kg".format(self.date, self.weight)def get_owner_object(self):'''diff --git a/wger/weight/templates/import_csv_preview.html b/wger/weight/templates/import_csv_preview.htmlindex 32d79c53e..775b48dd2 100644--- a/wger/weight/templates/import_csv_preview.html+++ b/wger/weight/templates/import_csv_preview.html@@ -16,7 +16,7 @@</tr>{% for entry in weight_list %}<tr>- <td>{{ entry.creation_date|date:"SHORT_DATE_FORMAT" }}</td>+ <td>{{ entry.date|date:"SHORT_DATE_FORMAT" }}</td><td>{{ entry.weight }}</td></tr>{% endfor %}diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.pyindex b27de9701..bfed66b66 100644--- a/wger/weight/tests/test_entry.py+++ b/wger/weight/tests/test_entry.py@@ -88,7 +88,7 @@ class AddWeightEntryTestCase(WorkoutManagerAddTestCase):url = 'weight:add'user_fail = Falsedata = {'weight': decimal.Decimal(81.1).quantize(TWOPLACES),- 'creation_date': datetime.date(2013, 2, 1),+ 'date': datetime.date(2013, 2, 1),'user': 1}@@ -101,7 +101,7 @@ class EditWeightEntryTestCase(WorkoutManagerEditTestCase):url = 'weight:edit'pk = 1data = {'weight': 100,- 'creation_date': datetime.date(2013, 2, 1),+ 'date': datetime.date(2013, 2, 1),'user': 1}user_success = 'test'user_fail = 'admin'@@ -115,4 +115,4 @@ class WeightEntryTestCase(api_base_test.ApiBaseResourceTestCase):resource = WeightEntryprivate_resource = Truedata = {'weight': 100,- 'creation_date': datetime.date(2013, 2, 1)}+ 'date': datetime.date(2013, 2, 1)}diff --git a/wger/weight/views.py b/wger/weight/views.pyindex 7dd769d38..8348f2311 100644--- a/wger/weight/views.py+++ b/wger/weight/views.py@@ -62,7 +62,7 @@ class WeightAddView(WgerFormMixin, CreateView):to pass the user here.'''return {'user': self.request.user,- 'creation_date': formats.date_format(datetime.date.today(), "SHORT_DATE_FORMAT")}+ 'date': formats.date_format(datetime.date.today(), "SHORT_DATE_FORMAT")}def form_valid(self, form):'''@@ -88,7 +88,7 @@ class WeightUpdateView(WgerFormMixin, UpdateView):def get_context_data(self, **kwargs):context = super(WeightUpdateView, self).get_context_data(**kwargs)context['form_action'] = reverse('weight:edit', kwargs={'pk': self.object.id})- context['title'] = _('Edit weight entry for the %s') % self.object.creation_date+ context['title'] = _('Edit weight entry for the %s') % self.object.datereturn context@@ -115,7 +115,7 @@ def export_csv(request):writer.writerow([_('Weight').encode('utf8'), _('Date').encode('utf8')])for entry in weights:- writer.writerow([entry.weight, entry.creation_date])+ writer.writerow([entry.weight, entry.date])# Send the data to the browserresponse['Content-Disposition'] = 'attachment; filename=Weightdata.csv'@@ -136,9 +136,9 @@ def overview(request, username=None):template_data = {}min_date = WeightEntry.objects.filter(user=user).\- aggregate(Min('creation_date'))['creation_date__min']+ aggregate(Min('date'))['date__min']max_date = WeightEntry.objects.filter(user=user).\- aggregate(Max('creation_date'))['creation_date__max']+ aggregate(Max('date'))['date__max']if min_date:template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \{'year': min_date.year,@@ -169,7 +169,7 @@ def get_weight_data(request, username=None):if date_min and date_max:weights = WeightEntry.objects.filter(user=user,- creation_date__range=(date_min, date_max))+ date__range=(date_min, date_max))else:weights = WeightEntry.objects.filter(user=user)@@ -177,9 +177,9 @@ def get_weight_data(request, username=None):for i in weights:chart_data.append({'x': "%(month)s/%(day)s/%(year)s" % {- 'year': i.creation_date.year,- 'month': i.creation_date.month,- 'day': i.creation_date.day},+ 'year': i.date.year,+ 'month': i.date.month,+ 'day': i.date.day},'y': i.weight,'id': i.id})