Skip to content

Commit

Permalink
Now, you can also search for missions
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Oct 11, 2024
1 parent a274ce7 commit 922a646
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
15 changes: 8 additions & 7 deletions georeferencing/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class BatchAdmin(admin.ModelAdmin):
list_display = ('name', 'createdDateTime', 'images_count', 'result')
list_display = ('name', 'createdDateTime', 'numberImages')
list_filter = ('createdDateTime',)
search_fields = ('name',)

Expand All @@ -28,10 +28,16 @@ def get_urls(self):
# Custom view to fetch data from an external API
def fetch_api_data(self, request):
feat_value = request.GET.get('feat', '')
mission = request.GET.get('mission', '')
url = 'https://eol.jsc.nasa.gov/SearchPhotos/PhotosDatabaseAPI/PhotosDatabaseAPI.pl'
query = f'query=frames|feat|like|*{feat_value}*|images|directory|like|*large*'
query = 'query=images|directory|like|*large*'
if feat_value:
query = f'{query}|frames|feat|like|*{feat_value}'
elif mission:
query = f'{query}|frames|mission|like|*{mission}'
key = config('NASA_API_KEY')
urlRequest = f'{url}?{query}&return=frames|geon|frames|feat|images|directory|images|filename|frames|fclt|frames|pdate|frames|ptime|frames|lat|frames|lon&key={key}'
print(urlRequest)


try:
Expand All @@ -55,11 +61,6 @@ def save_model(self, request, obj, form, change):
obj.user = request.user
obj.save()

def images_count(self, obj):
return Image.objects.filter(batch=obj).count()

images_count.short_description = '# Images'


class ImageAdmin(admin.ModelAdmin):
list_display = ('name', 'createdDateTime', 'geoattempts_count')
Expand Down
18 changes: 18 additions & 0 deletions georeferencing/migrations/0026_batch_mission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-10-11 22:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0025_batch_numberimages'),
]

operations = [
migrations.AddField(
model_name='batch',
name='mission',
field=models.CharField(blank=True, max_length=100, null=True),
),
]
3 changes: 3 additions & 0 deletions georeferencing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def __str__(self):
class Batch(models.Model):
name = models.CharField(max_length=100)
createdDateTime = models.DateTimeField(auto_now_add=True)
# Search fields
feat = models.CharField(max_length=100, blank = True, null = True)
mission = models.CharField(max_length=100, blank = True, null = True)

user = models.ForeignKey(User, on_delete=models.CASCADE)
result = models.JSONField(default=dict, blank=True, null=True)
numberImages = models.IntegerField(default=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
$(document).ready(function() {
$('#fetch-data-btn').on('click', function() {
var featValue = $('input[name="feat"]').val();
var requestUrl = '{{ fetch_api_url }}?feat=' + featValue;
var mission = $('input[name="mission"]').val();
var requestUrl = '{{ fetch_api_url }}?feat=' + featValue + '&mission=' + mission;
$.ajax({
url: requestUrl,
method: 'GET',
Expand Down

0 comments on commit 922a646

Please sign in to comment.