Skip to content

Commit

Permalink
Merge pull request #1666 from wger-project/feature/import-usda-products
Browse files Browse the repository at this point in the history
Refactor product/ingredient import
  • Loading branch information
rolandgeider authored May 29, 2024
2 parents 618481e + fde12ad commit 3322cb3
Show file tree
Hide file tree
Showing 49 changed files with 1,325 additions and 797 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ Developers
* Gabriel Liss - https://github.com/gabeliss
* Alexandra Rhodes - https://github.com/arhodes130
* Jayanth Bontha - https://github.com/JayanthBontha
* Roelof Rietbroek https://github.com/strawpants
* Ethan Winters - https://github.com/ebwinters
* Dieter Plaetinck - https://github.com/Dieterbe


Translators
-----------

Expand Down
1 change: 1 addition & 0 deletions extras/docker/development/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
WGER_SETTINGS["SYNC_EXERCISE_IMAGES_CELERY"] = env.bool("SYNC_EXERCISE_IMAGES_CELERY", False)
WGER_SETTINGS["SYNC_EXERCISE_VIDEOS_CELERY"] = env.bool("SYNC_EXERCISE_VIDEOS_CELERY", False)
WGER_SETTINGS["SYNC_INGREDIENTS_CELERY"] = env.bool("SYNC_INGREDIENTS_CELERY", False)
WGER_SETTINGS["SYNC_OFF_DAILY_DELTA_CELERY"] = env.bool("SYNC_OFF_DAILY_DELTA_CELERY", False)
WGER_SETTINGS["USE_RECAPTCHA"] = env.bool("USE_RECAPTCHA", False)
WGER_SETTINGS["USE_CELERY"] = env.bool("USE_CELERY", False)

Expand Down
2 changes: 1 addition & 1 deletion extras/open-food-facts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
ports:
- "27017:27017"
volumes:
- $PWD/dump:/dump
- $PWD/dump/dump:/dump
environment:
MONGO_INITDB_ROOT_USERNAME: off
MONGO_INITDB_ROOT_PASSWORD: off-wger
Expand Down
4 changes: 2 additions & 2 deletions wger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from .celery_configuration import app


MIN_APP_VERSION = (1, 6, 0, 'final', 1)
MIN_APP_VERSION = (1, 7, 3, 'final', 1)

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


Expand Down
51 changes: 30 additions & 21 deletions wger/core/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<div class="container-fluid">
<div class="container-lg" style="display: flex;">
<a class="navbar-brand" href="{% url 'core:index' %}">
<img src="{% static 'images/logos/logo-bg-white.png' %}" style="width: 38px;" alt="wger logo">
<img src="{% static 'images/logos/logo-bg-white.png' %}" style="width: 38px;"
alt="wger logo">
</a>
<button class="navbar-toggler"
type="button"
Expand All @@ -24,18 +25,21 @@
<a href="{% url 'manager:workout:overview' %}"
rel="nofollow"
class="nav-link dropdown-toggle text-white {% if active_tab == 'workout' %}active{% endif %}"
data-bs-toggle="dropdown">{% translate "Training" %} <b class="caret"></b></a>
data-bs-toggle="dropdown">{% translate "Training" %} <b
class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="{% url 'manager:workout:overview' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'manager:workout:overview' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
{% translate "Workouts" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'manager:schedule:overview' %}" rel="nofollow">
<a class="dropdown-item"
href="{% url 'manager:schedule:overview' %}" rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
Expand Down Expand Up @@ -63,7 +67,8 @@
{% endif %}

