Self hosted FLOSS fitness/workout, nutrition and weight tracker
use data field to store history id
Tom Bowyer5b4159ab47fb
diff --git a/wger/exercises/api/views.py b/wger/exercises/api/views.pyindex adfc65a6c..293d090bf 100644--- a/wger/exercises/api/views.py+++ b/wger/exercises/api/views.py@@ -145,10 +145,18 @@ class ExerciseTranslationViewSet(CreateUpdateModelViewSet):Save entry to activity stream"""super().perform_create(serializer)++ obj_id = self.kwargs['pk']+ updated_object = Exercise.objects.get(id=obj_id)+ most_recent_history = updated_object.history.order_by('history_date').last()+actstream_action.send(self.request.user,verb=StreamVerbs.UPDATED.value,action_object=serializer.instance,+ data={+ 'history_id': most_recent_history.history_id,+ })diff --git a/wger/exercises/views/history.py b/wger/exercises/views/history.pyindex eed9dfb19..83edc930f 100644--- a/wger/exercises/views/history.py+++ b/wger/exercises/views/history.py@@ -68,46 +68,22 @@ def control(request):"""Admin view of the history of the exercises"""- objectContentTypeID = ContentType.objects.get_for_model(Exercise).id+ object_content_type_ID = ContentType.objects.get_for_model(Exercise).id- history = []- for entry in Exercise.history.all():- stream = fetch_exercise_stream_for_object_id_content_type_id_and_timestamp(- entry.id,- objectContentTypeID,- entry.history_date- )- if entry.prev_record:- history.append({- 'record': entry,- 'delta': entry.diff_against(entry.prev_record),- 'stream': stream- })- else:- history.append({- 'record': entry,- 'delta': None,- 'stream': stream- })-- print(history)-- return render(request, 'history/list3.html', {- 'history': history,- })--def fetch_exercise_stream_for_object_id_content_type_id_and_timestamp(- object_id,- content_type_id,- timestamp-):- end_range = timestamp + timedelta(seconds=0.5)stream = Action.objects.filter(- action_object_object_id=object_id,- action_object_content_type_id=content_type_id,- timestamp__range=(timestamp, end_range)+ action_object_content_type_id=object_content_type_ID,)- if len(stream) >= 1:- return stream[0]- return None+ out = []+ for entry in stream:+ # Fetch history+ hist_id = entry.data['data']['history_id']+ hist = Exercise.history.filter(history_id=hist_id)+ out.append({+ 'history': hist,+ 'stream': entry+ })++ return render(request, 'history/list3.html', {+ 'history': out,+ })