Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Change weight DateField to a DateTimeField and removed previous date addition restrictions.

Cam Cecilc020002b051c
diff --git a/wger/core/demo.py b/wger/core/demo.py
index d5b870d19..7d6632e21 100644
--- a/wger/core/demo.py
+++ b/wger/core/demo.py
@@ -25,6 +25,7 @@ from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.http import HttpRequest
from django.utils.translation import gettext as _
+from django.utils import timezone
# wger
from wger.core.models import DaysOfWeek
@@ -191,16 +192,16 @@ def create_demo_entries(user):
# (Body) weight entries
#
temp = []
- 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),
- date=creation_date,
- )
- temp.append(entry)
+ creation_date = timezone.now() - datetime.timedelta(days=i)
+
+ entry = WeightEntry(
+ user=user,
+ weight=80 + 0.5 * i + random.randint(1, 3),
+ date=creation_date,
+ )
+ temp.append(entry)
+
WeightEntry.objects.bulk_create(temp)
#
diff --git a/wger/core/models/profile.py b/wger/core/models/profile.py
index 59e82527f..176c8ea25 100644
--- a/wger/core/models/profile.py
+++ b/wger/core/models/profile.py
@@ -28,6 +28,7 @@ from django.core.validators import (
)
from django.db import models
from django.db.models import IntegerField
+from django.utils import timezone
from django.utils.translation import gettext_lazy as _
# wger
@@ -513,23 +514,14 @@ by the US Department of Agriculture. It is extremely complete, with around
def user_bodyweight(self, weight):
"""
- Create a new weight entry as needed
+ Create a new weight entry and return it
"""
- if not WeightEntry.objects.filter(user=self.user).exists() or (
- datetime.date.today() - WeightEntry.objects.filter(user=self.user).latest().date
- > datetime.timedelta(days=3)
- ):
- entry = WeightEntry()
- entry.weight = weight
- entry.user = self.user
- entry.date = datetime.date.today()
- entry.save()
-
- # Update the last entry
- else:
- entry = WeightEntry.objects.filter(user=self.user).latest()
- entry.weight = weight
- entry.save()
+ entry = WeightEntry()
+ entry.weight = weight
+ entry.user = self.user
+ entry.date = timezone.now()
+ entry.save()
+
return entry
def get_owner_object(self):
diff --git a/wger/core/tests/test_preferences.py b/wger/core/tests/test_preferences.py
index ac5caf223..def8331f1 100644
--- a/wger/core/tests/test_preferences.py
+++ b/wger/core/tests/test_preferences.py
@@ -20,6 +20,7 @@ import logging
# Django
from django.contrib.auth.models import User
from django.urls import reverse
+from django.utils import timezone
# wger
from wger.core.tests.base_testcase import WgerTestCase
@@ -146,7 +147,7 @@ class UserBodyweightTestCase(WgerTestCase):
entry = user.userprofile.user_bodyweight(80)
count_after = WeightEntry.objects.filter(user=user).count()
self.assertEqual(count_before, count_after - 1)
- self.assertEqual(entry.date, datetime.date.today())
+ self.assertEqual(entry.date.date(), timezone.now().date())
def test_bodyweight_new_2(self):
"""
@@ -155,60 +156,41 @@ class UserBodyweightTestCase(WgerTestCase):
user = User.objects.get(pk=2)
count_before = WeightEntry.objects.filter(user=user).count()
last_entry = WeightEntry.objects.filter(user=user).latest()
- last_entry.date = datetime.date.today() - datetime.timedelta(weeks=1)
+ last_entry.date = timezone.now() - 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.date, datetime.date.today())
+ self.assertEqual(entry.date.date(), timezone.now().date())
- def test_bodyweight_no_entries(self):
+ def test_bodyweight_new_3(self):
"""
- Tests that a new weight entry is created if there are no weight entries
+ Tests that a new weight entry is created even if others exist today
"""
user = User.objects.get(pk=2)
- WeightEntry.objects.filter(user=user).delete()
-
count_before = WeightEntry.objects.filter(user=user).count()
- entry = user.userprofile.user_bodyweight(80)
- count_after = WeightEntry.objects.filter(user=user).count()
- self.assertEqual(count_before, count_after - 1)
- self.assertEqual(entry.date, datetime.date.today())
-
- def test_bodyweight_edit(self):
- """
- Tests that the last weight entry is edited
- """
- user = User.objects.get(pk=2)
last_entry = WeightEntry.objects.filter(user=user).latest()
- last_entry.date = datetime.date.today() - datetime.timedelta(days=3)
+ last_entry.date = timezone.now() - datetime.timedelta(hours=1)
last_entry.save()
- count_before = WeightEntry.objects.filter(user=user).count()
- entry = user.userprofile.user_bodyweight(100)
+ entry = user.userprofile.user_bodyweight(80)
count_after = WeightEntry.objects.filter(user=user).count()
- self.assertEqual(count_before, count_after)
- self.assertEqual(entry.pk, last_entry.pk)
- self.assertEqual(entry.date, last_entry.date)
- self.assertEqual(entry.weight, 100)
+ self.assertEqual(count_before, count_after - 1)
+ self.assertEqual(entry.date.date(), timezone.now().date())
- def test_bodyweight_edit_2(self):
+ def test_bodyweight_no_entries(self):
"""
- Tests that the last weight entry is edited
+ Tests that a new weight entry is created if there are no weight entries
"""
user = User.objects.get(pk=2)
- last_entry = WeightEntry.objects.filter(user=user).latest()
- last_entry.date = datetime.date.today()
- last_entry.save()
+ WeightEntry.objects.filter(user=user).delete()
count_before = WeightEntry.objects.filter(user=user).count()
- entry = user.userprofile.user_bodyweight(100)
+ entry = user.userprofile.user_bodyweight(80)
count_after = WeightEntry.objects.filter(user=user).count()
- self.assertEqual(count_before, count_after)
- self.assertEqual(entry.pk, last_entry.pk)
- self.assertEqual(entry.date, last_entry.date)
- self.assertEqual(entry.weight, 100)
+ self.assertEqual(count_before, count_after - 1)
+ self.assertEqual(entry.date.date(), timezone.now().date())
class PreferencesCalculationsTestCase(WgerTestCase):
@@ -223,7 +205,7 @@ class PreferencesCalculationsTestCase(WgerTestCase):
self.user_login('test')
user = User.objects.get(pk=2)
entry = WeightEntry()
- entry.date = datetime.datetime.today()
+ entry.date = timezone.now()
entry.user = user
entry.weight = 100
entry.save()
@@ -263,6 +245,10 @@ class PreferencesCalculationsTestCase(WgerTestCase):
self.user_login('test')
+ # Test User (pk=2)
+ # 180 cm, 20 years
+ # Last weight entry is 83 kg
+
# Male
user = User.objects.get(pk=2)
bmr = user.userprofile.calculate_basal_metabolic_rate()
diff --git a/wger/core/tests/test_temporary_users.py b/wger/core/tests/test_temporary_users.py
index 4f32b7651..998e4abec 100644
--- a/wger/core/tests/test_temporary_users.py
+++ b/wger/core/tests/test_temporary_users.py
@@ -21,6 +21,7 @@ from django.contrib.auth.models import User
from django.core.management import call_command
from django.http import HttpRequest
from django.urls import reverse
+from django.utils import timezone
# wger
from wger.core.demo import (
@@ -105,7 +106,7 @@ class DemoUserTestCase(WgerTestCase):
def test_demo_data_body_weight(self):
"""
- Tests that the helper function that creates demo data filters out
+ Tests that the helper function that creates demo data does not filter out
existing dates for the weight entries
"""
self.client.get(reverse('core:dashboard'))
@@ -114,7 +115,7 @@ class DemoUserTestCase(WgerTestCase):
temp = []
for i in range(1, 5):
- creation_date = datetime.date.today() - datetime.timedelta(days=i)
+ creation_date = timezone.now() - datetime.timedelta(days=i)
entry = WeightEntry(
user=user,
weight=80 + 0.5 * i + random.randint(1, 3),
@@ -125,7 +126,7 @@ class DemoUserTestCase(WgerTestCase):
create_demo_entries(user)
# Body weight
- self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)
+ self.assertEqual(WeightEntry.objects.filter(user=user).count(), 23)
def test_demo_user(self):
"""
diff --git a/wger/exercises/migrations/0031_WeightDateTime.py b/wger/exercises/migrations/0031_WeightDateTime.py
new file mode 100644
index 000000000..333db1757
--- /dev/null
+++ b/wger/exercises/migrations/0031_WeightDateTime.py
@@ -0,0 +1,53 @@
+# Generated by Django 4.2.16 on 2025-02-22 04:14
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('exercises', '0030_increase_author_field_length'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='exercise',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='exercisebase',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='exerciseimage',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='exercisevideo',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercise',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercisebase',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='historicalexerciseimage',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercisevideo',
+ name='license_author',
+ field=models.TextField(blank=True, help_text='If you are not the author, enter the name or source here.', max_length=3500, null=True, verbose_name='Author(s)'),
+ ),
+ ]
diff --git a/wger/nutrition/migrations/0025_WeightDateTime.py b/wger/nutrition/migrations/0025_WeightDateTime.py
new file mode 100644
index 000000000..fa7e9fbbe
--- /dev/null
+++ b/wger/nutrition/migrations/0025_WeightDateTime.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.16 on 2025-02-22 04:14
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('nutrition', '0024_remove_ingredient_status'),
+ ]
+
+ operations = [
+ migrations.RenameIndex(
+ model_name='ingredient',
+ new_name='nutrition_i_name_8f538f_gin',
+ old_name='nutrition_i_search__f274b7_gin',
+ ),
+ ]
diff --git a/wger/nutrition/models/plan.py b/wger/nutrition/models/plan.py
index 4010d287d..8adc30cf8 100644
--- a/wger/nutrition/models/plan.py
+++ b/wger/nutrition/models/plan.py
@@ -183,7 +183,7 @@ class NutritionPlan(models.Model):
)
if closest_entry_gte is None or closest_entry_lte is None:
return closest_entry_gte or closest_entry_lte
- if abs(closest_entry_gte.date - target) < abs(closest_entry_lte.date - target):
+ if abs(closest_entry_gte.date.date() - target) < abs(closest_entry_lte.date.date() - target):
return closest_entry_gte
else:
return closest_entry_lte
diff --git a/wger/nutrition/tests/test_calories_calculator.py b/wger/nutrition/tests/test_calories_calculator.py
index 42be1d8ed..6fdc67769 100644
--- a/wger/nutrition/tests/test_calories_calculator.py
+++ b/wger/nutrition/tests/test_calories_calculator.py
@@ -20,6 +20,7 @@ import json
# Django
from django.contrib.auth.models import User
from django.urls import reverse
+from django.utils import timezone
# wger
from wger.core.tests.base_testcase import WgerTestCase
@@ -90,7 +91,7 @@ class CaloriesCalculatorTestCase(WgerTestCase):
self.user_login('test')
user = User.objects.get(username=self.current_user)
- # Existing weight entry is old, a new one is created
+ # A new weight entry is always created
entry1 = WeightEntry.objects.filter(user=user).latest()
response = self.client.post(
reverse('nutrition:calories:bmr'), {'age': 30, 'height': 180, 'gender': 1, 'weight': 80}
@@ -100,18 +101,6 @@ class CaloriesCalculatorTestCase(WgerTestCase):
self.assertEqual(entry1.weight, 83)
self.assertEqual(entry2.weight, 80)
- # Existing weight entry is from today, is updated
- entry2.delete()
- entry1.date = datetime.date.today()
- entry1.save()
- response = self.client.post(
- reverse('nutrition:calories:bmr'), {'age': 30, 'height': 180, 'gender': 1, 'weight': 80}
- )
- self.assertEqual(response.status_code, 200)
- entry2 = WeightEntry.objects.filter(user=user).latest()
- self.assertEqual(entry1.pk, entry2.pk)
- self.assertEqual(entry2.weight, 80)
-
# No existing entries
WeightEntry.objects.filter(user=user).delete()
response = self.client.post(
@@ -120,4 +109,4 @@ class CaloriesCalculatorTestCase(WgerTestCase):
self.assertEqual(response.status_code, 200)
entry = WeightEntry.objects.filter(user=user).latest()
self.assertEqual(entry.weight, 80)
- self.assertEqual(entry.date, datetime.date.today())
+ self.assertEqual(entry.date.date(), timezone.now().date())
diff --git a/wger/utils/constants.py b/wger/utils/constants.py
index 3615b4d8a..530a7b0d0 100644
--- a/wger/utils/constants.py
+++ b/wger/utils/constants.py
@@ -37,6 +37,20 @@ DATE_FORMATS = [
'%Y-%m-%d', # '2012-10-25'
]
+# Valid datetime formats
+DATETIME_FORMATS = [
+ '%d.%m.%Y %H:%M:%S', # '25.10.2012 14:30:00'
+ '%d.%m.%Y %H:%M', # '25.10.2012 14:30'
+ '%d.%m.%y %H:%M:%S', # '25.10.12 14:30:00'
+ '%d.%m.%y %H:%M', # '25.10.12 14:30'
+ '%m/%d/%Y %H:%M:%S', # '10/25/2012 14:30:00'
+ '%m/%d/%Y %H:%M', # '10/25/2012 14:30'
+ '%m/%d/%y %H:%M:%S', # '10/25/12 14:30:00'
+ '%m/%d/%y %H:%M', # '10/25/12 14:30'
+ '%Y-%m-%d %H:%M:%S', # '2012-10-25 14:30:00'
+ '%Y-%m-%d %H:%M', # '2012-10-25 14:30'
+]
+
# Allowed tags, attributes and styles allowed in textareas edited with a JS
# editor. Everything not in these whitelists is stripped.
HTML_TAG_WHITELIST = {'b', 'i', 'strong', 'em', 'ul', 'ol', 'li', 'p'}
diff --git a/wger/weight/fixtures/test-weight-data.json b/wger/weight/fixtures/test-weight-data.json
index f340e017b..0b93f4f9b 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,
- "date": "2012-10-01"
+ "date": "2012-10-01T14:30:21.592Z"
}
},
{
@@ -14,7 +14,7 @@
"fields": {
"user": 2,
"weight": 77.2,
- "date": "2012-10-10"
+ "date": "2012-10-10T14:30:21.592Z"
}
},
{
@@ -23,7 +23,7 @@
"fields": {
"user": 2,
"weight": 80.6,
- "date": "2012-11-01"
+ "date": "2012-11-01T14:30:21.592Z"
}
},
{
@@ -32,7 +32,7 @@
"fields": {
"user": 2,
"weight": 80,
- "date": "2013-01-01"
+ "date": "2013-01-01T14:30:21.592Z"
}
},
{
@@ -41,7 +41,7 @@
"fields": {
"user": 2,
"weight": 81,
- "date": "2013-01-10"
+ "date": "2013-01-10T14:30:21.592Z"
}
},
{
@@ -50,7 +50,7 @@
"fields": {
"user": 2,
"weight": 82,
- "date": "2013-01-20"
+ "date": "2013-01-20T14:30:21.592Z"
}
},
{
@@ -59,7 +59,7 @@
"fields": {
"user": 2,
"weight": 83,
- "date": "2013-01-30"
+ "date": "2013-01-30T14:30:21.592Z"
}
}
]
diff --git a/wger/weight/forms.py b/wger/weight/forms.py
index 7a3809b3f..d944d9621 100644
--- a/wger/weight/forms.py
+++ b/wger/weight/forms.py
@@ -18,7 +18,7 @@
from django import forms
from django.forms import (
CharField,
- DateField,
+ DateTimeField,
Form,
ModelForm,
Textarea,
@@ -31,18 +31,24 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout
# wger
-from wger.utils.constants import DATE_FORMATS
+from wger.utils.constants import DATETIME_FORMATS
from wger.utils.widgets import Html5DateInput
from wger.weight.models import WeightEntry
-CSV_DATE_FORMAT = (
- ('%d.%m.%Y', 'DD.MM.YYYY (30.01.2012)'),
- ('%d.%m.%y', 'DD.MM.YY (30.01.12)'),
- ('%Y-%m-%d', 'YYYY-MM-DD (2012-01-30)'),
- ('%y-%m-%d', 'YY-MM-DD (12-01-30)'),
- ('%m/%d/%Y', 'MM/DD/YYYY (01/30/2012)'),
- ('%m/%d/%y', 'MM/DD/YY (01/30/12)'),
+CSV_DATETIME_FORMAT = (
+ ('%d.%m.%Y %H:%M:%S', 'DD.MM.YYYY HH:MM:SS (30.01.2012 14:30:00)'),
+ ('%d.%m.%Y %H:%M', 'DD.MM.YYYY HH:MM (30.01.2012 14:30)'),
+ ('%d.%m.%y %H:%M:%S', 'DD.MM.YY HH:MM:SS (30.01.12 14:30:00)'),
+ ('%d.%m.%y %H:%M', 'DD.MM.YY HH:MM (30.01.12 14:30)'),
+ ('%Y-%m-%d %H:%M:%S', 'YYYY-MM-DD HH:MM:SS (2012-01-30 14:30:00)'),
+ ('%Y-%m-%d %H:%M', 'YYYY-MM-DD HH:MM (2012-01-30 14:30)'),
+ ('%y-%m-%d %H:%M:%S', 'YY-MM-DD HH:MM:SS (12-01-30 14:30:00)'),
+ ('%y-%m-%d %H:%M', 'YY-MM-DD HH:MM (12-01-30 14:30)'),
+ ('%m/%d/%Y %H:%M:%S', 'MM/DD/YYYY HH:MM:SS (01/30/2012 14:30:00)'),
+ ('%m/%d/%Y %H:%M', 'MM/DD/YYYY HH:MM (01/30/2012 14:30)'),
+ ('%m/%d/%y %H:%M:%S', 'MM/DD/YY HH:MM:SS (01/30/12 14:30:00)'),
+ ('%m/%d/%y %H:%M', 'MM/DD/YY HH:MM (01/30/12 14:30)'),
)
@@ -52,7 +58,7 @@ class WeightCsvImportForm(Form):
"""
csv_input = CharField(widget=Textarea, label=_('Input'))
- date_format = forms.ChoiceField(choices=CSV_DATE_FORMAT, label=_('Date format'))
+ date_format = forms.ChoiceField(choices=CSV_DATETIME_FORMAT, label=_('Date format'))
def __init__(self, *args, **kwargs):
super(WeightCsvImportForm, self).__init__(*args, **kwargs)
@@ -66,7 +72,7 @@ class WeightCsvImportForm(Form):
class WeightForm(ModelForm):
- date = DateField(input_formats=DATE_FORMATS, widget=Html5DateInput())
+ date = DateTimeField(input_formats=DATETIME_FORMATS, widget=Html5DateInput())
class Meta:
model = WeightEntry
diff --git a/wger/weight/management/commands/dummy-generator-body-weight.py b/wger/weight/management/commands/dummy-generator-body-weight.py
index d6e6c04e2..c61cb556b 100644
--- a/wger/weight/management/commands/dummy-generator-body-weight.py
+++ b/wger/weight/management/commands/dummy-generator-body-weight.py
@@ -20,6 +20,7 @@ import random
# Django
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
+from django.utils import timezone
# wger
from wger.weight.models import WeightEntry
@@ -71,7 +72,7 @@ class Command(BaseCommand):
# Weight entries
for i in range(options['nr_entries']):
- creation_date = datetime.date.today() - datetime.timedelta(days=i)
+ creation_date = timezone.now() - datetime.timedelta(days=i)
if creation_date not in existing_entries:
entry = WeightEntry(
user=user,
diff --git a/wger/weight/management/commands/email-weight-reminder.py b/wger/weight/management/commands/email-weight-reminder.py
index 414390fc3..be8d625c8 100644
--- a/wger/weight/management/commands/email-weight-reminder.py
+++ b/wger/weight/management/commands/email-weight-reminder.py
@@ -21,7 +21,7 @@ from django.contrib.sites.models import Site
from django.core import mail
from django.core.management.base import BaseCommand
from django.template import loader
-from django.utils import translation
+from django.utils import translation, timezone
from django.utils.translation import gettext_lazy as _
# wger
@@ -45,7 +45,7 @@ class Command(BaseCommand):
if not profile.user.email:
continue
- today = datetime.datetime.now().date()
+ today = timezone.now()
try:
last_entry = WeightEntry.objects.filter(user=profile.user).latest().date
diff --git a/wger/weight/migrations/0004_WeightDateTime.py b/wger/weight/migrations/0004_WeightDateTime.py
new file mode 100644
index 000000000..a83ca27d0
--- /dev/null
+++ b/wger/weight/migrations/0004_WeightDateTime.py
@@ -0,0 +1,22 @@
+# Generated by Django 4.2.16 on 2025-02-22 04:14
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('weight', '0003_auto_20160416_1030'),
+ ]
+
+ operations = [
+ migrations.AlterUniqueTogether(
+ name='weightentry',
+ unique_together=set(),
+ ),
+ migrations.AlterField(
+ model_name='weightentry',
+ name='date',
+ field=models.DateTimeField(verbose_name='Date'),
+ ),
+ ]
diff --git a/wger/weight/models.py b/wger/weight/models.py
index 9030039f5..13a4a73ec 100644
--- a/wger/weight/models.py
+++ b/wger/weight/models.py
@@ -48,7 +48,7 @@ class WeightEntry(models.Model):
Model for a weight point
"""
- date = models.DateField(verbose_name=_('Date'))
+ date = models.DateTimeField(verbose_name=_('Date'))
weight = models.DecimalField(
verbose_name=_('Weight'),
max_digits=5,
@@ -80,7 +80,6 @@ class WeightEntry(models.Model):
'date',
]
get_latest_by = 'date'
- unique_together = ('date', 'user')
def __str__(self):
"""
diff --git a/wger/weight/tests/test_csv_export.py b/wger/weight/tests/test_csv_export.py
index a64ca4162..c2934aa41 100644
--- a/wger/weight/tests/test_csv_export.py
+++ b/wger/weight/tests/test_csv_export.py
@@ -39,8 +39,8 @@ class WeightCsvExportTestCase(WgerTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'text/csv')
self.assertEqual(response['Content-Disposition'], 'attachment; filename=Weightdata.csv')
- self.assertGreaterEqual(len(response.content), 120)
- self.assertLessEqual(len(response.content), 150)
+ self.assertGreaterEqual(len(response.content), 150)
+ self.assertLessEqual(len(response.content), 300)
def test_export_csv_logged_in(self):
"""
diff --git a/wger/weight/tests/test_csv_import.py b/wger/weight/tests/test_csv_import.py
index ca303f0e1..122ac463c 100644
--- a/wger/weight/tests/test_csv_import.py
+++ b/wger/weight/tests/test_csv_import.py
@@ -42,18 +42,18 @@ class WeightCsvImportTestCase(WgerTestCase):
# 1st step
count_before = WeightEntry.objects.count()
csv_input = """Datum Gewicht KJ
-05.01.10 error here 111
-22.01.aa 69,2 222
-27.01.10 69,6 222
-02.02.10 69 222
-11.02.10 70,4 222
-19.02.10 71 222
-26.02.10 71,9 222
-26.02.10 71,9 222
-19.03.10 72 222"""
+05.01.10 00:00:00 error here 111
+22.01.aa 00:00:00 69,2 222
+27.01.10 00:00:00 69,6 222
+02.02.10 00:00:00 69 222
+11.02.10 00:00:00 70,4 222
+19.02.10 00:00:00 71 222
+26.02.10 00:00:00 71,9 222
+26.02.10 00:00:00 71,9 222
+19.03.10 00:00:00 72 222"""
response = self.client.post(
reverse('weight:import-csv'),
- {'stage': 1, 'csv_input': csv_input, 'date_format': '%d.%m.%y'},
+ {'stage': 1, 'csv_input': csv_input, 'date_format': '%d.%m.%y %H:%M:%S'},
)
self.assertEqual(response.status_code, 200)
@@ -64,7 +64,7 @@ class WeightCsvImportTestCase(WgerTestCase):
# 2nd. step
response = self.client.post(
reverse('weight:import-csv'),
- {'stage': 2, 'hash': hash_value, 'csv_input': csv_input, 'date_format': '%d.%m.%y'},
+ {'stage': 2, 'hash': hash_value, 'csv_input': csv_input, 'date_format': '%d.%m.%y %H:%M:%S'},
)
count_after = WeightEntry.objects.count()
diff --git a/wger/weight/tests/test_email_weight_reminder.py b/wger/weight/tests/test_email_weight_reminder.py
index a54c9b5b4..6474375b2 100644
--- a/wger/weight/tests/test_email_weight_reminder.py
+++ b/wger/weight/tests/test_email_weight_reminder.py
@@ -22,6 +22,7 @@ from datetime import (
from django.contrib.auth.models import User
from django.core import mail
from django.core.management import call_command
+from django.utils import timezone
# wger
from wger.core.tests.base_testcase import WgerTestCase
@@ -66,7 +67,7 @@ class EmailWeightReminderTestCase(WgerTestCase):
user.save()
weightEntry = WeightEntry.objects.filter(user=user).get(pk=3)
- weightEntry.date = datetime.now().date() - timedelta(days=2)
+ weightEntry.date = timezone.now() - timedelta(days=2)
weightEntry.save()
user.userprofile.num_days_weight_reminder = 1
@@ -81,7 +82,7 @@ class EmailWeightReminderTestCase(WgerTestCase):
user.save()
weightEntry = WeightEntry.objects.filter(user=user).get(pk=3)
- weightEntry.date = datetime.now().date() - timedelta(days=1)
+ weightEntry.date = timezone.now() - timedelta(days=1)
weightEntry.save()
user.userprofile.num_days_weight_reminder = 1
@@ -96,7 +97,7 @@ class EmailWeightReminderTestCase(WgerTestCase):
user.save()
weightEntry = WeightEntry.objects.filter(user=user).latest()
- weightEntry.date = datetime.now().date()
+ weightEntry.date = timezone.now()
weightEntry.save()
user.userprofile.num_days_weight_reminder = 3
diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.py
index 8af3955d0..2cf7c0c1c 100644
--- a/wger/weight/tests/test_entry.py
+++ b/wger/weight/tests/test_entry.py
@@ -18,6 +18,7 @@ import decimal
# Django
from django.urls import reverse
+from django.utils import timezone
# wger
from wger.core.tests import api_base_test
@@ -40,7 +41,7 @@ class MealRepresentationTestCase(WgerTestCase):
"""
Test that the representation of an object is correct
"""
- self.assertEqual(str(WeightEntry.objects.get(pk=1)), '2012-10-01: 77.00 kg')
+ self.assertEqual(str(WeightEntry.objects.get(pk=1)), '2012-10-01 14:30:21.592000+00:00: 77.00 kg')
class AddWeightEntryTestCase(WgerAddTestCase):
@@ -51,9 +52,10 @@ class AddWeightEntryTestCase(WgerAddTestCase):
object_class = WeightEntry
url = 'weight:add'
user_fail = False
+ date = timezone.now()
data = {
'weight': decimal.Decimal(81.1).quantize(TWOPLACES),
- 'date': datetime.date(2013, 2, 1),
+ 'date': date,
'user': 1,
}
@@ -66,9 +68,10 @@ class EditWeightEntryTestCase(WgerEditTestCase):
object_class = WeightEntry
url = 'weight:edit'
pk = 1
+ date = timezone.now() - timezone.timedelta(days=25)
data = {
'weight': 100,
- 'date': datetime.date(2013, 2, 1),
+ 'date': date,
'user': 1,
}
user_success = 'test'
@@ -95,4 +98,5 @@ class WeightEntryTestCase(api_base_test.ApiBaseResourceTestCase):
pk = 3
resource = WeightEntry
private_resource = True
- data = {'weight': 100, 'date': datetime.date(2013, 2, 1)}
+ date = timezone.now() - timezone.timedelta(days=25)
+ data = {'weight': 100, 'date': date}
diff --git a/wger/weight/tests/test_overview.py b/wger/weight/tests/test_overview.py
index 4aea9a23b..ca2551400 100644
--- a/wger/weight/tests/test_overview.py
+++ b/wger/weight/tests/test_overview.py
@@ -58,8 +58,8 @@ class WeightExportCsvTestCase(WgerTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'text/csv')
- self.assertGreaterEqual(len(response.content), 120)
- self.assertLessEqual(len(response.content), 150)
+ self.assertGreaterEqual(len(response.content), 150)
+ self.assertLessEqual(len(response.content), 300)
def test_csv_export_loged_in(self):
"""