From 74c282a86805f0cc67c2e8f399e53ffd56aa42e4 Mon Sep 17 00:00:00 2001 From: Graham Herceg Date: Mon, 16 Dec 2024 14:52:26 -0500 Subject: [PATCH 1/2] Rename method that deletes item --- corehq/apps/accounting/views.py | 2 +- corehq/apps/data_interfaces/views.py | 6 +++--- corehq/apps/hqwebapp/views.py | 6 +++--- corehq/apps/reminders/views.py | 2 +- corehq/apps/reports/views.py | 2 +- corehq/apps/settings/views.py | 2 +- corehq/apps/sms/views.py | 4 ++-- corehq/apps/userreports/views.py | 2 +- corehq/motech/dhis2/views.py | 4 ++-- corehq/motech/views.py | 2 +- docs/ui_helpers.rst | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/corehq/apps/accounting/views.py b/corehq/apps/accounting/views.py index 70ef7291d005..e80664a242f6 100644 --- a/corehq/apps/accounting/views.py +++ b/corehq/apps/accounting/views.py @@ -1203,7 +1203,7 @@ def get_create_item_data(self, create_form): 'template': 'accounting-admin-new', } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): user = User.objects.get(id=item_id) ops_role = Role.objects.get(slug=privileges.OPERATIONS_TEAM) grant_to_remove = Grant.objects.filter( diff --git a/corehq/apps/data_interfaces/views.py b/corehq/apps/data_interfaces/views.py index 52a19dcb61b9..c7a28e669b4b 100644 --- a/corehq/apps/data_interfaces/views.py +++ b/corehq/apps/data_interfaces/views.py @@ -281,7 +281,7 @@ def get_create_item_data(self, create_form): 'template': 'new-group-template', } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): case_group = CommCareCaseGroup.get(item_id) item_data = self._get_item_data(case_group) case_group.soft_delete() @@ -474,7 +474,7 @@ def get_create_item_data(self, create_form): 'template': 'new-case-template', } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): if not item_id: raise PaginatedItemException("The case's ID was blank.") current_cases = set(self.case_group.cases) @@ -1067,7 +1067,7 @@ def activate_response(self): def deactivate_response(self): return self.update_rule() - def get_deleted_item_data(self, rule_id): + def delete_item(self, rule_id): (rule, error) = self._get_rule(rule_id) if rule is None: return {'success': False, 'error': error} diff --git a/corehq/apps/hqwebapp/views.py b/corehq/apps/hqwebapp/views.py index b3355e332345..05cf0eabbffb 100644 --- a/corehq/apps/hqwebapp/views.py +++ b/corehq/apps/hqwebapp/views.py @@ -1154,7 +1154,7 @@ def refresh_response(self): @property def delete_response(self): try: - response = self.get_deleted_item_data(self.item_id) + response = self.delete_item(self.item_id) return { 'deletedItem': response } @@ -1253,7 +1253,7 @@ def get_updated_item_data(self, update_form): """ raise NotImplementedError("You must implement get_updated_item_data") - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): """ This should return a dict of data for the deleted item. { @@ -1264,7 +1264,7 @@ def get_deleted_item_data(self, item_id): 'template': } """ - raise NotImplementedError("You must implement get_deleted_item_data") + raise NotImplementedError("You must implement delete_item") @login_required diff --git a/corehq/apps/reminders/views.py b/corehq/apps/reminders/views.py index 6584cc3e12a0..291ca0656e1d 100644 --- a/corehq/apps/reminders/views.py +++ b/corehq/apps/reminders/views.py @@ -362,7 +362,7 @@ def _fmt_deleted_keyword_data(self, keyword): 'description': keyword.description, } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): try: k = Keyword.objects.get(couch_id=item_id) except Keyword.DoesNotExist: diff --git a/corehq/apps/reports/views.py b/corehq/apps/reports/views.py index 638941e77aee..4bf7ade4cb7c 100644 --- a/corehq/apps/reports/views.py +++ b/corehq/apps/reports/views.py @@ -1933,7 +1933,7 @@ def _get_item_data(self, tableau_visualization): } return data - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): tableau_viz = TableauVisualization.objects.get( pk=item_id, domain=self.domain, diff --git a/corehq/apps/settings/views.py b/corehq/apps/settings/views.py index 5131e6e232c4..7bb71dacf6a7 100644 --- a/corehq/apps/settings/views.py +++ b/corehq/apps/settings/views.py @@ -793,7 +793,7 @@ def get_create_item_data(self, create_form): 'template': 'new-user-api-key-template', } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): deleted_key = self.base_query.get(id=item_id) deleted_key.delete() return { diff --git a/corehq/apps/sms/views.py b/corehq/apps/sms/views.py index 69fe22c286f1..384e3a70332d 100644 --- a/corehq/apps/sms/views.py +++ b/corehq/apps/sms/views.py @@ -1103,7 +1103,7 @@ def _get_backend_from_item_id(self, item_id): except (BadSMSConfigException, SQLMobileBackend.DoesNotExist, TypeError, ValueError): raise Http404() - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): item_id, backend = self._get_backend_from_item_id(item_id) if backend.is_global or backend.domain != self.domain: @@ -1455,7 +1455,7 @@ def _get_backend_from_item_id(self, item_id): except (BadSMSConfigException, SQLMobileBackend.DoesNotExist, TypeError, ValueError): raise Http404() - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): item_id, backend = self._get_backend_from_item_id(item_id) if not backend.is_global: diff --git a/corehq/apps/userreports/views.py b/corehq/apps/userreports/views.py index 897bbbecff4c..6920ece3c8af 100644 --- a/corehq/apps/userreports/views.py +++ b/corehq/apps/userreports/views.py @@ -1914,7 +1914,7 @@ def get_create_item_data(self, create_form): "template": "base-ucr-statement-template", } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): deleted_expression = self.base_query.get(id=item_id) deleted_expression.delete() return { diff --git a/corehq/motech/dhis2/views.py b/corehq/motech/dhis2/views.py index 8f37ea9f9bbf..46059086df90 100644 --- a/corehq/motech/dhis2/views.py +++ b/corehq/motech/dhis2/views.py @@ -103,7 +103,7 @@ def _get_item_data(self, dataset_map): ), } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): dataset_map = SQLDataSetMap.objects.get(domain=self.domain, pk=item_id) dataset_map.delete() return { @@ -312,7 +312,7 @@ def get_updated_item_data(self, update_form): "template": "datavalue-map-template", } - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): datavalue_map = SQLDataValueMap.objects.get(pk=item_id, dataset_map=self.object) datavalue_map.delete() diff --git a/corehq/motech/views.py b/corehq/motech/views.py index a1fd373042a6..beb7a41ac7a5 100644 --- a/corehq/motech/views.py +++ b/corehq/motech/views.py @@ -241,7 +241,7 @@ def _get_item_data(self, connection_settings): return data - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): connection_settings = ConnectionSettings.objects.get( pk=item_id, domain=self.domain, diff --git a/docs/ui_helpers.rst b/docs/ui_helpers.rst index beba66d7c5a6..ab54195330db 100644 --- a/docs/ui_helpers.rst +++ b/docs/ui_helpers.rst @@ -298,7 +298,7 @@ If you want to delete data with your paginated view, you should implement someth class PuppiesCRUDView(BaseSectionView, CRUDPaginatedMixin): ... - def get_deleted_item_data(self, item_id): + def delete_item(self, item_id): deleted_puppy = Puppy.get(item_id) deleted_puppy.delete() return { From 8eb45273de0fc0e5aa8631da1bdbfaf89efab1c7 Mon Sep 17 00:00:00 2001 From: Graham Herceg Date: Wed, 1 Jan 2025 09:15:36 -0500 Subject: [PATCH 2/2] Raise exception instead of custom dictionary --- corehq/apps/data_interfaces/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/data_interfaces/views.py b/corehq/apps/data_interfaces/views.py index c7a28e669b4b..50ab6b8c4c52 100644 --- a/corehq/apps/data_interfaces/views.py +++ b/corehq/apps/data_interfaces/views.py @@ -1070,7 +1070,7 @@ def deactivate_response(self): def delete_item(self, rule_id): (rule, error) = self._get_rule(rule_id) if rule is None: - return {'success': False, 'error': error} + raise PaginatedItemException(error) rule.soft_delete()