From 5d2e0f8da2d10a42f1c76419f51ba18522dac734 Mon Sep 17 00:00:00 2001 From: Francisco Sanz Date: Thu, 17 Oct 2024 00:23:26 +0200 Subject: [PATCH] Included focal length in the searh fields of the batch model --- georeferencing/admin.py | 9 +++++++- .../0031_batch_fcltge_batch_fcltlt.py | 23 +++++++++++++++++++ .../0032_rename_fcltlt_batch_fcltle.py | 18 +++++++++++++++ georeferencing/models.py | 3 ++- .../georeferencing/batch/change_form.html | 4 +++- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 georeferencing/migrations/0031_batch_fcltge_batch_fcltlt.py create mode 100644 georeferencing/migrations/0032_rename_fcltlt_batch_fcltle.py diff --git a/georeferencing/admin.py b/georeferencing/admin.py index 4d458df..2c51daf 100644 --- a/georeferencing/admin.py +++ b/georeferencing/admin.py @@ -86,14 +86,21 @@ def fetch_api_data(self, request): Raises: requests.RequestException: If there is an issue with the HTTP request. """ + print(request.GET) feat_value = request.GET.get('feat', '') mission = request.GET.get('mission', '') + fcltle = request.GET.get('fcltle', '') + fcltge = request.GET.get('fcltge', '') url = 'https://eol.jsc.nasa.gov/SearchPhotos/PhotosDatabaseAPI/PhotosDatabaseAPI.pl' query = 'query=images|directory|like|*large*' if feat_value: query = f'{query}|frames|feat|like|*{feat_value}*' - elif mission: + if mission: query = f'{query}|frames|mission|like|*{mission}' + if fcltle: + query = f'{query}|frames|fclt|le|{fcltle}' + if fcltge: + query = f'{query}|frames|fclt|ge|{fcltge}' key = config('NASA_API_KEY') url_request = ( f'{url}?{query}&return=frames|frame|frames|geon|frames|feat|frames|roll|' diff --git a/georeferencing/migrations/0031_batch_fcltge_batch_fcltlt.py b/georeferencing/migrations/0031_batch_fcltge_batch_fcltlt.py new file mode 100644 index 0000000..8e5658f --- /dev/null +++ b/georeferencing/migrations/0031_batch_fcltge_batch_fcltlt.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.16 on 2024-10-16 22:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('georeferencing', '0030_geoattempt_assigneduser'), + ] + + operations = [ + migrations.AddField( + model_name='batch', + name='fcltge', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AddField( + model_name='batch', + name='fcltlt', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/georeferencing/migrations/0032_rename_fcltlt_batch_fcltle.py b/georeferencing/migrations/0032_rename_fcltlt_batch_fcltle.py new file mode 100644 index 0000000..44d17fb --- /dev/null +++ b/georeferencing/migrations/0032_rename_fcltlt_batch_fcltle.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.16 on 2024-10-16 22:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('georeferencing', '0031_batch_fcltge_batch_fcltlt'), + ] + + operations = [ + migrations.RenameField( + model_name='batch', + old_name='fcltlt', + new_name='fcltle', + ), + ] diff --git a/georeferencing/models.py b/georeferencing/models.py index bae312b..ae7eddc 100644 --- a/georeferencing/models.py +++ b/georeferencing/models.py @@ -70,7 +70,8 @@ class Batch(models.Model): # Search fields feat = models.CharField(max_length=100, blank = True, null = True) mission = models.CharField(max_length=100, blank = True, null = True) - + fcltle = models.IntegerField(blank = True, null = True, verbose_name="Focal length <=") + fcltge = models.IntegerField(blank = True, null = True, verbose_name="Focal length >=") user = models.ForeignKey(User, on_delete=models.CASCADE) result = models.JSONField(default=dict, blank=True, null=True) numberImages = models.IntegerField(default=0) diff --git a/georeferencing/templates/admin/georeferencing/batch/change_form.html b/georeferencing/templates/admin/georeferencing/batch/change_form.html index 87e789a..931c701 100644 --- a/georeferencing/templates/admin/georeferencing/batch/change_form.html +++ b/georeferencing/templates/admin/georeferencing/batch/change_form.html @@ -19,7 +19,9 @@ $('#fetch-data-btn').on('click', function () { var featValue = $('input[name="feat"]').val(); var mission = $('input[name="mission"]').val(); - var requestUrl = '{{ fetch_api_url }}?feat=' + featValue + '&mission=' + mission; + var fcltle = $('input[name="fcltle"]').val(); + var fcltge = $('input[name="fcltge"]').val(); + var requestUrl = '{{ fetch_api_url }}?feat=' + featValue + '&mission=' + mission + '&fcltle=' + fcltle + '&fcltge=' + fcltge; $.ajax({ url: requestUrl, method: 'GET',