-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from ImperialCollegeLondon/edit_view
Adds edit, create and delete views
- Loading branch information
Showing
14 changed files
with
491 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
from django.urls import path | ||
|
||
from .views import DataImportDetailView, DataImportListView | ||
from .views import ( | ||
DataImportCreateView, | ||
DataImportDeleteView, | ||
DataImportDetailView, | ||
DataImportEditView, | ||
DataImportListView, | ||
) | ||
|
||
app_name = "importing" | ||
urlpatterns = [ | ||
path("", DataImportListView.as_view(), name="dataimport_list"), | ||
path("<int:pk>/", DataImportDetailView.as_view(), name="dataimport_detail"), | ||
path("edit/<int:pk>", DataImportEditView.as_view(), name="dataimport_edit"), | ||
path("create/", DataImportCreateView.as_view(), name="dataimport_create"), | ||
path("delete/<int:pk>", DataImportDeleteView.as_view(), name="dataimport_delete"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.contrib.admin.utils import NestedObjects | ||
from django.db import models | ||
from django.utils.encoding import force_str | ||
from django.utils.text import capfirst | ||
|
||
|
||
def get_deleted_objects( | ||
objs: list[models.Model], | ||
) -> tuple[list[str], dict[str, int], list[str]]: | ||
"""Return information about related objects to be deleted. | ||
How to do this has been taken from https://stackoverflow.com/a/39533619/3778792 | ||
Args: | ||
objs (list[models.Model]): List of objects to be deleted. | ||
Returns: | ||
tuple[list[str], dict[str, int], list[str]]: Tuple containing the following: | ||
- List of strings representing the objects to be deleted. | ||
- Dictionary containing the count of objects to be deleted for each model. | ||
- List of strings representing the objects that are protected from deletion | ||
""" | ||
collector = NestedObjects(using="default") | ||
collector.collect(objs) | ||
|
||
def format_callback(obj): | ||
opts = obj._meta | ||
no_edit_link = f"{capfirst(opts.verbose_name)}: {force_str(obj)}" | ||
return no_edit_link | ||
|
||
to_delete = collector.nested(format_callback) | ||
protected = [format_callback(obj) for obj in collector.protected] | ||
model_count = { | ||
model._meta.verbose_name_plural: len(objs) | ||
for model, objs in collector.model_objs.items() | ||
} | ||
if len(to_delete) == 0: | ||
to_delete.append("None") | ||
if len(protected) == 0: | ||
protected.append("None") | ||
return to_delete, model_count, protected |
Oops, something went wrong.