Repository: OpenEnergyPlatform/oeplatform

Issue:
toep: model factsheets have no "delete" button 
## Description of the issue

There is no delete button for model factsheets
## Ideas of solution

Add a delete button next to edit button

fyi @wingechr 

## Workflow checklist
- [ ] I am aware of the workflow in [CONTRIBUTING.md](https://github.com/OpenEnergyPlatform/oeplatform/blob/develop/CONTRIBUTING.md)



Discussion:
I will work on this. Since this has not been implemented before, the issue is now duplicated https://github.com/OpenEnergyPlatform/oeplatform/issues/1416 . I understand why you created this issue explicitly for the toep, but it only makes sense if it was implemented before, so there would be a difference between oep and toep.

I'll have to figure out a better workflow for when to create an issue explicitly for the toep and when not. 

FYI: We also decided yesterday that we won't have releases on Fridays anymore, so the release will be on Monday :) Will also write an E-Mail.

Resolving patch:
diff --git a/modelview/urls.py b/modelview/urls.py
--- a/modelview/urls.py
+++ b/modelview/urls.py
@@ -1,30 +1,60 @@
 from django.conf.urls import url
+from django.urls import path
 
 from modelview import views
 
+# urlpatterns = [
+#     path(r"^(?P<sheettype>[\w\d_]+)s/$", views.listsheets, {}, name="modellist"),
+#     url(
+#         r"^(?P<sheettype>[\w\d_]+)s/add/$",
+#         views.FSAdd.as_view(),
+#         {"method": "add"},
+#         name="modeladd",
+#     ),
+#     url(
+#         r"delete/<str:sheettype>/<int:pk>/",
+#         views.FSDelete.as_view(),
+#         name="delete_model",
+#     ),
+#     url(r"^(?P<sheettype>[\w\d_]+)s/download/$", views.model_to_csv, {}, name="index"),
+#     url(
+#         r"^(?P<sheettype>[\w\d_]+)s/(?P<model_name>[\d]+)/$",
+#         views.show,
+#         {},
+#         name="index",
+#     ),
+#     url(
+#         r"^(?P<sheettype>[\w\d_]+)s/(?P<model_name>[\d]+)/edit/$",
+#         views.editModel,
+#         {},
+#         name="index",
+#     ),
+#     url(
+#         r"^(?P<sheettype>[\w\d_]+)s/(?P<pk>[\d]+)/update/$",
+#         views.FSAdd.as_view(),
+#         {"method": "update"},
+#         name="index",
+#     ),
+# ]
+
 urlpatterns = [
-    url(r"^(?P<sheettype>[\w\d_]+)s/$", views.listsheets, {}, name="modellist"),
-    url(
-        r"^(?P<sheettype>[\w\d_]+)s/add/$",
+    path("<str:sheettype>s/", views.listsheets, name="modellist"),
+    path(
+        "<str:sheettype>s/add/",
         views.FSAdd.as_view(),
         {"method": "add"},
-        name="modellist",
-    ),
-    url(r"^(?P<sheettype>[\w\d_]+)s/download/$", views.model_to_csv, {}, name="index"),
-    url(
-        r"^(?P<sheettype>[\w\d_]+)s/(?P<model_name>[\d]+)/$",
-        views.show,
-        {},
-        name="index",
+        name="modeladd",
     ),
-    url(
-        r"^(?P<sheettype>[\w\d_]+)s/(?P<model_name>[\d]+)/edit/$",
-        views.editModel,
-        {},
-        name="index",
+    path(
+        "<str:sheettype>s/delete/<int:pk>/",
+        views.fs_delete,
+        name="delete_factsheet",
     ),
-    url(
-        r"^(?P<sheettype>[\w\d_]+)s/(?P<pk>[\d]+)/update/$",
+    path("<str:sheettype>s/download/", views.model_to_csv, name="index"),
+    path("<str:sheettype>s/<int:model_name>/", views.show, name="index"),
+    path("<str:sheettype>s/<int:model_name>/edit/", views.editModel, name="index"),
+    path(
+        "<str:sheettype>s/<int:pk>/update/",
         views.FSAdd.as_view(),
         {"method": "update"},
         name="index",
diff --git a/modelview/views.py b/modelview/views.py
--- a/modelview/views.py
+++ b/modelview/views.py
@@ -24,6 +24,9 @@
 from api.actions import _get_engine
 from dataedit.structures import Tag
 
+from django.views.decorators.http import require_http_methods
+from django.urls import reverse
+
 from .forms import (
     EnergyframeworkForm,
     EnergymodelForm,
@@ -319,6 +322,21 @@ def post(self, request, sheettype, method="add", pk=None):
             )
 
 
+@require_http_methods(["DELETE"])
+@login_required
+def fs_delete(request, sheettype, pk):
+    c, _ = getClasses(sheettype)
+    model = get_object_or_404(c, pk=pk)
+    model.delete()
+
+    response_data = {"success": True, "message": "Entry deleted successfully."}
+
+    response = HttpResponse(response_data)
+    url = reverse("modellist", kwargs={"sheettype": sheettype})
+    response["HX-Redirect"] = url
+    return response
+
+
 def _handle_github_contributions(org, repo, timedelta=3600, weeks_back=8):
     """
     This function returns the url of an image of recent GitHub contributions


Test patch: