Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove the status for ingredients
Roland Geider53494468812a
diff --git a/wger/__init__.py b/wger/__init__.pyindex 0c35a8b6d..a00e199c0 100644--- a/wger/__init__.py+++ b/wger/__init__.py@@ -8,6 +8,7 @@# Localfrom .celery_configuration import app+MIN_APP_VERSION = (1, 7, 3, 'final', 1)VERSION = (2, 3, 0, 'alpha', 2)diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.htmlindex 830dbf675..4bba8122f 100644--- a/wger/core/templates/navigation.html+++ b/wger/core/templates/navigation.html@@ -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"@@ -24,10 +25,12 @@<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 %}@@ -35,7 +38,8 @@</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 %}@@ -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 %}@@ -75,7 +80,8 @@<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 %}@@ -83,7 +89,8 @@</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 %}@@ -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>@@ -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>@@ -136,7 +148,8 @@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 %}@@ -144,7 +157,8 @@</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 %}@@ -152,7 +166,8 @@</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 %}@@ -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>diff --git a/wger/nutrition/api/filtersets.py b/wger/nutrition/api/filtersets.pyindex 44fdfbfdf..a1cca19da 100644--- a/wger/nutrition/api/filtersets.py+++ b/wger/nutrition/api/filtersets.py@@ -38,7 +38,6 @@ class IngredientFilterSet(filters.FilterSet):'name': ['exact'],'protein': ['exact'],'sodium': ['exact'],- 'status': ['exact'],'language': ['exact'],'license': ['exact'],'license_author': ['exact'],diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.pyindex 1a81aab61..473d36c30 100644--- a/wger/nutrition/api/views.py+++ b/wger/nutrition/api/views.py@@ -98,7 +98,7 @@ class IngredientViewSet(viewsets.ReadOnlyModelViewSet):def get_queryset(self):"""H"""- qs = Ingredient.objects.accepted()+ qs = Ingredient.objects.all()code = self.request.query_params.get('code')if not code:@@ -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 searchdiff --git a/wger/nutrition/dataclasses.py b/wger/nutrition/dataclasses.pyindex 49b9dfb49..d87408b9f 100644--- a/wger/nutrition/dataclasses.py+++ b/wger/nutrition/dataclasses.py@@ -38,7 +38,6 @@ class IngredientData:source_url: strcommon_name: strbrand: str- status: strlicense_id: intlicense_author: strlicense_title: strdiff --git a/wger/nutrition/fixtures/test-ingredients.json b/wger/nutrition/fixtures/test-ingredients.jsonindex 3bf8e55ad..d95e081c5 100644--- a/wger/nutrition/fixtures/test-ingredients.json+++ b/wger/nutrition/fixtures/test-ingredients.json@@ -5,7 +5,6 @@"fields": {"uuid": "7908c204-907f-4b1e-ad4e-f482e9769ade","remote_id": "1234567890987654321",- "status": "2","license_author": "wger test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-01-01T10:23:00+01:00",@@ -33,7 +32,6 @@"fields": {"uuid": "44dc5966-73a2-4df7-8b15-f6d37a8990d9","remote_id": "1234567890",- "status": "2","license_author": "wger test","name": "Ingredient, test, 2, organic, raw","last_update": "2013-02-12T15:12:00+01:00",@@ -61,7 +59,6 @@"fields": {"uuid": "f28c8a68-ecda-42db-a9c4-781ee2aee472","remote_id": "1223334444",- "status": "2","license_author": "wger test","last_update": "2013-03-22T18:32:15+01:00","created": "2013-02-03T16:16:50+01:00",@@ -89,7 +86,6 @@"fields": {"uuid": "fdd662aa-696c-46c6-acae-b192ccc25f11","remote_id": "0987654321",- "status": "2","license_author": "wger test","last_update": "2013-02-12T12:17:45+01:00","created": "2013-04-05T12:12:12+01:00",@@ -117,7 +113,6 @@"fields": {"uuid": "293957df-b5bb-4ca6-b883-2234185c5372","remote_id": "555555555",- "status": "2","license_author": "wger test","last_update": "2013-02-12T14:14:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -145,7 +140,6 @@"fields": {"uuid": "dfc5c622-027b-4f17-8141-dadd1ce7e3f1","remote_id": "1112222333333334444444",- "status": "2","license_author": "wger test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -173,7 +167,6 @@"fields": {"uuid": "42a41805-2caf-4c7e-9ff3-decbfee5f695","remote_id": "11222222333",- "status": "1","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -201,7 +194,6 @@"fields": {"uuid": "db9e0502-2a54-472d-97e2-3761d1b286ee","remote_id": "9988877766655",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -229,7 +221,6 @@"fields": {"uuid": "7164629a-9f58-450b-8316-ad7954564171","remote_id": "123454321",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -257,7 +248,6 @@"fields": {"uuid": "9d53cf0e-5100-480f-a320-2de51c70603b","remote_id": "0009999888777",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -285,7 +275,6 @@"fields": {"uuid": "0187406a-7290-4199-a4dc-ccceb8cb55ea","remote_id": "7787878787878787",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -313,7 +302,6 @@"fields": {"uuid": "16ade127-00b0-4bcf-906e-dd9730f5ade1","remote_id": "29292929292929",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -341,7 +329,6 @@"fields": {"uuid": "59a73b2c-ead1-4001-b6a0-355c9cb366a7","remote_id": "19191919191",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",@@ -369,7 +356,6 @@"fields": {"uuid": "a18665d0-24e3-4255-88aa-92f2831d568a","remote_id": "4444444444444",- "status": "2","license_author": "test","last_update": "2013-02-12T01:00:00+01:00","created": "2013-04-05T01:00:00+01:00",diff --git a/wger/nutrition/management/commands/import-off-products.py b/wger/nutrition/management/commands/import-off-products.pyindex 3ffb6de67..174d49e53 100644--- a/wger/nutrition/management/commands/import-off-products.py+++ b/wger/nutrition/management/commands/import-off-products.py@@ -28,6 +28,7 @@ from wger.nutrition.management.products import ()from wger.nutrition.off import extract_info_from_off+logger = logging.getLogger(__name__)@@ -49,8 +50,10 @@ class Command(ImportProductCommand):action='store_true',default=False,dest='use_jsonl',- help=('Use the JSONL dump of the Open Food Facts database.'- '(this option does not require mongo)')+ help=(+ 'Use the JSONL dump of the Open Food Facts database.'+ '(this option does not require mongo)'+ ),)parser.add_argument(diff --git a/wger/nutrition/migrations/0024_remove_ingredient_status.py b/wger/nutrition/migrations/0024_remove_ingredient_status.pynew file mode 100644index 000000000..85d00a473--- /dev/null+++ b/wger/nutrition/migrations/0024_remove_ingredient_status.py@@ -0,0 +1,55 @@+# Generated by Django 4.2.13 on 2024-05-24 17:28++import django.core.validators+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ('nutrition', '0023_fiber_spelling'),+ ]++ operations = [+ migrations.RemoveField(+ model_name='ingredient',+ name='status',+ ),+ migrations.AlterField(+ model_name='image',+ 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='ingredient',+ name='fiber',+ field=models.DecimalField(+ blank=True,+ decimal_places=3,+ help_text='In g per 100g of product',+ max_digits=6,+ null=True,+ validators=[+ django.core.validators.MinValueValidator(0),+ django.core.validators.MaxValueValidator(100),+ ],+ verbose_name='Fiber',+ ),+ ),+ migrations.AlterField(+ model_name='ingredient',+ 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/models/ingredient.py b/wger/nutrition/models/ingredient.pyindex 4563c997a..443dd0925 100644--- a/wger/nutrition/models/ingredient.py+++ b/wger/nutrition/models/ingredient.py@@ -54,28 +54,20 @@ from wger.nutrition.models.sources import Sourcefrom wger.utils.cache import cache_mapperfrom wger.utils.constants import TWOPLACESfrom wger.utils.language import load_language-from wger.utils.managers import SubmissionManager-from wger.utils.models import (- AbstractLicenseModel,- AbstractSubmissionModel,-)+from wger.utils.models import AbstractLicenseModelfrom wger.utils.requests import wger_user_agent# Localfrom .ingredient_category import IngredientCategory-logger = logging.getLogger(__name__)-class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):+class Ingredient(AbstractLicenseModel, models.Model):"""An ingredient, with some approximate nutrition values"""- objects = SubmissionManager()- """Custom manager"""-ENERGY_APPROXIMATION = 15"""How much the calculated energy from protein, etc. can deviate from the@@ -373,50 +365,9 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):## Own methods#-- def send_email(self, request):- """- Sends an email after being successfully added to the database (for user- submitted ingredients only)- """- try:- user = User.objects.get(username=self.license_author)- except User.DoesNotExist:- return-- if self.license_author and user.email:- translation.activate(user.userprofile.notification_language.short_name)- url = request.build_absolute_uri(self.get_absolute_url())- subject = _('Ingredient was successfully added to the general database')- context = {- 'ingredient': self.name,- 'url': url,- 'site': Site.objects.get_current().domain,- }- message = render_to_string('ingredient/email_new.tpl', context)- mail.send_mail(- subject,- message,- settings.WGER_SETTINGS['EMAIL_FROM'],- [user.email],- fail_silently=True,- )-def set_author(self, request):- if request.user.has_perm('nutrition.add_ingredient'):- self.status = Ingredient.STATUS_ACCEPTED- if not self.license_author:- self.license_author = request.get_host().split(':')[0]- else:- if not self.license_author:- self.license_author = request.user.username-- # Send email to administrator- subject = _('New user submitted ingredient')- message = _(- f'The user {request.user.username} submitted a new ingredient "{self.name}".'- )- mail.mail_admins(subject, message, fail_silently=True)+ if not self.license_author:+ self.license_author = request.get_host().split(':')[0]def get_owner_object(self):"""diff --git a/wger/nutrition/off.py b/wger/nutrition/off.pyindex 936768938..fb30a4602 100644--- a/wger/nutrition/off.py+++ b/wger/nutrition/off.py@@ -20,7 +20,6 @@ from wger.nutrition.consts import KJ_PER_KCALfrom wger.nutrition.dataclasses import IngredientDatafrom wger.nutrition.models import Sourcefrom wger.utils.constants import ODBL_LICENSE_ID-from wger.utils.models import AbstractSubmissionModelOFF_REQUIRED_TOP_LEVEL = [@@ -89,7 +88,6 @@ def extract_info_from_off(product_data: dict, language: int) -> IngredientData:source_url=source_url,common_name=common_name,brand=brand,- status=AbstractSubmissionModel.STATUS_ACCEPTED,license_id=ODBL_LICENSE_ID,license_author=authors,license_title=name,diff --git a/wger/nutrition/sitemap.py b/wger/nutrition/sitemap.pyindex 285ccb1a7..d948ddff1 100644--- a/wger/nutrition/sitemap.py+++ b/wger/nutrition/sitemap.py@@ -26,7 +26,7 @@ class NutritionSitemap(Sitemap):priority = 0.5def items(self):- return Ingredient.objects.accepted()+ return Ingredient.objects.all()def lastmod(self, obj):return obj.last_updatediff --git a/wger/nutrition/templates/ingredient/pending.html b/wger/nutrition/templates/ingredient/pending.htmldeleted file mode 100644index 2b0b9c390..000000000--- a/wger/nutrition/templates/ingredient/pending.html+++ /dev/null@@ -1,37 +0,0 @@-{% extends "base.html" %}-{% load i18n %}-{% load static %}-{% load wger_extras %}--{% block title %}{% translate "Ingredients pending review" %}{% endblock %}---{% block content %}--<table class="table">-<thead>-<tr>- <th>{% translate "Submission date" %}</th>- <th>{% translate "Name" %}</th>- <th>{% translate "User" %}</th>-</tr>-</thead>-<tbody>-{% for ingredient in ingredient_list %}-<tr>- <td>- {{ ingredient.created }}- </td>- <td><a href="{{ ingredient.get_absolute_url }}">{{ingredient.name}}</a></td>- <td>{{ingredient.user.username}}</td>-</tr>-{% empty %}-<tr>- <td colspan="2">{% translate "Nothing found" %}</td>-</tr>-{% endfor %}-</tbody>--</table>-<div style="padding-top:3em;"></div>-{% endblock %}diff --git a/wger/nutrition/templates/ingredient/view.html b/wger/nutrition/templates/ingredient/view.htmlindex 3adc780f9..012b736d5 100644--- a/wger/nutrition/templates/ingredient/view.html+++ b/wger/nutrition/templates/ingredient/view.html@@ -22,32 +22,6 @@ $(document).ready(function() {{% block content %}-{% if ingredient.status == ingredient.STATUS_PENDING %}-<div class="alert">-<h4>{% translate "Ingredient is pending review" %}</h4>-<p>{% blocktranslate %}This user submitted ingredient is pending a decision to be-included in the database. Till then, it will not be shown in the overview or-the search.{% endblocktranslate %}-{% if perms.nutrition.add_ingredient %}{% translate "Please select one of the options below." %}{% endif %}-</p>--{% if perms.nutrition.add_ingredient %}-<div class="btn-group btn-group-justified" role="group">- <a href="{% url 'nutrition:ingredient:accept' ingredient.id %}" class="btn btn-light">- <span class="{% fa_class 'check' %}"></span>- {% translate "Accept" %}- </a>- <a href="{% url 'nutrition:ingredient:decline' ingredient.id %}" class="btn btn-light">- <span class="{% fa_class 'times' %}"></span>- {% translate "Decline" %}- </a>-</div>-{% endif %} {# end check permissions #}--</div>-{% endif %} {# end ingredient is pending review #}--<div itemscope itemtype="http://schema.org/NutritionInformation">diff --git a/wger/nutrition/tests/test_ingredient.py b/wger/nutrition/tests/test_ingredient.pyindex 16d54b349..5176d1749 100644--- a/wger/nutrition/tests/test_ingredient.py+++ b/wger/nutrition/tests/test_ingredient.py@@ -132,10 +132,8 @@ class AddIngredientTestCase(WgerAddTestCase):ingredient.created.replace(microsecond=0),datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0),)- self.assertEqual(ingredient.status, Ingredient.STATUS_ACCEPTED)elif self.current_user == 'test':ingredient = Ingredient.objects.get(pk=self.pk_after)- self.assertEqual(ingredient.status, Ingredient.STATUS_PENDING)class IngredientNameShortTestCase(WgerTestCase):@@ -209,11 +207,9 @@ class IngredientDetailTestCase(WgerTestCase):if editor:self.assertContains(response, 'Edit ingredient')self.assertContains(response, 'Delete ingredient')- self.assertContains(response, 'pending review')else:self.assertNotContains(response, 'Edit ingredient')self.assertNotContains(response, 'Delete ingredient')- self.assertNotContains(response, 'pending review')# Non-existent ingredients throw a 404.response = self.client.get(reverse('nutrition:ingredient:view', kwargs={'pk': 42}))@@ -270,12 +266,6 @@ class IngredientSearchTestCase(WgerTestCase):self.assertEqual(result['suggestions'][1]['data']['image'], None)self.assertEqual(result['suggestions'][1]['data']['image_thumbnail'], None)- # Search for an ingredient pending review (0 hits, "Pending ingredient")- response = self.client.get(reverse('ingredient-search'), {'term': 'Pending'}, **kwargs)- self.assertEqual(response.status_code, 200)- result = json.loads(response.content.decode('utf8'))- self.assertEqual(len(result['suggestions']), 0)-def test_search_ingredient_anonymous(self):"""Test searching for an ingredient by an anonymous userdiff --git a/wger/nutrition/tests/test_ingredient_overview.py b/wger/nutrition/tests/test_ingredient_overview.pyindex 59f152814..8f3b52cf8 100644--- a/wger/nutrition/tests/test_ingredient_overview.py+++ b/wger/nutrition/tests/test_ingredient_overview.py@@ -56,7 +56,7 @@ class IngredientOverviewTestCase(WgerTestCase):self.assertEqual(response.status_code, 200)self.assertEqual(len(response.context['ingredients_list']), PAGINATION_OBJECTS_PER_PAGE)- rest_ingredients = 13+ rest_ingredients = 14response = self.client.get(reverse('nutrition:ingredient:list'), {'page': 3})self.assertEqual(response.status_code, 200)self.assertEqual(len(response.context['ingredients_list']), rest_ingredients)diff --git a/wger/nutrition/tests/test_off.py b/wger/nutrition/tests/test_off.pyindex ff6ef070a..a4a5fe71c 100644--- a/wger/nutrition/tests/test_off.py+++ b/wger/nutrition/tests/test_off.py@@ -20,7 +20,6 @@ from django.test import SimpleTestCasefrom wger.nutrition.dataclasses import IngredientDatafrom wger.nutrition.off import extract_info_from_offfrom wger.utils.constants import ODBL_LICENSE_ID-from wger.utils.models import AbstractSubmissionModelclass ExtractInfoFromOffTestCase(SimpleTestCase):@@ -73,7 +72,6 @@ class ExtractInfoFromOffTestCase(SimpleTestCase):source_url='https://world.openfoodfacts.org/api/v2/product/1234.json',common_name='Foo with chocolate, 250g package',brand='The bar company',- status=AbstractSubmissionModel.STATUS_ACCEPTED,license_id=ODBL_LICENSE_ID,license_author='open food facts, MrX',license_title='Foo with chocolate',diff --git a/wger/nutrition/tests/test_submitted_ingredient.py b/wger/nutrition/tests/test_submitted_ingredient.pydeleted file mode 100644index 233fecd2c..000000000--- a/wger/nutrition/tests/test_submitted_ingredient.py+++ /dev/null@@ -1,202 +0,0 @@-# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Django-from django.core import mail-from django.urls import reverse--# wger-from wger.core.tests.base_testcase import WgerTestCase-from wger.nutrition.models import Ingredient---class IngredientsPendingTestCase(WgerTestCase):- """- Tests the pending ingredients overview page- """-- def pending_overview(self, fail=False):- """- Helper function- """- response = self.client.get(reverse('nutrition:ingredient:pending'))- if not fail:- self.assertEqual(response.status_code, 200)- self.assertEqual(len(response.context['ingredient_list']), 1)- else:- self.assertIn(response.status_code, (302, 403))-- def test_pending_overview_admin(self):- """- Tests the pending exercises overview page as an admin user- """-- self.user_login('admin')- self.pending_overview()-- def test_pending_overview_user(self):- """- Tests the pending exercises overview page as a regular user- """-- self.user_login('test')- self.pending_overview(fail=True)-- def test_pending_overview_logged_out(self):- """- Tests the pending exercises overview page as a logged out user- """-- self.pending_overview(fail=True)---class IngredientsPendingDetailTestCase(WgerTestCase):- """- Tests the detail page of a pending ingredient- """-- def pending_view(self, fail=False):- """- Helper function- """- response = self.client.get(reverse('nutrition:ingredient:view', kwargs={'pk': 7}))- self.assertContains(response, 'pending review')-- if not fail:- self.assertEqual(response.status_code, 200)- self.assertContains(response, 'Please select one of the options below')- self.assertContains(response, 'Accept')- self.assertContains(response, 'Decline')- else:- self.assertNotContains(response, 'Please select one of the options below')- self.assertNotContains(response, 'Accept')- self.assertNotContains(response, 'Decline')-- def test_pending_view_admin(self):- """- Tests the detail page of a pending exercise as an admin user- """-- self.user_login('admin')- self.pending_view()-- def test_pending_view_user(self):- """- Tests the detail page of a pending exercise as a regular user- """-- self.user_login('test')- self.pending_view(fail=True)-- def test_pending_view_logged_out(self):- """- Tests the detail page of a pending exercise as a logged out user- """-- self.pending_view(fail=True)---class IngredientAcceptTestCase(WgerTestCase):- """- Tests accepting a user submitted ingredient- """-- def accept(self, fail=False):- """- Helper function- """- ingredient = Ingredient.objects.get(pk=7)- self.assertEqual(ingredient.status, Ingredient.STATUS_PENDING)- response = self.client.get(reverse('nutrition:ingredient:accept', kwargs={'pk': 7}))- ingredient = Ingredient.objects.get(pk=7)- self.assertEqual(response.status_code, 302)-- if not fail:- self.assertEqual(ingredient.status, Ingredient.STATUS_ACCEPTED)- response = self.client.get(response['Location'])- self.assertEqual(response.status_code, 200)- self.assertEqual(len(mail.outbox), 1)- else:- self.assertEqual(ingredient.status, Ingredient.STATUS_PENDING)- self.assertEqual(len(mail.outbox), 0)-- def test_accept_admin(self):- """- Tests accepting a user submitted ingredient as an admin user- """-- self.user_login('admin')- self.accept(fail=False)-- def test_accept_user(self):- """- Tests accepting a user submitted ingredient as a regular user- """-- self.user_login('test')- self.accept(fail=True)-- def test_accept_logged_out(self):- """- Tests accepting a user submitted ingredient as a logged out user- """-- self.accept(fail=True)---class IngredientRejectTestCase(WgerTestCase):- """- Tests rejecting a user submitted ingredient- """-- def reject(self, fail=False):- """- Helper function- """- ingredient = Ingredient.objects.get(pk=7)- self.assertEqual(ingredient.status, Ingredient.STATUS_PENDING)- response = self.client.get(reverse('nutrition:ingredient:decline', kwargs={'pk': 7}))- ingredient = Ingredient.objects.get(pk=7)- self.assertEqual(response.status_code, 302)-- if not fail:- self.assertEqual(ingredient.status, Ingredient.STATUS_DECLINED)- response = self.client.get(response['Location'])- self.assertEqual(response.status_code, 200)-- else:- self.assertEqual(ingredient.status, Ingredient.STATUS_PENDING)-- def test_reject_admin(self):- """- Tests rejecting a user submitted ingredient as an admin user- """-- self.user_login('admin')- self.reject()-- def test_reject_user(self):- """- Tests rejecting a user submitted ingredient as a regular user- """-- self.user_login('test')- self.reject(fail=True)-- def test_reject_logged_out(self):- """- Tests rejecting a user submitted ingredient as a logged out user- """-- self.reject(fail=True)diff --git a/wger/nutrition/tests/test_usda.py b/wger/nutrition/tests/test_usda.pyindex 8dc7895d1..8aab7d43c 100644--- a/wger/nutrition/tests/test_usda.py+++ b/wger/nutrition/tests/test_usda.py@@ -23,7 +23,6 @@ from wger.nutrition.usda import (extract_info_from_usda,)from wger.utils.constants import CC_0_LICENSE_ID-from wger.utils.models import AbstractSubmissionModelclass ExtractInfoFromUSDATestCase(SimpleTestCase):@@ -225,10 +224,9 @@ class ExtractInfoFromUSDATestCase(SimpleTestCase):source_url='https://fdc.nal.usda.gov/',common_name='Foo With Chocolate',brand='',- status=AbstractSubmissionModel.STATUS_ACCEPTED,license_id=CC_0_LICENSE_ID,license_author='U.S. Department of Agriculture, Agricultural Research Service, '- 'Beltsville Human Nutrition Research Center. FoodData Central.',+ 'Beltsville Human Nutrition Research Center. FoodData Central.',license_title='Foo With Chocolate',license_object_url='https://fdc.nal.usda.gov/fdc-app.html#/food-details/1234567/nutrients',)diff --git a/wger/nutrition/urls.py b/wger/nutrition/urls.pyindex 629f5849f..8ee4c952e 100644--- a/wger/nutrition/urls.py+++ b/wger/nutrition/urls.py@@ -81,21 +81,6 @@ patterns_ingredient = [ingredient.IngredientListView.as_view(),name='list',),- path(- 'pending/',- ingredient.PendingIngredientListView.as_view(),- name='pending',- ),- path(- '<int:pk>/accept/',- ingredient.accept,- name='accept',- ),- path(- '<int:pk>/decline/',- ingredient.decline,- name='decline',- ),path('<int:pk>/view/',ingredient.view,diff --git a/wger/nutrition/usda.py b/wger/nutrition/usda.pyindex 2c432b6a0..9e14bd213 100644--- a/wger/nutrition/usda.py+++ b/wger/nutrition/usda.py@@ -17,7 +17,6 @@from wger.nutrition.dataclasses import IngredientDatafrom wger.nutrition.models import Sourcefrom wger.utils.constants import CC_0_LICENSE_ID-from wger.utils.models import AbstractSubmissionModeldef convert_to_grams(entry: dict) -> float:@@ -116,7 +115,6 @@ def extract_info_from_usda(product_data: dict, language: int) -> IngredientData:source_name=source_name,source_url=source_url,brand=brand,- status=AbstractSubmissionModel.STATUS_ACCEPTED,license_id=CC_0_LICENSE_ID,license_author=author,license_title=name,diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.pyindex 25659d990..4b7b243a5 100644--- a/wger/nutrition/views/ingredient.py+++ b/wger/nutrition/views/ingredient.py@@ -18,17 +18,12 @@import logging# Django-from django.contrib import messages-from django.contrib.auth.decorators import permission_requiredfrom django.contrib.auth.mixins import (LoginRequiredMixin,PermissionRequiredMixin,)from django.core.cache import cache-from django.http import (- HttpResponseForbidden,- HttpResponseRedirect,-)+from django.http import HttpResponseForbiddenfrom django.shortcuts import (get_object_or_404,render,@@ -81,7 +76,7 @@ class IngredientListView(ListView):Filter the ingredients the user will see by its language"""language = load_language()- return Ingredient.objects.accepted().filter(language=language).only('id', 'name')+ return Ingredient.objects.filter(language=language).only('id', 'name')def view(request, pk, slug=None):@@ -165,46 +160,3 @@ class IngredientCreateView(WgerFormMixin, CreateView):if request.user.userprofile.is_temporary:return HttpResponseForbidden()return super(IngredientCreateView, self).dispatch(request, *args, **kwargs)---class PendingIngredientListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):- """- List all ingredients pending review- """-- model = Ingredient- template_name = 'ingredient/pending.html'- context_object_name = 'ingredient_list'- permission_required = 'nutrition.change_ingredient'-- def get_queryset(self):- """- Only show ingredients pending review- """- return Ingredient.objects.filter(status=Ingredient.STATUS_PENDING).order_by('-created')---@permission_required('nutrition.add_ingredient')-def accept(request, pk):- """- Accepts a pending user submitted ingredient- """- ingredient = get_object_or_404(Ingredient, pk=pk)- ingredient.status = Ingredient.STATUS_ACCEPTED- ingredient.save()- ingredient.send_email(request)- messages.success(request, _('Ingredient was successfully added to the general database'))-- return HttpResponseRedirect(ingredient.get_absolute_url())---@permission_required('nutrition.add_ingredient')-def decline(request, pk):- """- Declines and deletes a pending user submitted ingredient- """- ingredient = get_object_or_404(Ingredient, pk=pk)- ingredient.status = Ingredient.STATUS_DECLINED- ingredient.save()- messages.success(request, _('Ingredient was successfully marked as rejected'))- return HttpResponseRedirect(ingredient.get_absolute_url())diff --git a/wger/utils/managers.py b/wger/utils/managers.pydeleted file mode 100644index f70717b7e..000000000--- a/wger/utils/managers.py+++ /dev/null@@ -1,48 +0,0 @@-# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License-# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.--# Django-from django.db import models-from django.db.models.query import QuerySet--# wger-from wger.utils.models import AbstractSubmissionModel---"""-Custom managers and querysets-"""--# TODO: starting with django 1.7 this is simplified, see-# https://docs.djangoproject.com/en/1.7/topics/db/managers/#creating-manager-with-queryset-methods---class SubmissionQuerySet(QuerySet):- def accepted(self):- return self.filter(status=AbstractSubmissionModel.STATUS_ACCEPTED)-- def pending(self):- return self.filter(status=AbstractSubmissionModel.STATUS_PENDING)---class SubmissionManager(models.Manager):- def get_queryset(self):- return SubmissionQuerySet(self.model, using=self._db)-- def accepted(self):- return self.get_queryset().accepted()-- def pending(self):- return self.get_queryset().pending()diff --git a/wger/utils/models.py b/wger/utils/models.pyindex aa6660b2d..79d453884 100644--- a/wger/utils/models.py+++ b/wger/utils/models.py@@ -110,37 +110,6 @@ class AbstractLicenseModel(models.Model):return out-class AbstractSubmissionModel(models.Model):- """- Abstract class used for model for user submitted data.-- These models have to be approved first by an administrator before they are- shows in the website. There is also a manager that can be used:- utils.managers.SubmissionManager- """-- class Meta:- abstract = True-- STATUS_PENDING = '1'- STATUS_ACCEPTED = '2'- STATUS_DECLINED = '3'-- STATUS = (- (STATUS_PENDING, _('Pending')),- (STATUS_ACCEPTED, _('Accepted')),- (STATUS_DECLINED, _('Declined')),- )-- status = models.CharField(- max_length=2,- choices=STATUS,- default=STATUS_PENDING,- editable=False,- )- """Status of the submission, e.g. accepted or declined"""--class AbstractHistoryMixin:"""Abstract class used to model specific historical records.