mirror of
https://github.com/wger-project/wger.git
synced 2026-12-06 15:54:39 +01:00
Rename exercise model to translation
This commit is contained in:
1 parent
a0c5d300c4
commit
385df1d64f
31 files changed
+744
-745
No files matched your search
+558
-558
File diff suppressed because it is too large.
Load diff
@@ -16,7 +16,7 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
# wger
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -42,7 +42,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f'Extracting translations for {exercise_key}')
|
||||
|
||||
uuid = self.uuids[exercise_key]
|
||||
translations = Exercise.objects.filter(exercise_base__uuid=uuid)
|
||||
translations = Translation.objects.filter(exercise_base__uuid=uuid)
|
||||
|
||||
variables = []
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db.models import Q
|
||||
|
||||
# Third Party
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -25,7 +24,7 @@ from wger.exercises.models import (
|
||||
Alias,
|
||||
DeletionLog,
|
||||
Equipment,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseCategory,
|
||||
ExerciseComment,
|
||||
@@ -280,7 +279,7 @@ class ExerciseSerializer(serializers.ModelSerializer):
|
||||
author_history = serializers.ListSerializer(child=serializers.CharField())
|
||||
|
||||
class Meta:
|
||||
model = Exercise
|
||||
model = Translation
|
||||
fields = (
|
||||
'id',
|
||||
'uuid',
|
||||
@@ -316,7 +315,7 @@ class ExerciseTranslationBaseInfoSerializer(serializers.ModelSerializer):
|
||||
author_history = serializers.ListSerializer(child=serializers.CharField())
|
||||
|
||||
class Meta:
|
||||
model = Exercise
|
||||
model = Translation
|
||||
fields = (
|
||||
'id',
|
||||
'uuid',
|
||||
@@ -350,7 +349,7 @@ class ExerciseTranslationSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Exercise
|
||||
model = Translation
|
||||
fields = (
|
||||
'id',
|
||||
'uuid',
|
||||
@@ -380,7 +379,7 @@ class ExerciseTranslationSerializer(serializers.ModelSerializer):
|
||||
# Creating a new object
|
||||
# -> Check if the language already exists
|
||||
else:
|
||||
if Exercise.objects.filter(
|
||||
if Translation.objects.filter(
|
||||
exercise_base=value['exercise_base'],
|
||||
language=value['language'],
|
||||
).exists():
|
||||
@@ -408,7 +407,7 @@ class ExerciseInfoSerializer(serializers.ModelSerializer):
|
||||
author_history = serializers.ListSerializer(child=serializers.CharField())
|
||||
|
||||
class Meta:
|
||||
model = Exercise
|
||||
model = Translation
|
||||
depth = 1
|
||||
fields = [
|
||||
'id',
|
||||
|
||||
+12
-14
@@ -17,6 +17,10 @@
|
||||
import logging
|
||||
from uuid import UUID
|
||||
|
||||
# Third Party
|
||||
import bleach
|
||||
from actstream import action as actstream_action
|
||||
from bleach.css_sanitizer import CSSSanitizer
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
@@ -24,11 +28,6 @@ from django.db.models import Q
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
# Third Party
|
||||
import bleach
|
||||
from actstream import action as actstream_action
|
||||
from bleach.css_sanitizer import CSSSanitizer
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from drf_spectacular.utils import (
|
||||
OpenApiParameter,
|
||||
@@ -72,7 +71,7 @@ from wger.exercises.models import (
|
||||
Alias,
|
||||
DeletionLog,
|
||||
Equipment,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseCategory,
|
||||
ExerciseComment,
|
||||
@@ -92,7 +91,6 @@ from wger.utils.constants import (
|
||||
from wger.utils.db import is_postgres_db
|
||||
from wger.utils.language import load_language
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -153,7 +151,7 @@ class ExerciseTranslationViewSet(ModelViewSet):
|
||||
API endpoint for editing or adding exercise translation objects.
|
||||
"""
|
||||
|
||||
queryset = Exercise.objects.all()
|
||||
queryset = Translation.objects.all()
|
||||
permission_classes = (CanContributeExercises,)
|
||||
serializer_class = ExerciseTranslationSerializer
|
||||
ordering_fields = '__all__'
|
||||
@@ -223,7 +221,7 @@ class ExerciseViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
This is only kept for backwards compatibility and will be removed in the future
|
||||
"""
|
||||
|
||||
queryset = Exercise.objects.all()
|
||||
queryset = Translation.objects.all()
|
||||
permission_classes = (CanContributeExercises,)
|
||||
serializer_class = ExerciseSerializer
|
||||
ordering_fields = '__all__'
|
||||
@@ -251,7 +249,7 @@ class ExerciseViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
def get_queryset(self):
|
||||
"""Add additional filters for fields from exercise base"""
|
||||
|
||||
qs = Exercise.objects.all()
|
||||
qs = Translation.objects.all()
|
||||
|
||||
category = self.request.query_params.get('category')
|
||||
muscles = self.request.query_params.get('muscles')
|
||||
@@ -350,9 +348,9 @@ def search(request):
|
||||
# Filter the appropriate languages
|
||||
languages = [load_language(l) for l in language_codes.split(',')]
|
||||
if language_codes == SEARCH_ALL_LANGUAGES:
|
||||
query = Exercise.objects.all()
|
||||
query = Translation.objects.all()
|
||||
else:
|
||||
query = Exercise.objects.filter(language__in=languages)
|
||||
query = Translation.objects.filter(language__in=languages)
|
||||
|
||||
query = query.only('name')
|
||||
|
||||
@@ -400,7 +398,7 @@ class ExerciseInfoViewset(viewsets.ReadOnlyModelViewSet):
|
||||
API endpoint for exercise objects, use /api/v2/exercisebaseinfo/ instead.
|
||||
"""
|
||||
|
||||
queryset = Exercise.objects.all()
|
||||
queryset = Translation.objects.all()
|
||||
serializer_class = ExerciseInfoSerializer
|
||||
ordering_fields = '__all__'
|
||||
filterset_fields = (
|
||||
@@ -609,7 +607,7 @@ class ExerciseCommentViewSet(ModelViewSet):
|
||||
qs = ExerciseComment.objects.all()
|
||||
language = self.request.query_params.get('language')
|
||||
if language:
|
||||
exercises = Exercise.objects.filter(language=language)
|
||||
exercises = Translation.objects.filter(language=language)
|
||||
qs = ExerciseComment.objects.filter(exercise__in=exercises)
|
||||
return qs
|
||||
|
||||
|
||||
@@ -23,12 +23,10 @@ class ExerciseConfig(AppConfig):
|
||||
verbose_name = 'Exercise'
|
||||
|
||||
def ready(self):
|
||||
import wger.exercises.signals
|
||||
|
||||
from actstream import registry
|
||||
|
||||
registry.register(self.get_model('Alias'))
|
||||
registry.register(self.get_model('Exercise'))
|
||||
registry.register(self.get_model('Translation'))
|
||||
registry.register(self.get_model('ExerciseBase'))
|
||||
registry.register(self.get_model('ExerciseComment'))
|
||||
registry.register(self.get_model('ExerciseImage'))
|
||||
|
||||
@@ -138,7 +138,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "9838235c-e38f-4ca6-921e-9d237d8e0813",
|
||||
"language": 2,
|
||||
@@ -151,7 +151,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "7524ca8d-032e-482d-ab18-40e8a97851f6",
|
||||
"language": 2,
|
||||
@@ -164,7 +164,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "946afe7b-54a6-44a6-9c36-c3e31e6b4c3b",
|
||||
"language": 2,
|
||||
@@ -177,7 +177,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 4,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "5e80d257-3ece-43a1-b01d-2b28c6c288be",
|
||||
"language": 2,
|
||||
@@ -191,7 +191,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 5,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "13b532f9-d208-462e-a000-7b9982b2b53e",
|
||||
"language": 3,
|
||||
@@ -205,7 +205,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 6,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "e75335be-5177-4475-b17b-8d833c2aadf1",
|
||||
"language": 3,
|
||||
@@ -219,7 +219,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 7,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "3362115b-5743-4896-9bdd-4abc17b8cc86",
|
||||
"language": 1,
|
||||
@@ -232,7 +232,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 8,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "e75c421a-6839-4c14-b89a-bd2023818089",
|
||||
"language": 2,
|
||||
@@ -245,7 +245,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 9,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "c6286b86-026e-4fdb-9223-c8b011073678",
|
||||
"language": 2,
|
||||
@@ -258,7 +258,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 10,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "a2c9fac1-6d2c-4564-9300-0719d12a7ed1",
|
||||
"language": 2,
|
||||
@@ -271,7 +271,7 @@
|
||||
},
|
||||
{
|
||||
"pk": 11,
|
||||
"model": "exercises.exercise",
|
||||
"model": "exercises.translation",
|
||||
"fields": {
|
||||
"uuid": "b589657e-5a8d-468a-9dc2-4d5b2237b394",
|
||||
"language": 2,
|
||||
|
||||
@@ -17,7 +17,7 @@ from django.core.management.base import BaseCommand
|
||||
|
||||
# wger
|
||||
from wger.exercises.models import ExerciseBase
|
||||
from wger.exercises.models.exercise import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -70,7 +70,7 @@ class Command(BaseCommand):
|
||||
|
||||
if exercise_id is not None:
|
||||
try:
|
||||
exercise = Exercise.objects.get(id=exercise_id)
|
||||
exercise = Translation.objects.get(id=exercise_id)
|
||||
except ExerciseBase.DoesNotExist:
|
||||
self.print_error('Failed to find exercise')
|
||||
return
|
||||
|
||||
@@ -21,7 +21,7 @@ from django.core.management.base import BaseCommand
|
||||
# wger
|
||||
from wger.core.models import Language
|
||||
from wger.exercises.models import (
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ class Command(BaseCommand):
|
||||
'author': '',
|
||||
}
|
||||
|
||||
exercise = Exercise.objects.filter(exercise_base=base, language=language).first()
|
||||
exercise = Translation.objects.filter(exercise_base=base, language=language).first()
|
||||
if exercise:
|
||||
exercise_data['uuid'] = exercise.uuid
|
||||
exercise_data['name'] = exercise.name
|
||||
|
||||
@@ -29,7 +29,7 @@ from wger.core.models import (
|
||||
from wger.exercises.models import (
|
||||
Alias,
|
||||
Equipment,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseCategory,
|
||||
ExerciseVideo,
|
||||
@@ -37,7 +37,6 @@ from wger.exercises.models import (
|
||||
)
|
||||
from wger.utils.constants import CC_BY_SA_4_ID
|
||||
|
||||
|
||||
UUID_NEW = 'NEW'
|
||||
VIDEO_AUTHOR = 'Goulart'
|
||||
VIDEO_PATH = pathlib.Path('videos-tmp')
|
||||
@@ -204,11 +203,11 @@ class Command(BaseCommand):
|
||||
continue
|
||||
|
||||
translation = (
|
||||
Exercise.objects.get_or_create(
|
||||
Translation.objects.get_or_create(
|
||||
uuid=exercise_uuid, defaults={'exercise_base': base, 'language': language}
|
||||
)[0]
|
||||
if not new_translation
|
||||
else Exercise()
|
||||
else Translation()
|
||||
)
|
||||
translation.exercise_base = base
|
||||
translation.language = language
|
||||
@@ -281,15 +280,15 @@ class Command(BaseCommand):
|
||||
|
||||
if translation_uuid:
|
||||
try:
|
||||
Exercise.objects.filter(uuid=translation_uuid).delete()
|
||||
Translation.objects.filter(uuid=translation_uuid).delete()
|
||||
self.stdout.write(f'* Deleted translation {translation_uuid}')
|
||||
except Exercise.DoesNotExist:
|
||||
except Translation.DoesNotExist:
|
||||
pass
|
||||
|
||||
if variation_id:
|
||||
try:
|
||||
Variation.objects.filter(id=variation_id).delete()
|
||||
self.stdout.write(f'* Deleted variation {variation_id}')
|
||||
except Exercise.DoesNotExist:
|
||||
except Translation.DoesNotExist:
|
||||
pass
|
||||
csv_file.close()
|
||||
@@ -16,7 +16,7 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
# wger
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -29,7 +29,7 @@ class Command(BaseCommand):
|
||||
help = 'Read out the user submitted exercise'
|
||||
|
||||
def handle(self, **options):
|
||||
exercises = Exercise.objects.all()
|
||||
exercises = Translation.objects.all()
|
||||
usernames = []
|
||||
for exercise in exercises:
|
||||
if exercise.user not in usernames:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.2.13 on 2024-06-12 12:59
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('exercises', '0030_increase_author_field_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='Exercise',
|
||||
new_name='Translation',
|
||||
),
|
||||
migrations.RenameModel(
|
||||
old_name='HistoricalExercise',
|
||||
new_name='HistoricalTranslation',
|
||||
),
|
||||
]
|
||||
@@ -20,9 +20,9 @@ from .category import ExerciseCategory
|
||||
from .comment import ExerciseComment
|
||||
from .deletion_log import DeletionLog
|
||||
from .equipment import Equipment
|
||||
from .exercise import Exercise
|
||||
from .exercise_alias import Alias
|
||||
from .image import ExerciseImage
|
||||
from .muscle import Muscle
|
||||
from .translation import Translation
|
||||
from .variation import Variation
|
||||
from .video import ExerciseVideo
|
||||
@@ -24,14 +24,13 @@ from typing import (
|
||||
|
||||
# Django
|
||||
from django.core.checks import Warning
|
||||
from django.db import models
|
||||
from django.db import models, OperationalError
|
||||
from django.db.models import Q
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import (
|
||||
get_language,
|
||||
gettext_lazy as _,
|
||||
)
|
||||
|
||||
# Third Party
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
@@ -49,7 +48,6 @@ from wger.utils.models import (
|
||||
AbstractLicenseModel,
|
||||
collect_models_author_history,
|
||||
)
|
||||
|
||||
# Local
|
||||
from .category import ExerciseCategory
|
||||
from .equipment import Equipment
|
||||
@@ -145,17 +143,22 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
|
||||
def check(cls, **kwargs):
|
||||
errors = super().check(**kwargs)
|
||||
|
||||
no_translations = cls.no_translations.all().count()
|
||||
if no_translations:
|
||||
errors.append(
|
||||
Warning(
|
||||
'exercises without translations',
|
||||
hint=f'There are {no_translations} exercises without translations, this will '
|
||||
'cause problems! You can output or delete them with "python manage.py '
|
||||
'exercises-health-check --help"',
|
||||
id='wger.W002',
|
||||
try:
|
||||
no_translations = cls.no_translations.all().count()
|
||||
if no_translations:
|
||||
errors.append(
|
||||
Warning(
|
||||
'exercises without translations',
|
||||
hint=f'There are {no_translations} exercises without translations, this will '
|
||||
'cause problems! You can output or delete them with "python manage.py '
|
||||
'exercises-health-check --help"',
|
||||
id='wger.W002',
|
||||
)
|
||||
)
|
||||
)
|
||||
except OperationalError:
|
||||
# This check runs before the migrations that rename the table "exercise"
|
||||
# to "translations" so if there are any errors, just ignore them
|
||||
pass
|
||||
|
||||
return errors
|
||||
|
||||
@@ -222,18 +225,18 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
|
||||
have deleted the English translation or similar
|
||||
"""
|
||||
# wger
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
language = language or get_language()
|
||||
|
||||
try:
|
||||
translation = self.exercises.get(language__short_name=language)
|
||||
except Exercise.DoesNotExist:
|
||||
except Translation.DoesNotExist:
|
||||
try:
|
||||
translation = self.exercises.get(language__short_name=ENGLISH_SHORT_NAME)
|
||||
except Exercise.DoesNotExist:
|
||||
except Translation.DoesNotExist:
|
||||
translation = self.exercises.first()
|
||||
except Exercise.MultipleObjectsReturned:
|
||||
except Translation.MultipleObjectsReturned:
|
||||
translation = self.exercises.filter(language__short_name=language).first()
|
||||
|
||||
return translation
|
||||
|
||||
@@ -20,15 +20,13 @@ import uuid
|
||||
# Django
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Third Party
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
# wger
|
||||
from wger.utils.cache import reset_exercise_api_cache
|
||||
|
||||
# Local
|
||||
from .exercise import Exercise
|
||||
from .translation import Translation
|
||||
|
||||
|
||||
class ExerciseComment(models.Model):
|
||||
@@ -45,7 +43,7 @@ class ExerciseComment(models.Model):
|
||||
"""Globally unique ID, to identify the comment across installations"""
|
||||
|
||||
exercise = models.ForeignKey(
|
||||
Exercise,
|
||||
Translation,
|
||||
verbose_name=_('Exercise'),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
@@ -21,15 +21,13 @@ import uuid
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Third Party
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
# wger
|
||||
from wger.utils.cache import reset_exercise_api_cache
|
||||
|
||||
# Local
|
||||
from .exercise import Exercise
|
||||
from .translation import Translation
|
||||
|
||||
|
||||
class Alias(models.Model):
|
||||
@@ -46,7 +44,7 @@ class Alias(models.Model):
|
||||
"""Globally unique ID, to identify the alias across installations"""
|
||||
|
||||
exercise = models.ForeignKey(
|
||||
Exercise,
|
||||
Translation,
|
||||
verbose_name=_('Exercise'),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# Standard Library
|
||||
import uuid
|
||||
|
||||
# Third Party
|
||||
import bleach
|
||||
# Django
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.core.validators import MinLengthValidator
|
||||
@@ -24,9 +26,6 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Third Party
|
||||
import bleach
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
# wger
|
||||
@@ -39,9 +38,9 @@ from wger.utils.models import (
|
||||
)
|
||||
|
||||
|
||||
class Exercise(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
|
||||
class Translation(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
|
||||
"""
|
||||
Model for an exercise
|
||||
Model for an exercise translation
|
||||
"""
|
||||
|
||||
description = models.TextField(
|
||||
@@ -24,7 +24,6 @@ from django.db.models.signals import (
|
||||
pre_save,
|
||||
)
|
||||
from django.dispatch import receiver
|
||||
|
||||
# Third Party
|
||||
from easy_thumbnails.files import get_thumbnailer
|
||||
from easy_thumbnails.signal_handlers import generate_aliases
|
||||
@@ -33,7 +32,7 @@ from easy_thumbnails.signals import saved_file
|
||||
# wger
|
||||
from wger.exercises.models import (
|
||||
DeletionLog,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseImage,
|
||||
ExerciseVideo,
|
||||
)
|
||||
@@ -112,8 +111,8 @@ def delete_exercise_video_on_update(sender, instance: ExerciseVideo, **kwargs):
|
||||
# pass
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=Exercise)
|
||||
def add_deletion_log_translation(sender, instance: Exercise, **kwargs):
|
||||
@receiver(pre_delete, sender=Translation)
|
||||
def add_deletion_log_translation(sender, instance: Translation, **kwargs):
|
||||
log = DeletionLog(
|
||||
model_type=DeletionLog.MODEL_TRANSLATION,
|
||||
uuid=instance.uuid,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
from django.contrib.sitemaps import Sitemap
|
||||
|
||||
# wger
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
|
||||
class ExercisesSitemap(Sitemap):
|
||||
@@ -26,7 +26,7 @@ class ExercisesSitemap(Sitemap):
|
||||
priority = 0.5
|
||||
|
||||
def items(self):
|
||||
return Exercise.objects.all()
|
||||
return Translation.objects.all()
|
||||
|
||||
def lastmod(self, obj):
|
||||
return obj.last_update
|
||||
@@ -15,14 +15,13 @@
|
||||
# Standard Library
|
||||
import os
|
||||
|
||||
# Third Party
|
||||
import requests
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.core.files import File
|
||||
from django.core.files.temp import NamedTemporaryFile
|
||||
|
||||
# Third Party
|
||||
import requests
|
||||
|
||||
# wger
|
||||
from wger.core.api.endpoints import (
|
||||
LANGUAGE_ENDPOINT,
|
||||
@@ -45,7 +44,7 @@ from wger.exercises.models import (
|
||||
Alias,
|
||||
DeletionLog,
|
||||
Equipment,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseCategory,
|
||||
ExerciseComment,
|
||||
@@ -101,7 +100,7 @@ def sync_exercises(
|
||||
description = translation_data['description']
|
||||
language_id = translation_data['language']
|
||||
|
||||
translation, translation_created = Exercise.objects.update_or_create(
|
||||
translation, translation_created = Translation.objects.update_or_create(
|
||||
uuid=trans_uuid,
|
||||
defaults={
|
||||
'exercise_base': base,
|
||||
@@ -296,7 +295,6 @@ def handle_deleted_entries(
|
||||
style_fn=lambda x: x,
|
||||
):
|
||||
if not print_fn:
|
||||
|
||||
def print_fn(_):
|
||||
return None
|
||||
|
||||
@@ -344,10 +342,10 @@ def handle_deleted_entries(
|
||||
|
||||
elif model_type == DeletionLog.MODEL_TRANSLATION:
|
||||
try:
|
||||
obj = Exercise.objects.get(uuid=uuid)
|
||||
obj = Translation.objects.get(uuid=uuid)
|
||||
obj.delete()
|
||||
print_fn(f"Deleted translation {uuid} ({data['comment']})")
|
||||
except Exercise.DoesNotExist:
|
||||
except Translation.DoesNotExist:
|
||||
pass
|
||||
|
||||
elif model_type == DeletionLog.MODEL_IMAGE:
|
||||
|
||||
@@ -20,8 +20,8 @@ from django.core.management import call_command
|
||||
|
||||
# wger
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import Translation
|
||||
from wger.exercises.models.base import ExerciseBase
|
||||
from wger.exercises.models.exercise import Exercise
|
||||
|
||||
|
||||
class ChangeExerciseAuthorTestCase(WgerTestCase):
|
||||
@@ -66,12 +66,12 @@ class ChangeExerciseAuthorTestCase(WgerTestCase):
|
||||
"""
|
||||
Test to ensure command can handle an exercise id passed
|
||||
"""
|
||||
exercise = Exercise.objects.get(id=1)
|
||||
exercise = Translation.objects.get(id=1)
|
||||
self.assertNotEqual(exercise.license_author, 'tom')
|
||||
|
||||
args = ['--author-name', 'tom', '--exercise-id', '1']
|
||||
call_command('change-exercise-author', *args, stdout=self.out, no_color=True)
|
||||
self.assertIn('Exercise and/or exercise base has been updated', self.out.getvalue())
|
||||
|
||||
exercise = Exercise.objects.get(id=1)
|
||||
exercise = Translation.objects.get(id=1)
|
||||
self.assertEqual(exercise.license_author, 'tom')
|
||||
@@ -19,7 +19,7 @@ from uuid import UUID
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
DeletionLog,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
)
|
||||
|
||||
@@ -108,7 +108,7 @@ class DeletionLogTestCase(WgerTestCase):
|
||||
"""
|
||||
self.assertEqual(DeletionLog.objects.all().count(), 0)
|
||||
|
||||
translation = Exercise.objects.get(pk=1)
|
||||
translation = Translation.objects.get(pk=1)
|
||||
translation.delete()
|
||||
|
||||
# Translation is deleted
|
||||
|
||||
@@ -19,7 +19,7 @@ from django.core.cache import cache
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
Alias,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseComment,
|
||||
)
|
||||
@@ -72,7 +72,7 @@ class ExerciseApiCacheTestCase(WgerTestCase):
|
||||
self.client.get(self.url)
|
||||
self.assertTrue(cache.get(self.cache_key))
|
||||
|
||||
translation = Exercise.objects.get(pk=1)
|
||||
translation = Translation.objects.get(pk=1)
|
||||
translation.name = 'something else'
|
||||
translation.save()
|
||||
|
||||
@@ -86,7 +86,7 @@ class ExerciseApiCacheTestCase(WgerTestCase):
|
||||
self.client.get(self.url)
|
||||
self.assertTrue(cache.get(self.cache_key))
|
||||
|
||||
translation = Exercise.objects.get(pk=1)
|
||||
translation = Translation.objects.get(pk=1)
|
||||
translation.delete()
|
||||
|
||||
self.assertFalse(cache.get(self.cache_key))
|
||||
|
||||
@@ -23,7 +23,7 @@ from wger.core.tests.api_base_test import ExerciseCrudApiTestCase
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
DeletionLog,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
)
|
||||
from wger.utils.constants import CC_BY_SA_4_ID
|
||||
@@ -43,7 +43,7 @@ class ExerciseBaseTestCase(WgerTestCase):
|
||||
"""
|
||||
Test that the properties return the correct data
|
||||
"""
|
||||
translation = Exercise.objects.get(pk=1)
|
||||
translation = Translation.objects.get(pk=1)
|
||||
exercise = translation.exercise_base
|
||||
self.assertEqual(exercise.category, translation.category)
|
||||
self.assertListEqual(self.get_ids(exercise.equipment), self.get_ids(translation.equipment))
|
||||
@@ -90,7 +90,7 @@ class ExerciseBaseTestCase(WgerTestCase):
|
||||
|
||||
def test_images(self):
|
||||
"""Test that the correct images are returned for the exercises"""
|
||||
translation = Exercise.objects.get(pk=1)
|
||||
translation = Translation.objects.get(pk=1)
|
||||
exercise = translation.exercise_base
|
||||
self.assertListEqual(
|
||||
self.get_ids(translation.images), self.get_ids(exercise.exerciseimage_set)
|
||||
|
||||
@@ -18,7 +18,7 @@ import datetime
|
||||
# wger
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
)
|
||||
|
||||
@@ -30,8 +30,8 @@ class ExerciseBaseTranslationHandlingTestCase(WgerTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
Exercise.objects.get(pk=1).delete()
|
||||
Exercise.objects.get(pk=5).delete()
|
||||
Translation.objects.get(pk=1).delete()
|
||||
Translation.objects.get(pk=5).delete()
|
||||
|
||||
def test_managers(self):
|
||||
self.assertEqual(ExerciseBase.translations.all().count(), 7)
|
||||
|
||||
@@ -14,18 +14,14 @@
|
||||
|
||||
# Django
|
||||
from django.core.files import File
|
||||
from django.urls import reverse
|
||||
|
||||
# wger
|
||||
from wger.core.tests import api_base_test
|
||||
from wger.core.tests.base_testcase import (
|
||||
WgerAddTestCase,
|
||||
WgerDeleteTestCase,
|
||||
WgerEditTestCase,
|
||||
WgerTestCase,
|
||||
)
|
||||
from wger.exercises.models import (
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseImage,
|
||||
)
|
||||
|
||||
@@ -53,7 +49,7 @@ class MainImageTestCase(WgerTestCase):
|
||||
Tests that the first uploaded image is automatically a main image
|
||||
"""
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise = Translation.objects.get(pk=2)
|
||||
pk = self.save_image(exercise, 'protestschwein.jpg')
|
||||
|
||||
image = ExerciseImage.objects.get(pk=pk)
|
||||
@@ -64,7 +60,7 @@ class MainImageTestCase(WgerTestCase):
|
||||
Tests that there is always a main image after deleting one
|
||||
"""
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise = Translation.objects.get(pk=2)
|
||||
pk1 = self.save_image(exercise, 'protestschwein.jpg')
|
||||
pk2 = self.save_image(exercise, 'wildschwein.jpg')
|
||||
|
||||
@@ -79,7 +75,7 @@ class MainImageTestCase(WgerTestCase):
|
||||
Tests that there is always a main image after deleting one
|
||||
"""
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise = Translation.objects.get(pk=2)
|
||||
pk1 = self.save_image(exercise, 'protestschwein.jpg')
|
||||
pk2 = self.save_image(exercise, 'protestschwein.jpg')
|
||||
pk3 = self.save_image(exercise, 'wildschwein.jpg')
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
# wger
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
|
||||
|
||||
class ExerciseModelTestCase(WgerTestCase):
|
||||
@@ -24,15 +24,15 @@ class ExerciseModelTestCase(WgerTestCase):
|
||||
|
||||
def test_absolute_url_name(self):
|
||||
"""Test that the get_absolute_url returns the correct URL"""
|
||||
exercise = Exercise(exercise_base_id=1, description='abc', name='foo')
|
||||
exercise = Translation(exercise_base_id=1, description='abc', name='foo')
|
||||
self.assertEqual(exercise.get_absolute_url(), '/en/exercise/1/view-base/foo')
|
||||
|
||||
def test_absolute_url_no_name(self):
|
||||
"""Test that the get_absolute_url returns the correct URL"""
|
||||
exercise = Exercise(exercise_base_id=2, description='abc', name='')
|
||||
exercise = Translation(exercise_base_id=2, description='abc', name='')
|
||||
self.assertEqual(exercise.get_absolute_url(), '/en/exercise/2/view-base')
|
||||
|
||||
def test_absolute_url_no_name2(self):
|
||||
"""Test that the get_absolute_url returns the correct URL"""
|
||||
exercise = Exercise(exercise_base_id=42, description='abc', name='@@@@@')
|
||||
exercise = Translation(exercise_base_id=42, description='abc', name='@@@@@')
|
||||
self.assertEqual(exercise.get_absolute_url(), '/en/exercise/42/view-base')
|
||||
@@ -16,13 +16,11 @@
|
||||
import json
|
||||
|
||||
# Django
|
||||
from django.core.cache import cache
|
||||
from django.template import (
|
||||
Context,
|
||||
Template,
|
||||
)
|
||||
from django.urls import reverse
|
||||
|
||||
# Third Party
|
||||
from rest_framework import status
|
||||
|
||||
@@ -30,14 +28,12 @@ from rest_framework import status
|
||||
from wger.core.tests import api_base_test
|
||||
from wger.core.tests.api_base_test import ExerciseCrudApiTestCase
|
||||
from wger.core.tests.base_testcase import (
|
||||
WgerDeleteTestCase,
|
||||
WgerTestCase,
|
||||
)
|
||||
from wger.exercises.models import (
|
||||
Exercise,
|
||||
Translation,
|
||||
Muscle,
|
||||
)
|
||||
from wger.utils.cache import cache_mapper
|
||||
from wger.utils.constants import CC_BY_SA_4_ID
|
||||
|
||||
|
||||
@@ -50,7 +46,7 @@ class ExerciseRepresentationTestCase(WgerTestCase):
|
||||
"""
|
||||
Test that the representation of an object is correct
|
||||
"""
|
||||
self.assertEqual(str(Exercise.objects.get(pk=1)), 'An exercise')
|
||||
self.assertEqual(str(Translation.objects.get(pk=1)), 'An exercise')
|
||||
|
||||
|
||||
class ExercisesTestCase(WgerTestCase):
|
||||
@@ -99,7 +95,7 @@ class ExercisesTestCase(WgerTestCase):
|
||||
"""
|
||||
Test that changing exercise details generates a historical record
|
||||
"""
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise = Translation.objects.get(pk=2)
|
||||
self.assertEqual(len(exercise.history.all()), 0)
|
||||
|
||||
exercise.name = 'Very cool exercise 2'
|
||||
@@ -107,7 +103,7 @@ class ExercisesTestCase(WgerTestCase):
|
||||
exercise.exercise_base.muscles_secondary.add(Muscle.objects.get(pk=2))
|
||||
exercise.save()
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise = Translation.objects.get(pk=2)
|
||||
self.assertEqual(len(exercise.history.all()), 1)
|
||||
|
||||
|
||||
@@ -225,10 +221,13 @@ class ExerciseApiTestCase(
|
||||
"""
|
||||
|
||||
pk = 1
|
||||
resource = Exercise
|
||||
resource = Translation
|
||||
private_resource = False
|
||||
overview_cached = True
|
||||
|
||||
def get_resource_name(self):
|
||||
return 'exercise'
|
||||
|
||||
|
||||
class ExerciseInfoApiTestCase(
|
||||
api_base_test.BaseTestCase,
|
||||
@@ -282,45 +281,45 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):
|
||||
Test that it is not possible to change the base id of an existing
|
||||
exercise translation.
|
||||
"""
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.exercise_base_id, 1)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.exercise_base_id, 1)
|
||||
|
||||
self.authenticate('trainer1')
|
||||
response = self.client.patch(self.url_detail, data={'exercise_base': 2})
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.exercise_base_id, 1)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.exercise_base_id, 1)
|
||||
|
||||
def test_cant_change_language(self):
|
||||
"""
|
||||
Test that it is not possible to change the language id of an existing
|
||||
exercise translation.
|
||||
"""
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.language_id, 2)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.language_id, 2)
|
||||
|
||||
self.authenticate('trainer1')
|
||||
response = self.client.patch(self.url_detail, data={'language': 1})
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.language_id, 2)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.language_id, 2)
|
||||
|
||||
def test_cant_change_license(self):
|
||||
"""
|
||||
Test that it is not possible to change the license of an existing
|
||||
exercise translation.
|
||||
"""
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.license_id, 2)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.license_id, 2)
|
||||
|
||||
self.authenticate('trainer1')
|
||||
response = self.client.patch(self.url_detail, data={'license': 3})
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.license_id, 2)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.license_id, 2)
|
||||
|
||||
def test_cant_set_license(self):
|
||||
"""
|
||||
@@ -333,8 +332,8 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):
|
||||
response = self.client.post(self.url, data=self.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.license_id, CC_BY_SA_4_ID)
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.license_id, CC_BY_SA_4_ID)
|
||||
|
||||
def test_patch_clean_html(self):
|
||||
"""
|
||||
@@ -345,8 +344,8 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):
|
||||
response = self.client.patch(self.url_detail, data={'description': description})
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
exercise = Exercise.objects.get(pk=self.pk)
|
||||
self.assertEqual(exercise.description, 'alert(); The wild boar is a suid native...')
|
||||
translation = Translation.objects.get(pk=self.pk)
|
||||
self.assertEqual(translation.description, 'alert(); The wild boar is a suid native...')
|
||||
|
||||
def test_post_only_one_language_per_base(self):
|
||||
"""
|
||||
|
||||
@@ -11,20 +11,17 @@
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# Standard Library
|
||||
from time import sleep
|
||||
|
||||
# Third Party
|
||||
from actstream import action as actstream_action
|
||||
# Django
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
|
||||
# Third Party
|
||||
from actstream import action as actstream_action
|
||||
|
||||
# wger
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
from wger.exercises.views.helper import StreamVerbs
|
||||
|
||||
|
||||
@@ -39,17 +36,17 @@ class ExerciseHistoryControl(WgerTestCase):
|
||||
"""
|
||||
self.user_login()
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
translation = Translation.objects.get(pk=2)
|
||||
|
||||
exercise.save()
|
||||
exercise.name = 'Very cool exercise!'
|
||||
exercise.save()
|
||||
translation.save()
|
||||
translation.name = 'Very cool exercise!'
|
||||
translation.save()
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
translation = Translation.objects.get(pk=2)
|
||||
actstream_action.send(
|
||||
User.objects.all().first(),
|
||||
verb=StreamVerbs.UPDATED.value,
|
||||
action_object=exercise,
|
||||
action_object=translation,
|
||||
)
|
||||
|
||||
response = self.client.get(reverse('exercise:history:overview'))
|
||||
@@ -63,23 +60,23 @@ class ExerciseHistoryControl(WgerTestCase):
|
||||
"""
|
||||
self.user_login()
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
exercise.description = 'Boring exercise'
|
||||
exercise.save()
|
||||
translation = Translation.objects.get(pk=2)
|
||||
translation.description = 'Boring exercise'
|
||||
translation.save()
|
||||
|
||||
most_recent_history = exercise.history.order_by('history_date').last()
|
||||
exercise.description = 'Very cool exercise!'
|
||||
exercise.save()
|
||||
most_recent_history = translation.history.order_by('history_date').last()
|
||||
translation.description = 'Very cool exercise!'
|
||||
translation.save()
|
||||
|
||||
self.client.get(
|
||||
reverse(
|
||||
'exercise:history:revert',
|
||||
kwargs={
|
||||
'history_pk': most_recent_history.history_id,
|
||||
'content_type_id': ContentType.objects.get_for_model(exercise).id,
|
||||
'content_type_id': ContentType.objects.get_for_model(translation).id,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
exercise = Exercise.objects.get(pk=2)
|
||||
self.assertEqual(exercise.description, 'Boring exercise')
|
||||
translation = Translation.objects.get(pk=2)
|
||||
self.assertEqual(translation.description, 'Boring exercise')
|
||||
@@ -22,7 +22,7 @@ from django.test import SimpleTestCase
|
||||
# wger
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
)
|
||||
|
||||
@@ -78,8 +78,8 @@ class TestHealthCheckManagementCommands(WgerTestCase):
|
||||
self.assertEqual('', self.out.getvalue())
|
||||
|
||||
def test_find_untranslated(self):
|
||||
Exercise.objects.get(pk=1).delete()
|
||||
Exercise.objects.get(pk=5).delete()
|
||||
Translation.objects.get(pk=1).delete()
|
||||
Translation.objects.get(pk=5).delete()
|
||||
|
||||
call_command('exercises-health-check', stdout=self.out)
|
||||
self.assertIn(
|
||||
@@ -89,14 +89,14 @@ class TestHealthCheckManagementCommands(WgerTestCase):
|
||||
self.assertNotIn('-> deleted', self.out.getvalue())
|
||||
|
||||
def atest_fix_untranslated(self):
|
||||
Exercise.objects.get(pk=1).delete()
|
||||
Translation.objects.get(pk=1).delete()
|
||||
|
||||
call_command('exercises-health-check', '--delete-untranslated', stdout=self.out)
|
||||
self.assertIn('-> deleted', self.out.getvalue())
|
||||
self.assertRaises(ExerciseBase.DoesNotExist, ExerciseBase.objects.get, pk=1)
|
||||
|
||||
def test_find_no_english_translation(self):
|
||||
Exercise.objects.get(pk=1).delete()
|
||||
Translation.objects.get(pk=1).delete()
|
||||
|
||||
call_command('exercises-health-check', stdout=self.out)
|
||||
self.assertIn(
|
||||
@@ -106,14 +106,14 @@ class TestHealthCheckManagementCommands(WgerTestCase):
|
||||
self.assertNotIn('-> deleted', self.out.getvalue())
|
||||
|
||||
def test_fix_no_english_translation(self):
|
||||
Exercise.objects.get(pk=1).delete()
|
||||
Translation.objects.get(pk=1).delete()
|
||||
|
||||
call_command('exercises-health-check', '--delete-no-english', stdout=self.out)
|
||||
self.assertIn('-> deleted', self.out.getvalue())
|
||||
self.assertRaises(ExerciseBase.DoesNotExist, ExerciseBase.objects.get, pk=1)
|
||||
|
||||
def test_find_duplicate_translations(self):
|
||||
exercise = Exercise.objects.get(pk=1)
|
||||
exercise = Translation.objects.get(pk=1)
|
||||
exercise.language_id = 3
|
||||
exercise.save()
|
||||
|
||||
@@ -125,10 +125,10 @@ class TestHealthCheckManagementCommands(WgerTestCase):
|
||||
self.assertNotIn('-> deleted', self.out.getvalue())
|
||||
|
||||
def test_fix_duplicate_translations(self):
|
||||
exercise = Exercise.objects.get(pk=1)
|
||||
exercise = Translation.objects.get(pk=1)
|
||||
exercise.language_id = 3
|
||||
exercise.save()
|
||||
|
||||
call_command('exercises-health-check', '--delete-duplicate-translations', stdout=self.out)
|
||||
self.assertIn('Deleting all but first fr translation', self.out.getvalue())
|
||||
self.assertRaises(Exercise.DoesNotExist, Exercise.objects.get, pk=5)
|
||||
self.assertRaises(Translation.DoesNotExist, Translation.objects.get, pk=5)
|
||||
@@ -23,7 +23,7 @@ from wger.core.models import (
|
||||
from wger.core.tests.base_testcase import WgerTestCase
|
||||
from wger.exercises.models import (
|
||||
Equipment,
|
||||
Exercise,
|
||||
Translation,
|
||||
ExerciseBase,
|
||||
ExerciseCategory,
|
||||
Muscle,
|
||||
@@ -648,7 +648,7 @@ class TestSyncMethods(WgerTestCase):
|
||||
@patch('requests.get', return_value=MockDeletionLogResponse())
|
||||
def test_deletion_log(self, mock_request):
|
||||
self.assertEqual(ExerciseBase.objects.count(), 8)
|
||||
self.assertEqual(Exercise.objects.count(), 11)
|
||||
self.assertEqual(Translation.objects.count(), 11)
|
||||
|
||||
exercise1 = ExerciseBase.objects.get(pk=1)
|
||||
exercise2 = ExerciseBase.objects.get(pk=4)
|
||||
@@ -665,8 +665,8 @@ class TestSyncMethods(WgerTestCase):
|
||||
headers=wger_headers(),
|
||||
)
|
||||
self.assertEqual(ExerciseBase.objects.count(), 7)
|
||||
self.assertEqual(Exercise.objects.count(), 8)
|
||||
self.assertRaises(Exercise.DoesNotExist, Exercise.objects.get, pk=3)
|
||||
self.assertEqual(Translation.objects.count(), 8)
|
||||
self.assertRaises(Translation.DoesNotExist, Translation.objects.get, pk=3)
|
||||
self.assertRaises(ExerciseBase.DoesNotExist, ExerciseBase.objects.get, pk=1)
|
||||
|
||||
# Workouts and logs have been moved
|
||||
@@ -678,7 +678,7 @@ class TestSyncMethods(WgerTestCase):
|
||||
@patch('requests.get', return_value=MockExerciseResponse())
|
||||
def test_exercise_sync(self, mock_request):
|
||||
self.assertEqual(ExerciseBase.objects.count(), 8)
|
||||
self.assertEqual(Exercise.objects.count(), 11)
|
||||
self.assertEqual(Translation.objects.count(), 11)
|
||||
exercise = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')
|
||||
self.assertEqual(exercise.category_id, 2)
|
||||
|
||||
@@ -689,7 +689,7 @@ class TestSyncMethods(WgerTestCase):
|
||||
headers=wger_headers(),
|
||||
)
|
||||
self.assertEqual(ExerciseBase.objects.count(), 9)
|
||||
self.assertEqual(Exercise.objects.count(), 14)
|
||||
self.assertEqual(Translation.objects.count(), 14)
|
||||
|
||||
# New exercise was created
|
||||
new_exercise = ExerciseBase.objects.get(uuid='1b020b3a-3732-4c7e-92fd-a0cec90ed69b')
|
||||
|
||||
@@ -33,14 +33,12 @@ from django.utils.translation import (
|
||||
)
|
||||
from django.views.generic import (
|
||||
DeleteView,
|
||||
TemplateView,
|
||||
)
|
||||
|
||||
# wger
|
||||
from wger.exercises.models import Exercise
|
||||
from wger.exercises.models import Translation
|
||||
from wger.utils.generic_views import WgerDeleteMixin
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -48,7 +46,7 @@ def view(request, id, slug=None):
|
||||
"""
|
||||
Detail view for an exercise translation
|
||||
"""
|
||||
exercise = get_object_or_404(Exercise, pk=id)
|
||||
exercise = get_object_or_404(Translation, pk=id)
|
||||
|
||||
return HttpResponsePermanentRedirect(
|
||||
reverse(
|
||||
@@ -67,7 +65,7 @@ class ExerciseDeleteView(
|
||||
Generic view to delete an existing exercise
|
||||
"""
|
||||
|
||||
model = Exercise
|
||||
model = Translation
|
||||
success_url = reverse_lazy('exercise:exercise:overview')
|
||||
delete_message_extra = gettext_lazy('This will delete the exercise from all workouts.')
|
||||
messages = gettext_lazy('Successfully deleted')
|
||||
|
||||
Reference in new issue
Block a user