Repository: wger-project/wger

Issue:
Feature Request: remove or edit weight entry
- [ ] Remove or edit weight entry



Discussion:
Yes! I'm not even sure if this is already possible via the API, but the entries need to be deletable via the website as well
- [ ] Add appropriate delete/edit views (and tests, but this is mostly copy&paste)
- [ ] Add dropdowns to the weight list in the overview page with the two options

Resolving patch:
diff --git a/wger/weight/urls.py b/wger/weight/urls.py
--- a/wger/weight/urls.py
+++ b/wger/weight/urls.py
@@ -33,6 +33,10 @@
         login_required(views.WeightUpdateView.as_view()),
         name='edit'),
 
+    url(r'^(?P<pk>\d+)/delete/$',
+        views.WeightDeleteView.as_view(),
+        name='delete'),
+
     url(r'^export-csv/$',
         views.export_csv,
         name='export-csv'),
diff --git a/wger/weight/views.py b/wger/weight/views.py
--- a/wger/weight/views.py
+++ b/wger/weight/views.py
@@ -21,6 +21,7 @@
 
 # Django
 from django.contrib.auth.decorators import login_required
+from django.contrib.auth.mixins import LoginRequiredMixin
 from django.db.models import (
     Max,
     Min
@@ -37,7 +38,8 @@
 )
 from django.views.generic import (
     CreateView,
-    UpdateView
+    UpdateView,
+    DeleteView
 )
 
 # Third Party
@@ -46,7 +48,10 @@
 from rest_framework.response import Response
 
 # wger
-from wger.utils.generic_views import WgerFormMixin
+from wger.utils.generic_views import (
+    WgerFormMixin,
+    WgerDeleteMixin
+)
 from wger.utils.helpers import check_access
 from wger.weight import helpers
 from wger.weight.forms import WeightForm
@@ -88,7 +93,7 @@ def get_success_url(self):
         return reverse('weight:overview', kwargs={'username': self.object.user.username})
 
 
-class WeightUpdateView(WgerFormMixin, UpdateView):
+class WeightUpdateView(WgerFormMixin, LoginRequiredMixin, UpdateView):
     """
     Generic view to edit an existing weight entry
     """
@@ -108,6 +113,28 @@ def get_success_url(self):
         return reverse('weight:overview', kwargs={'username': self.object.user.username})
 
 
+class WeightDeleteView(WgerDeleteMixin, LoginRequiredMixin, DeleteView):
+    """
+    Generic view to delete a weight entry
+    """
+
+    model = WeightEntry
+    fields = ('weight',)
+
+    messages = ugettext_lazy('Successfully deleted.')
+
+    def get_context_data(self, **kwargs):
+        context = super(WeightDeleteView, self).get_context_data(**kwargs)
+        context['title'] = _('Delete weight entry for the %s') % self.object.date
+        return context
+
+    def get_success_url(self):
+        """
+        Return to overview with username
+        """
+        return reverse('weight:overview', kwargs={'username': self.object.user.username})
+
+
 @login_required
 def export_csv(request):
     """


Test patch:
diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.py
--- a/wger/weight/tests/test_entry.py
+++ b/wger/weight/tests/test_entry.py
@@ -24,7 +24,8 @@
 from wger.core.tests.base_testcase import (
     WgerAddTestCase,
     WgerEditTestCase,
-    WgerTestCase
+    WgerTestCase,
+    WgerDeleteTestCase
 )
 from wger.utils.constants import TWOPLACES
 from wger.weight.models import WeightEntry
@@ -112,6 +113,18 @@ class EditWeightEntryTestCase(WgerEditTestCase):
     user_fail = 'admin'
 
 
+class DeleteWeightEntryTestCase(WgerDeleteTestCase):
+    """
+    Tests deleting a weight entry
+    """
+
+    object_class = WeightEntry
+    url = 'weight:delete'
+    pk = 1
+    user_success = 'test'
+    user_fail = 'admin'
+
+
 class WeightEntryTestCase(api_base_test.ApiBaseResourceTestCase):
     """
     Tests the weight entry overview resource