Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend changes needed to move the nutrtition to react #1437

Merged
merged 32 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc8104f
Use default div ID for pages that are rendered completely in react
rolandgeider Aug 11, 2023
23e0423
Some updates to the ingredient info serializer
rolandgeider Aug 16, 2023
8f91bc6
Move generator logic to dummy-generator-nutrition.py
rolandgeider Aug 16, 2023
30accb2
Add filter sets for finer control of results in the api
rolandgeider Aug 17, 2023
8849920
Rename some of the options
rolandgeider Aug 17, 2023
22cec1a
Use default div ID for pages that are rendered completely in react
rolandgeider Aug 11, 2023
53f4b30
Some updates to the ingredient info serializer
rolandgeider Aug 16, 2023
fc0e4e6
Move generator logic to dummy-generator-nutrition.py
rolandgeider Aug 16, 2023
28e155b
Add filter sets for finer control of results in the api
rolandgeider Aug 17, 2023
db86b03
Rename some of the options
rolandgeider Aug 17, 2023
e3da5e8
Remove unneeded modal dialog
rolandgeider Sep 27, 2023
91b4fef
Start removing unneeded code and templates
rolandgeider Sep 27, 2023
4a9cc29
Merge remote-tracking branch 'origin/feature/react-nutrition' into fe…
rolandgeider Sep 27, 2023
cd85de2
Fix comment
rolandgeider Sep 28, 2023
ccf55bb
Remove unneeded files and views
rolandgeider Sep 28, 2023
4fa407d
Bump version
rolandgeider Sep 28, 2023
cba2451
Formatting
rolandgeider Sep 28, 2023
bf84232
Don't force users to add individual ingredients/products to a plan
rolandgeider Sep 29, 2023
d26331d
Make sure that we always return a date
rolandgeider Oct 10, 2023
37c3e25
Catch JSONDecodeError when loading ingredients from OFF
rolandgeider Oct 10, 2023
69a623f
Commit missing muscle
rolandgeider Oct 10, 2023
6d50b49
Also initialise the energy_kilojoule key
rolandgeider Oct 10, 2023
07dd3f9
Merge branch 'master' into feature/react-nutrition
rolandgeider Oct 10, 2023
05346c8
Merge remote-tracking branch 'origin/feature/react-nutrition' into fe…
rolandgeider Oct 11, 2023
68e9a53
Use a dataclass to handle the nutritional values calculations
rolandgeider Oct 11, 2023
bb2726f
Use old python 3.9 syntax for types
rolandgeider Oct 12, 2023
49e871f
Add fields for general goals
rolandgeider Oct 16, 2023
0048980
Update react code
rolandgeider Oct 16, 2023
734a350
Remove unneeded code
rolandgeider Oct 16, 2023
9bd85a3
Remove possibility to download PDF with token
rolandgeider Oct 16, 2023
907c3d6
Update react code
rolandgeider Oct 16, 2023
f28c4f6
Update react code again
rolandgeider Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 4 additions & 93 deletions extras/dummy_generator/generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +14,6 @@

# Standard Library
import argparse
import csv
import datetime
import os
import random
Expand All @@ -26,9 +23,10 @@
# Django
import django
from django.db import IntegrityError
from django.utils import timezone
from django.utils.text import slugify

import csv

