From 489c91560ec8522bff724acc90c2544fa2829a4c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 12 Mar 2024 11:46:44 +0100 Subject: [PATCH 1/3] add view for delete file_datas register --- idhub/admin/views.py | 13 +++++++++++++ idhub/urls.py | 2 ++ 2 files changed, 15 insertions(+) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index a030f99..aed49ba 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -1078,3 +1078,16 @@ class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView): messages.error(self.request, e.message) return super().form_valid(form) + + +class ImportDeleteView(AdminView): + model = PeopleView + + def get(self, request, *args, **kwargs): + self.check_valid_user() + self.pk = kwargs['pk'] + self.object = get_object_or_404(self.model, pk=self.pk) + self.object.delete() + + return redirect('idhub:admin_import') + diff --git a/idhub/urls.py b/idhub/urls.py index d0230c9..cbcadcd 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -176,6 +176,8 @@ urlpatterns = [ name='admin_terms_and_conditions'), path('admin/import/new', views_admin.ImportAddView.as_view(), name='admin_import_add'), + path('admin/import//del', views_admin.ImportDeleteView.as_view(), + name='admin_import_del'), path('admin/enc/', views_admin.EncryptionKeyView.as_view(), name='encryption_key'), path('admin/auth/', views_admin.DobleFactorAuthView.as_view(), name='admin_2fauth'), From 8a1871a7b3a2472c661ddb9ce037a614cb48742f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 12 Mar 2024 18:37:01 +0100 Subject: [PATCH 2/3] delete file datas --- idhub/admin/tables.py | 9 ++++++++- idhub/admin/views.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 51df7e8..6e6b273 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -211,11 +211,18 @@ class DIDTable(tables.Table): class DataTable(tables.Table): created_at = tables.Column(verbose_name="Date") file_name = tables.Column(verbose_name="File") + delete_template_code = """""" + delete_data = tables.TemplateColumn(template_code=delete_template_code, + orderable=False, + verbose_name="Delete") class Meta: model = File_datas template_name = "idhub/custom_table.html" - fields = ("created_at", "file_name", "success") + fields = ("created_at", "file_name", "success", "delete_data") class TemplateTable(tables.Table): diff --git a/idhub/admin/views.py b/idhub/admin/views.py index aed49ba..e8e4876 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -1080,8 +1080,8 @@ class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView): return super().form_valid(form) -class ImportDeleteView(AdminView): - model = PeopleView +class ImportDeleteView(AdminView, DeleteView): + model = File_datas def get(self, request, *args, **kwargs): self.check_valid_user() From f30a45af0556db5e0bd30cc228d2ba20da83c722 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 13 Mar 2024 10:02:44 +0100 Subject: [PATCH 3/3] test detele one file of import data --- idhub/tests/test_credentials.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/idhub/tests/test_credentials.py b/idhub/tests/test_credentials.py index c5e6ead..ac95977 100644 --- a/idhub/tests/test_credentials.py +++ b/idhub/tests/test_credentials.py @@ -239,3 +239,13 @@ class CredentialsViewTest(TestCase): def test_user_require_credential(self): for p in PILOTS: self._user_require_credentail(p) + + def test_remove_file_data(self): + p = PILOTS[0] + self.admin_login() + self._upload_data_membership(p) + url = reverse('idhub:admin_import_del', args=[1]) + response = self.client.get(url) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, reverse('idhub:admin_import')) +