mirror of
https://github.com/wger-project/wger.git
synced 2026-12-02 18:19:40 +01:00
More code reformatting to be more flake8 compliant
This commit is contained in:
54
setup.py
54
setup.py
@@ -53,34 +53,34 @@ setup(
|
||||
# supported here. After the release, django-user-agent will be removed
|
||||
# and this can be replaced again with: install_requires=install_requires,
|
||||
install_requires=[
|
||||
"wheel",
|
||||
"bleach>=3.1,<3.2",
|
||||
"django-bootstrap-breadcrumbs==0.9.1",
|
||||
"django-bower==5.2.0",
|
||||
"django-formtools>=2.0,<3.0",
|
||||
"django-recaptcha==2.0.6",
|
||||
"Django>=3.0,<3.1",
|
||||
"django_compressor>=2.4,<2.5",
|
||||
"django_extensions>=2.1",
|
||||
"django-sortedm2m>=3.0,<3.1",
|
||||
"django-storages>=1.7",
|
||||
"easy-thumbnails>=2.7,<2.8",
|
||||
"icalendar==4.0.3",
|
||||
"invoke==0.17",
|
||||
"pillow>=6.2,<6.3",
|
||||
"python-mimeparse",
|
||||
"reportlab==3.5.21",
|
||||
"matplotlib>=3.1",
|
||||
"requests",
|
||||
"setuptools>=18.5",
|
||||
"sphinx",
|
||||
"wheel",
|
||||
"bleach>=3.1,<3.2",
|
||||
"django-bootstrap-breadcrumbs==0.9.1",
|
||||
"django-bower==5.2.0",
|
||||
"django-formtools>=2.0,<3.0",
|
||||
"django-recaptcha==2.0.6",
|
||||
"Django>=3.0,<3.1",
|
||||
"django_compressor>=2.4,<2.5",
|
||||
"django_extensions>=2.1",
|
||||
"django-sortedm2m>=3.0,<3.1",
|
||||
"django-storages>=1.7",
|
||||
"easy-thumbnails>=2.7,<2.8",
|
||||
"icalendar==4.0.3",
|
||||
"invoke==0.17",
|
||||
"pillow>=6.2,<6.3",
|
||||
"python-mimeparse",
|
||||
"reportlab==3.5.21",
|
||||
"matplotlib>=3.1",
|
||||
"requests",
|
||||
"setuptools>=18.5",
|
||||
"sphinx",
|
||||
|
||||
"django-cors-headers>=3.0",
|
||||
"django-filter==2.1.0",
|
||||
"django-tastypie>=0.14,<.0.15",
|
||||
"djangorestframework>=3.11,<3.12",
|
||||
"django-user_agents"
|
||||
],
|
||||
"django-cors-headers>=3.0",
|
||||
"django-filter==2.1.0",
|
||||
"django-tastypie>=0.14,<.0.15",
|
||||
"djangorestframework>=3.11,<3.12",
|
||||
"django-user_agents"
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'wger = wger.__main__:main',
|
||||
|
||||
@@ -375,8 +375,8 @@ by the US Department of Agriculture. It is extremely complete, with around
|
||||
Make sure the total amount of hours is 24
|
||||
"""
|
||||
if ((self.sleep_hours and self.freetime_hours and self.work_hours)
|
||||
and (self.sleep_hours + self.freetime_hours + self.work_hours) > 24):
|
||||
raise ValidationError(_('The sum of all hours has to be 24'))
|
||||
and (self.sleep_hours + self.freetime_hours + self.work_hours) > 24):
|
||||
raise ValidationError(_('The sum of all hours has to be 24'))
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
@@ -407,8 +407,7 @@ by the US Department of Agriculture. It is extremely complete, with around
|
||||
return 0
|
||||
|
||||
weight = self.weight if self.use_metric else AbstractWeight(self.weight, 'lb').kg
|
||||
return weight / (self.height / decimal.Decimal(100) *
|
||||
self.height / decimal.Decimal(100.0))
|
||||
return weight / pow(self.height / decimal.Decimal(100), 2)
|
||||
|
||||
def calculate_basal_metabolic_rate(self, formula=1):
|
||||
"""
|
||||
@@ -599,6 +598,7 @@ class RepetitionUnit(models.Model):
|
||||
"""
|
||||
Setting unit, used in combination with an amount such as '10 reps', '5 km'
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Set Meta options
|
||||
@@ -637,6 +637,7 @@ class WeightUnit(models.Model):
|
||||
"""
|
||||
Weight unit, used in combination with an amount such as '10 kg', '5 plates'
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Set Meta options
|
||||
|
||||
@@ -64,5 +64,6 @@ def set_user_age(sender, instance, **kwargs):
|
||||
instance.age = (today.year - birthday.year
|
||||
- ((today.month, today.day) < (birthday.month, birthday.day)))
|
||||
|
||||
|
||||
post_save.connect(create_user_profile, sender=User)
|
||||
post_save.connect(create_user_cache, sender=User)
|
||||
|
||||
@@ -236,8 +236,8 @@ class PreferencesCalculationsTestCase(WorkoutManagerTestCase):
|
||||
user = User.objects.get(pk=2)
|
||||
bmi = user.userprofile.calculate_bmi()
|
||||
self.assertEqual(bmi,
|
||||
user.userprofile.weight.quantize(TWOPLACES) /
|
||||
decimal.Decimal(1.80 * 1.80).quantize(TWOPLACES))
|
||||
user.userprofile.weight.quantize(TWOPLACES)
|
||||
/ decimal.Decimal(1.80 * 1.80).quantize(TWOPLACES))
|
||||
|
||||
def test_basal_metabolic_rate(self):
|
||||
"""
|
||||
|
||||
@@ -433,10 +433,10 @@ class ExerciseImage(AbstractSubmissionModel, AbstractLicenseModel, models.Model)
|
||||
.filter(is_main=False) \
|
||||
.count():
|
||||
|
||||
image = ExerciseImage.objects.accepted() \
|
||||
.filter(exercise=self.exercise, is_main=False)[0]
|
||||
image.is_main = True
|
||||
image.save()
|
||||
image = ExerciseImage.objects.accepted() \
|
||||
.filter(exercise=self.exercise, is_main=False)[0]
|
||||
image.is_main = True
|
||||
image.save()
|
||||
|
||||
def get_owner_object(self):
|
||||
"""
|
||||
|
||||
@@ -36,9 +36,9 @@ class GymManager(models.Manager):
|
||||
perm_trainer = Permission.objects.get(codename='gym_trainer')
|
||||
|
||||
users = User.objects.filter(userprofile__gym_id=gym_pk)
|
||||
return users.exclude(Q(groups__permissions=perm_gym) |
|
||||
Q(groups__permissions=perm_gyms) |
|
||||
Q(groups__permissions=perm_trainer)).distinct()
|
||||
return users.exclude(Q(groups__permissions=perm_gym)
|
||||
| Q(groups__permissions=perm_gyms)
|
||||
| Q(groups__permissions=perm_trainer)).distinct()
|
||||
|
||||
def get_admins(self, gym_pk):
|
||||
"""
|
||||
@@ -49,6 +49,6 @@ class GymManager(models.Manager):
|
||||
perm_trainer = Permission.objects.get(codename='gym_trainer')
|
||||
|
||||
users = User.objects.filter(userprofile__gym_id=gym_pk)
|
||||
return users.filter(Q(groups__permissions=perm_gym) |
|
||||
Q(groups__permissions=perm_gyms) |
|
||||
Q(groups__permissions=perm_trainer)).distinct()
|
||||
return users.filter(Q(groups__permissions=perm_gym)
|
||||
| Q(groups__permissions=perm_gyms)
|
||||
| Q(groups__permissions=perm_trainer)).distinct()
|
||||
|
||||
@@ -178,7 +178,6 @@ class ScheduleTestCase(WorkoutManagerTestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'This schedule is a loop')
|
||||
|
||||
|
||||
# Commented out since travis was seemingly randomly failing this. See #468
|
||||
#
|
||||
# def test_schedule_detail_page_owner(self):
|
||||
|
||||
@@ -262,14 +262,14 @@ class WeightlogTestCase(WorkoutManagerTestCase):
|
||||
workout2 = Workout.objects.get(pk=2)
|
||||
|
||||
WorkoutLog.objects.all().delete()
|
||||
l = WorkoutLog()
|
||||
l.user = user1
|
||||
l.date = datetime.date(2014, 1, 5)
|
||||
l.exercise = Exercise.objects.get(pk=1)
|
||||
l.workout = workout1
|
||||
l.weight = 10
|
||||
l.reps = 10
|
||||
l.save()
|
||||
log = WorkoutLog()
|
||||
log.user = user1
|
||||
log.date = datetime.date(2014, 1, 5)
|
||||
log.exercise = Exercise.objects.get(pk=1)
|
||||
log.workout = workout1
|
||||
log.weight = 10
|
||||
log.reps = 10
|
||||
log.save()
|
||||
|
||||
session1 = WorkoutSession()
|
||||
session1.user = user1
|
||||
@@ -295,7 +295,7 @@ class WeightlogTestCase(WorkoutManagerTestCase):
|
||||
session3.date = datetime.date(2014, 1, 5)
|
||||
session3.save()
|
||||
|
||||
self.assertEqual(l.get_workout_session(), session1)
|
||||
self.assertEqual(log.get_workout_session(), session1)
|
||||
|
||||
|
||||
class WeightLogDeleteTestCase(WorkoutManagerDeleteTestCase):
|
||||
|
||||
@@ -50,7 +50,6 @@ from wger.utils.models import (
|
||||
from wger.utils.units import AbstractWeight
|
||||
from wger.weight.models import WeightEntry
|
||||
|
||||
|
||||
MEALITEM_WEIGHT_GRAM = '1'
|
||||
MEALITEM_WEIGHT_UNIT = '2'
|
||||
|
||||
@@ -64,7 +63,6 @@ ENERGY_FACTOR = {'protein': {'kg': 4,
|
||||
Simple approximation of energy (kcal) provided per gram or ounce
|
||||
"""
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -238,7 +236,7 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
|
||||
editable=False)
|
||||
|
||||
name = models.CharField(max_length=200,
|
||||
verbose_name=_('Name'),)
|
||||
verbose_name=_('Name'), )
|
||||
|
||||
energy = models.IntegerField(verbose_name=_('Energy'),
|
||||
help_text=_('In kcal per 100g'))
|
||||
@@ -372,9 +370,10 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
|
||||
equal = True
|
||||
if isinstance(other, self.__class__):
|
||||
for i in self._meta.fields:
|
||||
if (hasattr(self, i.name) and hasattr(other, i.name) and
|
||||
(getattr(self, i.name, None) != getattr(other, i.name, None))):
|
||||
equal = False
|
||||
if (hasattr(self, i.name)
|
||||
and hasattr(other, i.name)
|
||||
and (getattr(self, i.name, None) != getattr(other, i.name, None))):
|
||||
equal = False
|
||||
else:
|
||||
equal = False
|
||||
return equal
|
||||
@@ -469,7 +468,7 @@ class WeightUnit(models.Model):
|
||||
editable=False,
|
||||
on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=200,
|
||||
verbose_name=_('Name'),)
|
||||
verbose_name=_('Name'), )
|
||||
|
||||
# Metaclass to set some other properties
|
||||
class Meta:
|
||||
@@ -652,17 +651,17 @@ class MealItem(models.Model):
|
||||
if self.get_unit_type() == MEALITEM_WEIGHT_GRAM:
|
||||
item_weight = self.amount
|
||||
else:
|
||||
item_weight = (self.amount *
|
||||
self.weight_unit.amount *
|
||||
self.weight_unit.gram)
|
||||
item_weight = (self.amount
|
||||
* self.weight_unit.amount
|
||||
* self.weight_unit.gram)
|
||||
|
||||
nutritional_info['energy'] += self.ingredient.energy * item_weight / 100
|
||||
nutritional_info['protein'] += self.ingredient.protein * item_weight / 100
|
||||
nutritional_info['carbohydrates'] += self.ingredient.carbohydrates * item_weight / 100
|
||||
|
||||
if self.ingredient.carbohydrates_sugar:
|
||||
nutritional_info['carbohydrates_sugar'] += self.ingredient.carbohydrates_sugar \
|
||||
* item_weight / 100
|
||||
nutritional_info['carbohydrates_sugar'] += \
|
||||
self.ingredient.carbohydrates_sugar * item_weight / 100
|
||||
|
||||
nutritional_info['fat'] += self.ingredient.fat * item_weight / 100
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ def processor(request):
|
||||
if '/software/' in request.get_full_path() \
|
||||
or '/contact' in request.get_full_path() \
|
||||
or '/api/v2' in request.get_full_path():
|
||||
context['active_tab'] = constants.SOFTWARE_TAB
|
||||
context['show_shariff'] = True
|
||||
context['active_tab'] = constants.SOFTWARE_TAB
|
||||
context['show_shariff'] = True
|
||||
|
||||
elif '/exercise/' in request.get_full_path():
|
||||
context['active_tab'] = constants.EXERCISE_TAB
|
||||
|
||||
@@ -67,10 +67,10 @@ class CreateOnlyPermission(permissions.BasePermission):
|
||||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return (request.method in ['GET', 'HEAD', 'OPTIONS'] or
|
||||
(request.user and
|
||||
request.user.is_authenticated and
|
||||
request.method == 'POST'))
|
||||
return (request.method in ['GET', 'HEAD', 'OPTIONS']
|
||||
or (request.user
|
||||
and request.user.is_authenticated
|
||||
and request.method == 'POST'))
|
||||
|
||||
|
||||
class UpdateOnlyPermission(permissions.BasePermission):
|
||||
@@ -80,6 +80,6 @@ class UpdateOnlyPermission(permissions.BasePermission):
|
||||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return (request.user and
|
||||
request.user.is_authenticated and
|
||||
request.method in ['GET', 'HEAD', 'OPTIONS', 'PATCH'])
|
||||
return (request.user
|
||||
and request.user.is_authenticated
|
||||
and request.method in ['GET', 'HEAD', 'OPTIONS', 'PATCH'])
|
||||
|
||||
@@ -192,14 +192,15 @@ class CheckboxFieldRendererTranslated(CheckboxSelectMultiple):
|
||||
class CheckboxFieldRendererTranslatedOriginal(CheckboxSelectMultiple):
|
||||
choice_input_class = CheckboxChoiceInputTranslatedOriginal
|
||||
|
||||
|
||||
class BootstrapSelectMultiple(CheckboxSelectMultiple):
|
||||
pass
|
||||
#renderer = CheckboxBootstrapRenderer
|
||||
# renderer = CheckboxBootstrapRenderer
|
||||
|
||||
|
||||
class BootstrapSelectMultipleTranslatedOriginal(CheckboxSelectMultiple):
|
||||
pass
|
||||
#renderer = CheckboxBootstrapRendererTranslatedOriginal
|
||||
# renderer = CheckboxBootstrapRendererTranslatedOriginal
|
||||
|
||||
|
||||
class TranslatedSelectMultiple(BootstrapSelectMultiple):
|
||||
|
||||
@@ -207,30 +207,30 @@ def process_log_entries(logs):
|
||||
|
||||
|
||||
def get_last_entries(user, amount=5):
|
||||
"""
|
||||
Get the last weight entries as well as the difference to the last
|
||||
"""
|
||||
Get the last weight entries as well as the difference to the last
|
||||
|
||||
This can be used e.g. to present a list where the last entries and
|
||||
their changes are presented.
|
||||
"""
|
||||
This can be used e.g. to present a list where the last entries and
|
||||
their changes are presented.
|
||||
"""
|
||||
|
||||
last_entries = WeightEntry.objects.filter(user=user).order_by('-date')[:5]
|
||||
last_entries_details = []
|
||||
last_entries = WeightEntry.objects.filter(user=user).order_by('-date')[:5]
|
||||
last_entries_details = []
|
||||
|
||||
for index, entry in enumerate(last_entries):
|
||||
curr_entry = entry
|
||||
prev_entry_index = index + 1
|
||||
for index, entry in enumerate(last_entries):
|
||||
curr_entry = entry
|
||||
prev_entry_index = index + 1
|
||||
|
||||
if prev_entry_index < len(last_entries):
|
||||
prev_entry = last_entries[prev_entry_index]
|
||||
else:
|
||||
prev_entry = None
|
||||
if prev_entry_index < len(last_entries):
|
||||
prev_entry = last_entries[prev_entry_index]
|
||||
else:
|
||||
prev_entry = None
|
||||
|
||||
if prev_entry and curr_entry:
|
||||
weight_diff = curr_entry.weight - prev_entry.weight
|
||||
day_diff = (curr_entry.date - prev_entry.date).days
|
||||
else:
|
||||
weight_diff = day_diff = None
|
||||
last_entries_details.append((curr_entry, weight_diff, day_diff))
|
||||
if prev_entry and curr_entry:
|
||||
weight_diff = curr_entry.weight - prev_entry.weight
|
||||
day_diff = (curr_entry.date - prev_entry.date).days
|
||||
else:
|
||||
weight_diff = day_diff = None
|
||||
last_entries_details.append((curr_entry, weight_diff, day_diff))
|
||||
|
||||
return last_entries_details
|
||||
return last_entries_details
|
||||
|
||||
Reference in New Issue
Block a user