sys.path.insert(0, os.path.join('..', '..'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
django.setup()
Expand All @@ -40,7 +38,6 @@
# wger
from wger.core.models import (
DaysOfWeek,
Language,
)
from wger.exercises.models import Exercise
from wger.gym.models import (
Expand All @@ -61,13 +58,6 @@
Category,
Measurement,
)
from wger.nutrition.models import (
Ingredient,
LogItem,
Meal,
MealItem,
NutritionPlan,
)
from wger.weight.models import WeightEntry

parser = argparse.ArgumentParser(description='Data generator. Please consult the documentation')
Expand Down Expand Up @@ -566,89 +556,10 @@
# Nutrition Generator
#
if hasattr(args, 'number_nutrition_plans'):
print("** Generating {0} nutrition plan(s) per user".format(args.number_nutrition_plans))

if args.add_to_user:
userlist = [User.objects.get(pk=args.add_to_user)]
else:
userlist = User.objects.all()

# Load all ingredients to a list
ingredient_list = [i for i in Ingredient.objects.order_by('?').all()[:100]]

# Total meals per plan
TOTAL_MEALS = 4

for user in userlist:
print(' - generating for {0}'.format(user.username))

# Add nutrition plan
for i in range(0, args.number_nutrition_plans):
uid = str(uuid.uuid4()).split('-')
start_date = datetime.date.today() - datetime.timedelta(days=random.randint(0, 100))
nutrition_plan = NutritionPlan(
language=Language.objects.all()[1],
description='Dummy nutrition plan - {0}'.format(uid[1]),
creation_date=start_date,
)
nutrition_plan.user = user

nutrition_plan.save()

# Add meals to plan
order = 1
for j in range(0, TOTAL_MEALS):
meal = Meal(
plan=nutrition_plan,
order=order,
time=datetime.time(hour=random.randint(0, 23), minute=random.randint(0, 59))
)
meal.save()
for k in range(0, random.randint(1, 5)):
ingredient = random.choice(ingredient_list)
meal_item = MealItem(
meal=meal,
ingredient=ingredient,
weight_unit=None,
order=order,
amount=random.randint(10, 250)
)
meal_item.save()
order = order + 1
print("*** Please use 'python manage.py dummy-generator-nutrition' instead")

#
# Nutrition diary Generator
#
if hasattr(args, 'number_nutrition_logs'):
print("** Generating {0} nutrition diary entries per user".format(args.number_nutrition_logs))

if args.add_to_user:
userlist = [User.objects.get(pk=args.add_to_user)]
else:
userlist = User.objects.all()

# Load all ingredients to a list
ingredient_list = [i for i in Ingredient.objects.order_by('?').all()[:100]]

for user in userlist:
plan_list = NutritionPlan.objects.order_by('?').filter(user=user)
print(' - generating for {0}'.format(user.username))

# Add diary entries
for plan in NutritionPlan.objects.filter(user=user):
for i in range(0, args.number_diary_dates):
date = timezone.now() - datetime.timedelta(
days=random.randint(0, 100),
hours=random.randint(0, 12),
minutes=random.randint(0, 59)
)
for j in range(0, args.number_nutrition_logs):
ingredient = random.choice(ingredient_list)
log = LogItem(
plan=plan,
datetime=date,
ingredient=ingredient,
weight_unit=None,
amount=random.randint(10, 300)
)
log.save()
print("*** Please use 'python manage.py dummy-generator-nutrition' instead")
2 changes: 1 addition & 1 deletion wger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

MIN_APP_VERSION = (1, 5, 0, 'final', 1)

VERSION = (2, 2, 0, 'alpha', 3)
VERSION = (2, 2, 0, 'alpha', 4)
RELEASE = True


Expand Down
4 changes: 2 additions & 2 deletions wger/core/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ def user_bodyweight(self, weight):
"""
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)
datetime.date.today() - WeightEntry.objects.filter(user=self.user).latest().date >
datetime.timedelta(days=3)
)
):
entry = WeightEntry()
Expand Down
97 changes: 97 additions & 0 deletions wger/core/static/react/locales/el/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"exercises": {
"secondaryMuscles": "Δευτερεύοντες μύες",
"muscles": "Μύες",
"contributeExercise": "Συνεισφέρετε μια άσκηση",
"notEnoughRights": "Μπορείτε να συνεισφέρετε ασκήσεις μόνο εάν ο λογαριασμός σας είναι παλαιότερος από {{days}} ημέρες και έχετε επαληθεύσει το ηλεκτρονικό σας ταχυδρομείο",
"variations": "Παραλλαγές",
"notEnoughRightsHeader": "Δεν μπορείτε να συνεισφέρετε ασκήσεις",
"newNote": "Νέα σημείωση",
"identicalExercise": "Αποφύγετε διπλές ασκήσεις",
"identicalExercisePleaseDiscard": "Αν παρατηρήσετε μια άσκηση που είναι πανομοιότυπη με αυτή που προσθέτετε, παρακαλούμε απορρίψτε το προσχέδιό σας και επεξεργαστείτε αυτή την άσκηση.",
"missingExerciseDescription": "Βοηθήστε την κοινότητα με τη συνεισφορά σας!",
"equipment": "Εξοπλισμός",
"exercises": "Ασκήσεις",
"alsoKnownAs": "Επίσης γνωστό ως:",
"primaryMuscles": "Πρωτεύοντες μύες",
"successfullyUpdated": "Η άσκηση ενημερώθηκε επιτυχώς. Λόγω της προσωρινής αποθήκευσης μπορεί να χρειαστεί κάποιος χρόνος μέχρι οι αλλαγές να είναι ορατές σε όλη την εφαρμογή.",
"noEquipment": "Χωρίς εξοπλισμό",
"translateExerciseNow": "Μεταφράστε αυτή την άσκηση τώρα",
"notesHelpText": "Οι σημειώσεις είναι σύντομα σχόλια για τον τρόπο εκτέλεσης της άσκησης, όπως \"κρατήστε το σώμα σας ίσιο\"",
"notes": "Σημειώσεις",
"basics": "Βασικά στοιχεία",
"whatVariationsExist": "Ποιες παραλλαγές αυτής της άσκησης υπάρχουν, αν υπάρχουν;",
"submitExercise": "Υποβολή άσκησης",
"changeExerciseLanguage": "Αλλάξτε τη γλώσσα αυτής της άσκησης",
"exerciseNotTranslated": "Δεν υπάρχει διαθέσιμη μετάφραση",
"compatibleImagesCC": "Οι εικόνες πρέπει να είναι συμβατές με την άδεια CC BY SA. Αν έχετε αμφιβολίες, ανεβάζετε μόνο φωτογραφίες που έχετε τραβήξει μόνοι σας.",
"step1HeaderBasics": "Βασικά στα αγγλικά",
"exerciseNotTranslatedBody": "Αυτή η άσκηση δεν είναι προς το παρόν διαθέσιμη στην τρέχουσα επιλεγμένη γλώσσα. Θέλετε να συνεισφέρετε μια μετάφραση;",
"cacheWarning": "Λόγω της προσωρινής αποθήκευσης μπορεί να χρειαστεί κάποιος χρόνος μέχρι οι αλλαγές να είναι ορατές σε όλη την εφαρμογή.",
"deleteTranslation": "Διαγραφή μετάφρασης",
"checkInformationBeforeSubmitting": "Βεβαιωθείτε ότι οι πληροφορίες που καταχωρήσατε είναι σωστές πριν υποβάλετε την άσκηση",
"searchExerciseName": "Αναζήτηση με το όνομα της άσκησης",
"description": "Περιγραφή",
"deleteExerciseBody": "Θέλετε να διαγράψετε την άσκηση \"{{όνομα}}\"; Μπορείτε να διαγράψετε είτε την τρέχουσα μετάφραση {{γλώσσα}} είτε ολόκληρη την άσκηση με όλες τις μεταφράσεις, τις εικόνες, κ.λπ.",
"missingExercise": "Σας λείπει μια συγκεκριμένη άσκηση;",
"deleteExerciseFull": "Διαγραφή πλήρους άσκησης",
"alternativeNames": "Εναλλακτικές ονομασίες",
"filterVariations": "Εισάγετε το όνομα της άσκησης για να φιλτράρετε τις παραλλαγές"
},
"nutritionalPlan": "Διατροφικό σχέδιο",
"date": "Ημερομηνία",
"days": "Ημέρες",
"edit": "Επεξεργασία",
"submit": "Υποβολλή",
"value": "Αξία",
"delete": "Διαγραφή",
"deleteConfirmation": "Είστε βέβαιοι ότι θέλετε να διαγράψετε το \"{{name}}\";",
"notes": "Σημειώσεις",
"difference": "Διαφορά",
"seeDetails": "Δείτε λεπτομέρειες",
"server": {
"none__bodyweight_exercise_": "κανένα (άσκηση με σωματικό βάρος)"
},
"currentWeight": "Τρέχον βάρος",
"workout": "Προπόνηση",
"addEntry": "Προσθήκη καταχώρησης",
"actions": "Ενέργειες",
"unit": "Μονάδα",
"loading": "Φόρτωση…",
"weight": "Βάρος",
"add": "Προσθήκη",
"routines": {
"logsHeader": "Ημερολόγιο βάρους για προπόνηση",
"addDay": "Προσθέστε ημέρα προπόνησης",
"addWeightLog": "Προσθέστε ημερολόγιο βάρους",
"logsFilterNote": "Σημειώστε ότι καταγράφονται μόνο καταχωρήσεις με μονάδα βάρους kg ή lb και επαναλήψεις, άλλοι συνδυασμοί όπως χρόνος ή μέχρι την αποτυχία αγνοούνται εδώ"
},
"images": "Εικόνες",
"save": "Αποθήκευση",
"forms": {
"valueTooLong": "Η τιμή είναι πολύ μεγάλη",
"minValue": "Η τιμή για αυτό το πεδίο πρέπει να είναι μεγαλύτερη από {{value}}",
"minLength": "Παρακαλώ εισάγετε περισσότερους από {{chars}} χαρακτήρες",
"valueTooShort": "Η τιμή είναι πολύ μικρή",
"supportedImageFormats": "Υποστηρίζονται μόνο αρχεία JPEG, PNG και WEBP κάτω των 20Mb",
"maxLength": "Παρακαλώ εισάγετε λιγότερους από {{chars}} χαρακτήρες",
"maxValue": "Η τιμή για αυτό το πεδίο πρέπει να είναι μικρότερη από {{value}}",
"fieldRequired": "Το πεδίο αυτό είναι υποχρεωτικό"
},
"videos": "Βίντεο",
"English": "Αγγλικά",
"success": "Επιτυχία!",
"description": "Περιγραφή",
"name": "Όνομα",
"preferences": "Προτιμήσεις",
"continue": "Συνεχίστε",
"noResults": "Δεν υπάρχουν αποτελέσματα",
"goBack": "Πίσω",
"translation": "Μετάφραση",
"cancel": "Ακύρωση",
"language": "Γλώσσα",
"noResultsDescription": "Δεν βρέθηκαν αποτελέσματα για αυτό το ερώτημα, σκεφτείτε να μειώσετε τον αριθμό των φίλτρων.",
"overview": "Επισκόπηση",
"category": "Κατηγορία",
"cannotBeUndone": "Αυτή η ενέργεια δεν μπορεί να αναιρεθεί."
}
60 changes: 59 additions & 1 deletion wger/core/static/react/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"weight": "Weight",
"date": "Date",
"timeOfDay": "Time of day",
"submit": "Submit",
"edit": "Edit",
"delete": "Delete",
"deleteConfirmation": "Are you sure you want to delete \"{{name}}\"?",
"add": "Add",
"close": "Close",
"difference": "Difference",
"days": "Days",
"loading": "Loading...",
Expand All @@ -17,6 +20,7 @@
"notes": "Notes",
"value": "Value",
"unit": "Unit",
"alsoSearchEnglish": "Also search for names in English",
"exercises": {
"contributeExercise": "Contribute an exercise",
"step1HeaderBasics": "Basics in English",
Expand Down Expand Up @@ -56,6 +60,59 @@
"newNote": "New note",
"notesHelpText": "Notes are short comments on how to perform the exercise such as \"keep your body straight\""
},
"nutrition": {
"plans": "Nutritional plans",
"copyPlan": "Make a copy of this plan",
"plan": "Nutritional plan",
"onlyLoggingHelpText": "Only track calories. Check the box if you only want to log your calories and don't want to setup a detailed nutritional plan with specific meals",
"goalsTitle": "Goals",
"useGoalsHelpText": "Add goals to this plan",
"useGoalsHelpTextLong": "This allows you to set general goals for energy, protein, carbohydrates or fat for the plan. Note that if you setup a detailed meal plan, these values will take precedence.",
"goalEnergy": "Energy goal",
"goalProtein": "Protein goal",
"goalCarbohydrates": "Carbohydrates goal",
"goalFat": "Fat goal",
"addNutritionalDiary": "Add nutrition diary entry",
"meal": "Meal",
"addMeal": "Add meal",
"addMealItem": "Add ingredient to meal",
"nutritionalDiary": "Nutrition diary",
"gramShort": "g",
"kcal": "kcal",
"valueEnergyKcal": "{{value}} kcal",
"valueEnergyKcalKj": "{{kcal}} kcal / {{kj}} kJ",
"searchIngredientName": "Search by ingredient name",
"macronutrient": "Macronutrient",
"percentEnergy": "Percent of energy",
"gPerBodyKg": "g per body-kg",
"planned": "Planned",
"logged": "Logged",
"loggedToday": "Logged today",
"difference": "Difference",
"today": "Today",
"7dayAvg": "7-day average",
"energy": "Energy",
"protein": "Protein",
"carbohydrates": "Carbohydrates",
"sugar": "Sugar",
"ofWhichSugars": "of which sugars",
"fat": "Fat",
"ofWhichSaturated": "of which saturated",
"saturatedFat": "Saturated fat",
"pseudoMealTitle": "Other logs",
"others": "Others",
"fibres": "Fibres",
"sodium": "Sodium",
"planDeleteInfo": "This will delete all nutrition diary entries as well",
"mealDeleteInfo": "Nutrition diary entries to this meal will not be deleted and will appear under \"other logs\"",
"diaryEntrySaved": "Diary entry successfully saved",
"logThisMeal": "Log this meal as-is to the nutrition diary",
"logThisMealItem": "Log this ingredient as-is to the nutrition diary",
"valueRemaining": "remaining",
"valueTooMany": "too many"
},
"downloadAsPdf": "Download as PDF",
"total": "Total",
"description": "Description",
"translation": "Translation",
"images": "Images",
Expand Down Expand Up @@ -96,7 +153,8 @@
},
"measurements": {
"measurements": "Measurements",
"unitFormHelpText": "The unit in which the category will be measured, such as cm or %"
"unitFormHelpText": "The unit in which the category will be measured, such as cm or %",
"deleteInfo": "This will delete the category as well as all its entries"
},
"server": {
"abs": "Abs",
Expand Down
Loading