Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove image views and logic

Roland Geidera3d56f222838
diff --git a/wger/exercises/templates/exercise/view.html b/wger/exercises/templates/exercise/view.html
index 573918c76..8f3ffc40b 100644
--- a/wger/exercises/templates/exercise/view.html
+++ b/wger/exercises/templates/exercise/view.html
@@ -73,14 +73,7 @@ $(document).ready(function() {
<img class="card-img-top" src="{{ image.image|thumbnail_url:'large' }}" alt="">
</a>
<div class="card-body text-center">
- {% if perms.exercises.change_exerciseimage %}
- <a href="{% url 'exercise:image:delete' exercise.pk image.pk %}" class="wger-modal-dialog btn btn-link">
- <span class="{% fa_class 'trash' %}"></span>
- </a>
- <a href="{% url 'exercise:image:edit' image.pk %}" class="btn btn-link">
- <span class="{% fa_class 'edit' %}"></span>
- </a>
- {% endif %}
+
{% if image.is_main %}
<p class="card-text text-wger-green">
@@ -99,16 +92,7 @@ $(document).ready(function() {
{% endfor %}
{% endwith %}
</div>
-
-
{% endif %}
- {% if perms.exercises.change_exerciseimage or perms.exercises.add_exerciseimage or user.userprofile.is_trustworthy %}
- <p>
- <a href="{% url 'exercise:image:add' exercise.id %}" >
- {% translate "Add new image" %}
- </a>
- </p>
- {% endif %}
{% endwith %}
@@ -121,7 +105,7 @@ $(document).ready(function() {
<div class="col mb-4">
<div class="card h-100">
<video controls preload="metadata" class="card-img-top">
- <source src='{{ MEDIA_URL }}{{ video.video }}' type='video/mp4'>
+ <source src='{{ MEDIA_URL }}{{ video.video }}'>
Your browser does not support the video tag.
</video>
<div class="card-body text-center">
diff --git a/wger/exercises/tests/test_exercise_images.py b/wger/exercises/tests/test_exercise_images.py
index 2394d5f87..7bebd59d8 100644
--- a/wger/exercises/tests/test_exercise_images.py
+++ b/wger/exercises/tests/test_exercise_images.py
@@ -105,43 +105,6 @@ class MainImageTestCase(WgerTestCase):
self.assertFalse(ExerciseImage.objects.get(pk=pk5).is_main)
-class AddExerciseImageTestCase(WgerAddTestCase):
- """
- Tests adding an image to an exercise
- """
-
- object_class = ExerciseImage
- url = reverse('exercise:image:add', kwargs={'exercise_pk': 1})
- user_fail = False
- data = {
- 'is_main': True,
- 'image': open('wger/exercises/tests/protestschwein.jpg', 'rb'),
- 'license': 1,
- 'style': '1'
- }
-
-
-class EditExerciseImageTestCase(WgerEditTestCase):
- """
- Tests editing an image to an exercise
- """
-
- object_class = ExerciseImage
- url = 'exercise:image:edit'
- pk = 2
- data = {'is_main': True, 'license': 1, 'style': '1'}
-
-
-class DeleteExerciseImageTestCase(WgerDeleteTestCase):
- """
- Tests deleting an image to an exercise
- """
-
- object_class = ExerciseImage
- url = reverse('exercise:image:delete', kwargs={'exercise_pk': 1, 'pk': 1})
- pk = 1
-
-
# TODO: add POST and DELETE tests
class ExerciseImagesApiTestCase(
api_base_test.BaseTestCase,
diff --git a/wger/exercises/tests/test_submitted_image.py b/wger/exercises/tests/test_submitted_image.py
deleted file mode 100644
index 1602eeeaa..000000000
--- a/wger/exercises/tests/test_submitted_image.py
+++ /dev/null
@@ -1,161 +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.exercises.models import ExerciseImage
-
-
-class ImagePendingDetailTestCase(WgerTestCase):
- """
- Tests the detail page of an exercise with a pending image
- """
-
- def pending_view(self, fail=False):
- """
- Helper function
- """
- response = self.client.get(reverse('exercise:exercise:view', kwargs={'id': 2}))
- self.assertEqual(response.status_code, 200)
-
- if not fail:
- self.assertContains(response, 'Images pending review')
- self.assertContains(response, 'Accept')
- self.assertContains(response, 'Decline')
- else:
- self.assertNotContains(response, 'Images pending review')
- self.assertNotContains(response, 'Accept')
- self.assertNotContains(response, 'Decline')
-
- def test_pending_view_admin(self):
- """
- Tests the detail page of an exercise with a pending image as an admin user
- """
-
- self.user_login('admin')
- self.pending_view()
-
- def test_pending_view_user(self):
- """
- Tests the detail page of an exercise with a pending image 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 an exercise with a pending image as a logged out user
- """
-
- self.pending_view(fail=True)
-
-
-class ImageAcceptTestCase(WgerTestCase):
- """
- Tests accepting a user submitted exercise image
- """
-
- def accept(self, fail=False):
- """
- Helper function
- """
- image = ExerciseImage.objects.get(pk=3)
- self.assertEqual(image.status, ExerciseImage.STATUS_PENDING)
- response = self.client.get(reverse('exercise:image:accept', kwargs={'pk': 3}))
- image = ExerciseImage.objects.get(pk=3)
- self.assertEqual(response.status_code, 302)
-
- if not fail:
- self.assertEqual(image.status, ExerciseImage.STATUS_ACCEPTED)
- response = self.client.get(response['Location'])
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(mail.outbox), 0)
- else:
- self.assertEqual(image.status, ExerciseImage.STATUS_PENDING)
- self.assertEqual(len(mail.outbox), 0)
-
- def test_accept_admin(self):
- """
- Tests accepting a user submitted exercise image as an admin user
- """
-
- self.user_login('admin')
- self.accept()
-
- def test_accept_user(self):
- """
- Tests accepting a user submitted exercise image as a regular user
- """
-
- self.user_login('test')
- self.accept(fail=True)
-
- def test_accept_logged_out(self):
- """
- Tests accepting a user submitted exercise as a logged out user
- """
-
- self.accept(fail=True)
-
-
-class ImageRejectTestCase(WgerTestCase):
- """
- Tests rejecting a user submitted exercise image
- """
-
- def reject(self, fail=False):
- """
- Helper function
- """
- image = ExerciseImage.objects.get(pk=3)
- self.assertEqual(image.status, ExerciseImage.STATUS_PENDING)
- response = self.client.get(reverse('exercise:image:decline', kwargs={'pk': 3}))
- image = ExerciseImage.objects.get(pk=3)
- self.assertEqual(response.status_code, 302)
-
- if not fail:
- self.assertEqual(image.status, ExerciseImage.STATUS_DECLINED)
- response = self.client.get(response['Location'])
- self.assertEqual(response.status_code, 200)
-
- else:
- self.assertEqual(image.status, ExerciseImage.STATUS_PENDING)
-
- def test_reject_admin(self):
- """
- Tests rejecting a user submitted exercise image as an admin user
- """
-
- self.user_login('admin')
- self.reject()
-
- def test_reject_user(self):
- """
- Tests rejecting a user submitted exercise image as a regular user
- """
-
- self.user_login('test')
- self.reject(fail=True)
-
- def test_reject_logged_out(self):
- """
- Tests rejecting a user submitted exercise image as a logged out user
- """
-
- self.reject(fail=True)
diff --git a/wger/exercises/views/images.py b/wger/exercises/views/images.py
deleted file mode 100644
index 3d1a67788..000000000
--- a/wger/exercises/views/images.py
+++ /dev/null
@@ -1,169 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# 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
-
-# Standard Library
-import logging
-
-# Django
-from django.contrib.auth.decorators import permission_required
-from django.contrib.auth.mixins import (
- LoginRequiredMixin,
- PermissionRequiredMixin,
-)
-from django.http import HttpResponseRedirect
-from django.shortcuts import get_object_or_404
-from django.urls import reverse
-from django.utils.translation import (
- gettext as _,
- gettext_lazy,
-)
-from django.views.generic import (
- CreateView,
- DeleteView,
- UpdateView,
-)
-
-# wger
-from wger.exercises.forms import ExerciseImageForm
-from wger.exercises.models import (
- Exercise,
- ExerciseImage,
-)
-from wger.utils.generic_views import (
- WgerDeleteMixin,
- WgerFormMixin,
-)
-
-
-logger = logging.getLogger(__name__)
-"""
-Exercise images
-"""
-
-
-class ExerciseImageEditView(
- WgerFormMixin,
- LoginRequiredMixin,
- PermissionRequiredMixin,
- UpdateView,
-):
- """
- Generic view to update an existing exercise image
- """
-
- model = ExerciseImage
- title = gettext_lazy('Edit exercise image')
- permission_required = 'exercises.change_exerciseimage'
- form_class = ExerciseImageForm
-
- def get_success_url(self):
- return reverse('exercise:exercise:view', kwargs={'id': self.object.exercise_base.id})
-
- # Send some additional data to the template
- def get_context_data(self, **kwargs):
- context = super(ExerciseImageEditView, self).get_context_data(**kwargs)
- context['enctype'] = 'multipart/form-data'
- return context
-
-
-class ExerciseImageAddView(
- WgerFormMixin,
- LoginRequiredMixin,
- PermissionRequiredMixin,
- CreateView,
-):
- """
- Generic view to add a new exercise image
- """
-
- model = ExerciseImage
- title = gettext_lazy('Add new image')
- permission_required = 'exercises.add_exerciseimage'
- form_class = ExerciseImageForm
-
- def form_valid(self, form):
- """Set the exercise base and the author"""
- exercise = get_object_or_404(Exercise, pk=self.kwargs['exercise_pk'])
- form.instance.exercise_base = exercise.exercise_base
- return super(ExerciseImageAddView, self).form_valid(form)
-
- def get_success_url(self):
- return reverse('exercise:exercise:view', kwargs={'id': self.kwargs['exercise_pk']})
-
- def get_context_data(self, **kwargs):
- """
- Send some additional data to the template
- """
- context = super(ExerciseImageAddView, self).get_context_data(**kwargs)
- context['enctype'] = 'multipart/form-data'
- return context
-
-
-class ExerciseImageDeleteView(
- WgerDeleteMixin,
- LoginRequiredMixin,
- PermissionRequiredMixin,
- DeleteView,
-):
- """
- Generic view to delete an existing exercise image
- """
-
- model = ExerciseImage
- fields = ('image', 'is_main')
- messages = gettext_lazy('Successfully deleted')
- permission_required = 'exercises.delete_exerciseimage'
-
- def get_success_url(self):
- """
- Return to exercise image
- """
- return reverse('exercise:exercise:view', kwargs={'id': self.kwargs['exercise_pk']})
-
- def get_context_data(self, **kwargs):
- """
- Send some additional data to the template
- """
- context = super(ExerciseImageDeleteView, self).get_context_data(**kwargs)
-
- context['title'] = _('Delete exercise image?')
- return context
-
-
-@permission_required('exercises.change_exerciseimage')
-def accept(request, pk):
- """
- Accepts a pending user submitted image and emails the user, if possible
- """
- image = get_object_or_404(ExerciseImage, pk=pk)
- image.status = ExerciseImage.STATUS_ACCEPTED
- image.save()
- # image.send_email(request)
-
- return HttpResponseRedirect(reverse('exercise:exercise:overview'))
-
-
-@permission_required('exercises.change_exerciseimage')
-def decline(request, pk):
- """
- Declines and deletes a pending user submitted image
- """
- image = get_object_or_404(ExerciseImage, pk=pk)
- image.status = ExerciseImage.STATUS_DECLINED
- image.save()
- # image.send_email(request)
-
- return HttpResponseRedirect(reverse('exercise:exercise:overview'))