From ff2cc8b657e480d0953dfaf9875c399f16c160a9 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Wed, 27 Sep 2023 05:24:58 -0700 Subject: [PATCH 1/5] remove reliance on alerce page return --- tom_alerts/brokers/alerce.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tom_alerts/brokers/alerce.py b/tom_alerts/brokers/alerce.py index c498a2ab7..c03024054 100644 --- a/tom_alerts/brokers/alerce.py +++ b/tom_alerts/brokers/alerce.py @@ -308,7 +308,7 @@ def _clean_parameters(self, parameters): def _request_alerts(self, parameters): payload = self._clean_parameters(parameters) logger.log(msg=f'Fetching alerts from ALeRCE with payload {payload}', level=logging.INFO) - args = urlencode(self._clean_parameters(parameters)) + args = urlencode(payload) response = requests.get(f'{ALERCE_SEARCH_URL}/objects/?count=false&{args}') response.raise_for_status() return response.json() @@ -317,8 +317,8 @@ def fetch_alerts(self, parameters): response = self._request_alerts(parameters) alerts = response['items'] broker_feedback = '' - if len(alerts) > 0 and response['page'] < parameters.get('max_pages', 1): - parameters['page'] = response.get('page') + 1 + if len(alerts) > 0 and parameters.get('page', 1) < parameters.get('max_pages', 1): + parameters['page'] = parameters.get('page', 1) + 1 alerts += self.fetch_alerts(parameters)[0] return iter(alerts), broker_feedback From 54596ffbbb3626288dfafd51baf596dfc983763b Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Thu, 28 Sep 2023 08:23:05 -0700 Subject: [PATCH 2/5] edit setup prompt --- tom_setup/management/commands/tom_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tom_setup/management/commands/tom_setup.py b/tom_setup/management/commands/tom_setup.py index 715e2787e..2b7ccb687 100644 --- a/tom_setup/management/commands/tom_setup.py +++ b/tom_setup/management/commands/tom_setup.py @@ -88,7 +88,7 @@ def get_target_type(self): '2': 'NON_SIDEREAL' } options_str = ['{}) {}'.format(key, target_type) for key, target_type in allowed_types.items()] - prompt = 'Which target type will your project use? {} '.format(self.style.WARNING(", ".join(options_str))) + prompt = 'Which target type should be used as default? {} '.format(self.style.WARNING(", ".join(options_str))) target_type = input(prompt) try: self.context['TARGET_TYPE'] = allowed_types[target_type] From 005da25c80dbeca5f0a9b22677ba4651df9d4f06 Mon Sep 17 00:00:00 2001 From: Dan Avner Date: Mon, 2 Oct 2023 11:52:50 -0700 Subject: [PATCH 3/5] fix - Correct delete view for DataProduct. --- tom_dataproducts/views.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tom_dataproducts/views.py b/tom_dataproducts/views.py index 73cb920a8..233437278 100644 --- a/tom_dataproducts/views.py +++ b/tom_dataproducts/views.py @@ -190,17 +190,30 @@ def get_success_url(self): referer = urlparse(referer).path if referer else '/' return referer - def delete(self, request, *args, **kwargs): + def form_valid(self, form): """ - Method that handles DELETE requests for this view. First deletes all ``ReducedDatum`` objects associated with - the ``DataProduct``, then deletes the ``DataProduct``. + Method that handles DELETE requests for this view. It performs the following actions in order: + 1. Deletes all ``ReducedDatum`` objects associated with the ``DataProduct``. + 2. Deletes the file referenced by the ``DataProduct``. + 3. Deletes the ``DataProduct`` object from the database. - :param request: Django POST request object - :type request: HttpRequest + :param form: Django form instance containing the data for the DELETE request. + :type form: django.forms.Form + :return: HttpResponseRedirect to the success URL. + :rtype: HttpResponseRedirect """ - ReducedDatum.objects.filter(data_product=self.get_object()).delete() - self.get_object().data.delete() - return super().delete(request, *args, **kwargs) + # Fetch the DataProduct object + data_product = self.get_object() + + # Delete associated ReducedDatum objects + ReducedDatum.objects.filter(data_product=data_product).delete() + + # Delete the file reference. + data_product.data.delete() + # Delete the `DataProduct` object from the database. + data_product.delete() + + return HttpResponseRedirect(self.get_success_url()) def get_context_data(self, *args, **kwargs): """ From 19fd373a6833021fef41f29bc7dd3e8f7e6e8bf6 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Tue, 3 Oct 2023 16:18:48 -0700 Subject: [PATCH 4/5] add some comments and documentation --- tom_alerts/brokers/alerce.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tom_alerts/brokers/alerce.py b/tom_alerts/brokers/alerce.py index c03024054..2541bfc5a 100644 --- a/tom_alerts/brokers/alerce.py +++ b/tom_alerts/brokers/alerce.py @@ -314,12 +314,19 @@ def _request_alerts(self, parameters): return response.json() def fetch_alerts(self, parameters): + """ + Loop through pages of ALeRCE alerts until we reach the maximum pages requested. + This simply concatenates all alerts from n pages into a single iterable to be returned. + """ response = self._request_alerts(parameters) alerts = response['items'] broker_feedback = '' - if len(alerts) > 0 and parameters.get('page', 1) < parameters.get('max_pages', 1): - parameters['page'] = parameters.get('page', 1) + 1 + current_page = parameters.get('page', 1) + if len(alerts) > 0 and current_page < parameters.get('max_pages', 1): + # make new request for the next page. (by recursion) + parameters['page'] = current_page + 1 alerts += self.fetch_alerts(parameters)[0] + # Bottom out of recursion and return accumulated alerts return iter(alerts), broker_feedback def fetch_alert(self, id): From d115280cdbad4b4c4f960a5e37fcfeab4d7b7434 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain <32683393+jchate6@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:29:41 -0700 Subject: [PATCH 5/5] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 747cee3d7..c0e8b009e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,5 +9,5 @@ updates: open-pull-requests-limit: 10 target-branch: dev reviewers: - - dmcollom + - jchate6 - phycodurus