Skip to content

Commit

Permalink
added delete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Oct 11, 2024
1 parent 4116ab7 commit d73fdb8
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
90 changes: 90 additions & 0 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PersonPlace(AbstractRelation):

Expand Down Expand Up @@ -410,6 +416,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PersonInstitution(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -449,6 +461,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PersonEvent(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -488,6 +506,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PersonWork(AbstractRelation):

Expand Down Expand Up @@ -528,6 +552,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


#######################################################################
#
Expand Down Expand Up @@ -574,6 +604,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class InstitutionPlace(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -613,6 +649,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class InstitutionEvent(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -652,6 +694,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class InstitutionWork(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -691,6 +739,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


#######################################################################
#
Expand Down Expand Up @@ -733,6 +787,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PlaceEvent(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -772,6 +832,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class PlaceWork(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -811,6 +877,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


#######################################################################
#
Expand Down Expand Up @@ -857,6 +929,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


class EventWork(AbstractRelation):
@classmethod
Expand Down Expand Up @@ -896,6 +974,12 @@ def get_copy_url(self):
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)


#######################################################################
#
Expand Down Expand Up @@ -941,3 +1025,9 @@ def get_copy_url(self):
"apis:apis_relations:copy_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)

def get_delete_url(self):
return reverse_lazy(
"apis:apis_relations:generic_delete_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)
7 changes: 6 additions & 1 deletion apis_core/apis_relations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
from . import event_event_relation_views
from . import event_work_relation_views
from . import work_work_relation_views
from .views import copy_relation
from .views import copy_relation, GenericRelationDeleteView


app_name = "apis_relations"

urlpatterns = [
path(
"delete/<relation_class>/<int:pk>",
GenericRelationDeleteView.as_view(),
name="generic_delete_relation",
),
path(
"copy/<relation_class>/<int:pk>",
copy_relation,
Expand Down
4 changes: 3 additions & 1 deletion apis_core/apis_relations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class MyTable(tables.Table):
<a href="{{ record.get_copy_url }}">
<i class="bi bi-clipboard p-1 fs-5"></i>
</a>
<i class="bi bi-trash p-1 fs-5"></i>
<a href="{{ record.get_delete_url }}">
<i class="bi bi-trash p-1 fs-5"></i>
</a>
""",
verbose_name="Ändern, Kopieren oder Löschen",
orderable=False,
Expand Down
22 changes: 22 additions & 0 deletions apis_core/apis_relations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import re

from django.apps import apps

from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.template import loader
from django.views.generic.edit import DeleteView


from apis_core.apis_entities.models import (
AbstractEntity,
Expand Down Expand Up @@ -53,6 +56,25 @@ def copy_relation(request, relation_class, pk):
return redirect(original_object.get_edit_url())


class GenericRelationDeleteView(DeleteView):
template_name = "apis_entities/confirm_delete.html"

def get_model(self):
model_name = self.kwargs.get("relation_class")
model = apps.get_model(app_label="apis_relations", model_name=model_name)
return model

def get_object(self):
model = self.get_model()
obj = get_object_or_404(model, pk=self.kwargs["pk"])
return obj

def get_success_url(self):
obj = self.get_object()
url = obj.get_listview_url()
return url


def turn_form_modules_into_dict(form_module_list):
"""
Since form classes are loaded dynamically from the respective modules and it's settings-dependent which modules
Expand Down

0 comments on commit d73fdb8

Please sign in to comment.