Skip to content

Commit

Permalink
refactor(history): make ChangeHistoryView reuse existing views
Browse files Browse the repository at this point in the history
The DetailView is a TemplateView that inherits from BaseDetailView,
which inherits from SingleObjectMixin and implements a similar `get`
as ChangeHistoryView does. So inheriting from DetailView makes the whole
thing smaller.
  • Loading branch information
b1rger committed Apr 18, 2024
1 parent d0c081b commit 7d08a44
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions apis_core/history/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from apis_core.generic.views import GenericModelMixin
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import TemplateView
from django.contrib.contenttypes.models import ContentType
from datetime import datetime
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.detail import DetailView
from django.utils import timezone


Expand All @@ -25,13 +24,9 @@ def convert_timestamps(data):
return data


class ChangeHistoryView(GenericModelMixin, SingleObjectMixin, TemplateView):
class ChangeHistoryView(GenericModelMixin, DetailView):
template_name = "history/change_history.html"

def get(self, request, *args, **kwargs):
self.object = self.get_object()
return super().get(request, *args, **kwargs)


def create_new_version(request, contenttype, pk):
"""Gets the version of the history instance and creates a new version."""
Expand Down

0 comments on commit 7d08a44

Please sign in to comment.