Add ability to export station status in admin
parent
aa3e91fb01
commit
b018ea7947
|
@ -2,7 +2,7 @@ from django.contrib import admin
|
|||
|
||||
from network.base.models import (Antenna, Satellite, Station, Transmitter,
|
||||
Observation, Mode, Tle, DemodData)
|
||||
from network.base.utils import export_as_csv
|
||||
from network.base.utils import export_as_csv, export_station_status
|
||||
|
||||
|
||||
@admin.register(Mode)
|
||||
|
@ -30,8 +30,9 @@ class StationAdmin(admin.ModelAdmin):
|
|||
list_filter = ('status', 'created', 'client_version')
|
||||
search_fields = ('name', 'owner__username')
|
||||
|
||||
actions = [export_as_csv]
|
||||
actions = [export_as_csv, export_station_status]
|
||||
export_as_csv.short_description = "Export selected as CSV"
|
||||
export_station_status.short_description = "Export selected status"
|
||||
|
||||
def created_date(self, obj):
|
||||
return obj.created.strftime('%d.%m.%Y, %H:%M')
|
||||
|
|
|
@ -51,6 +51,21 @@ def export_as_csv(modeladmin, request, queryset):
|
|||
return response
|
||||
|
||||
|
||||
def export_station_status(self, request, queryset):
|
||||
meta = self.model._meta
|
||||
field_names = ["id", "status"]
|
||||
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
|
||||
writer = csv.writer(response)
|
||||
|
||||
writer.writerow(field_names)
|
||||
for obj in queryset:
|
||||
writer.writerow([getattr(obj, field) for field in field_names])
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def demod_to_db(frame_id):
|
||||
"""Task to send a frame from SatNOGS network to SatNOGS db"""
|
||||
frame = DemodData.objects.get(id=frame_id)
|
||||
|
|
Loading…
Reference in New Issue