<li>
<a class="dropdown-item" href="{% url 'gallery:images:overview' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'gallery:images:overview' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
Expand All @@ -75,15 +80,17 @@
<li class="dropdown-divider"></li>
<li class="dropdown-header">{% translate "Workout templates" %}</li>
<li>
<a class="dropdown-item" href="{% url 'manager:template:overview' %}" rel="nofollow">
<a class="dropdown-item"
href="{% url 'manager:template:overview' %}" rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
{% translate "Your templates" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'manager:template:public' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'manager:template:public' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
Expand All @@ -93,7 +100,8 @@

<li class="dropdown-divider"></li>
<li>
<a class="dropdown-item" href="{% url 'exercise:exercise:overview' %}">
<a class="dropdown-item"
href="{% url 'exercise:exercise:overview' %}">
{% translate "Exercises" %}
</a>
</li>
Expand All @@ -102,22 +110,26 @@
<li class="dropdown-divider"></li>
<li class="dropdown-header">{% translate "Administration" %}</li>
<li>
<a class="dropdown-item" href="{% url 'exercise:history:overview' %}">
<a class="dropdown-item"
href="{% url 'exercise:history:overview' %}">
{% translate "Exercise edit history" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'exercise:equipment:list' %}">
<a class="dropdown-item"
href="{% url 'exercise:equipment:list' %}">
{% translate "Equipment" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'exercise:muscle:admin-list' %}">
<a class="dropdown-item"
href="{% url 'exercise:muscle:admin-list' %}">
{% translate "Muscles" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'exercise:category:list' %}">
<a class="dropdown-item"
href="{% url 'exercise:category:list' %}">
{% translate "Categories" %}
</a>
</li>
Expand All @@ -136,23 +148,26 @@
rel="nofollow">{% translate "Nutrition" %} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="{% url 'nutrition:plan:overview' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'nutrition:plan:overview' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
{% translate "Nutrition plans" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'nutrition:bmi:view' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'nutrition:bmi:view' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
{% translate "BMI calculator" %}
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'nutrition:calories:view' %}" rel="nofollow">
<a class="dropdown-item" href="{% url 'nutrition:calories:view' %}"
rel="nofollow">
{% if not user.is_authenticated %}
<span class="{% fa_class 'lock' %}"></span>
{% endif %}
Expand All @@ -171,12 +186,6 @@
<li><a class="dropdown-item"
href="{% url 'nutrition:weight_unit:list' %}">{% translate "Ingredient weight units" %}</a>
</li>
<li>
<a class="dropdown-item"
href="{% url 'nutrition:ingredient:pending' %}">
{% translate "Ingredients pending review" %}
</a>
</li>
{% endif %}
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion wger/core/tests/test_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def test_sitemap_ingredients(self):
reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': 'nutrition'})
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['urlset']), 13)
self.assertEqual(len(response.context['urlset']), 14)
100 changes: 100 additions & 0 deletions wger/exercises/migrations/0030_increase_author_field_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Generated by Django 4.2.6 on 2024-05-20 19:40

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('exercises', '0029_full_text_search'),
]

operations = [
migrations.AlterField(
model_name='exercise',
name='license_author',
field=models.CharField(
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.CharField(
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.CharField(
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.CharField(
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.CharField(
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.CharField(
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.CharField(
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.CharField(
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)',
),
),
]
3 changes: 1 addition & 2 deletions wger/nutrition/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ class Meta:
'energy': ['exact'],
'fat': ['exact'],
'fat_saturated': ['exact'],
'fibres': ['exact'],
'fiber': ['exact'],
'name': ['exact'],
'protein': ['exact'],
'sodium': ['exact'],
'status': ['exact'],
'language': ['exact'],
'license': ['exact'],
'license_author': ['exact'],
Expand Down
11 changes: 6 additions & 5 deletions wger/nutrition/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Meta:
fields = [
'id',
'uuid',
'remote_id',
'code',
'name',
'created',
Expand All @@ -124,7 +125,7 @@ class Meta:
'carbohydrates_sugar',
'fat',
'fat_saturated',
'fibres',
'fiber',
'sodium',
'license',
'license_title',
Expand Down Expand Up @@ -160,7 +161,7 @@ class Meta:
'carbohydrates_sugar',
'fat',
'fat_saturated',
'fibres',
'fiber',
'sodium',
'weight_units',
'language',
Expand Down Expand Up @@ -265,7 +266,7 @@ class NutritionalValuesSerializer(serializers.Serializer):
carbohydrates_sugar = serializers.FloatField()
fat = serializers.FloatField()
fat_saturated = serializers.FloatField()
fibres = serializers.FloatField()
fiber = serializers.FloatField()
sodium = serializers.FloatField()


Expand Down Expand Up @@ -312,7 +313,7 @@ class Meta:
'goal_protein',
'goal_carbohydrates',
'goal_fat',
'goal_fibers',
'goal_fiber',
# 'nutritional_values',
]

Expand All @@ -336,6 +337,6 @@ class Meta:
'goal_protein',
'goal_carbohydrates',
'goal_fat',
'goal_fibers',
'goal_fiber',
'meals',
]
7 changes: 3 additions & 4 deletions wger/nutrition/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def list(self, request, *args, **kwargs):

def get_queryset(self):
"""H"""
qs = Ingredient.objects.accepted()
qs = Ingredient.objects.all()

code = self.request.query_params.get('code')
if not code:
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_values(self, request, pk):
'carbohydrates_sugar': 0,
'fat': 0,
'fat_saturated': 0,
'fibres': 0,
'fiber': 0,
'sodium': 0,
'errors': [],
}
Expand Down Expand Up @@ -219,7 +219,6 @@ def search(request):
languages = [load_language(l) for l in language_codes.split(',')]
query = Ingredient.objects.filter(
language__in=languages,
status=Ingredient.STATUS_ACCEPTED,
).only('name')

# Postgres uses a full-text search
Expand All @@ -232,7 +231,7 @@ def search(request):
else:
query = query.filter(name__icontains=term)

for ingredient in query[:100]:
for ingredient in query[:150]:
if hasattr(ingredient, 'image'):
image_obj = ingredient.image
image = image_obj.image.url
Expand Down
Loading

0 comments on commit 3322cb3

Please sign in to comment.