1
0
Fork 0
satnogs-db/db/base/views.py

593 lines
22 KiB
Python
Raw Normal View History

"""Base django views for SatNOGS DB"""
2015-07-21 12:26:08 -06:00
import logging
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
from datetime import timedelta
2015-07-21 12:26:08 -06:00
from bootstrap_modal_forms.generic import BSModalCreateView, BSModalFormView, BSModalUpdateView
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator
from django.db import OperationalError
from django.db.models import Count, Max, Prefetch, Q
from django.http import HttpResponse, HttpResponseServerError, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils.timezone import now
from django.views.decorators.http import require_POST
2015-04-25 10:47:22 -06:00
from db.base.forms import MergeSatellitesForm, SatelliteCreateForm, SatelliteUpdateForm, \
TransmitterCreateForm, TransmitterUpdateForm
from db.base.helpers import get_api_token
from db.base.models import DemodData, Satellite, SatelliteEntry, SatelliteIdentifier, \
SatelliteSuggestion, Transmitter, TransmitterEntry, TransmitterSuggestion
from db.base.tasks import export_frames, notify_suggestion
from db.base.utils import cache_statistics, millify, read_influx
2017-03-02 10:57:12 -07:00
LOGGER = logging.getLogger('db')
2015-07-21 12:26:08 -06:00
2015-04-22 05:05:30 -06:00
def home(request):
"""View to render home page.
:returns: base/home.html
"""
prefetch_approved = Prefetch(
'transmitter_entries', queryset=Transmitter.objects.all(), to_attr='approved_transmitters'
)
prefetch_suggested = Prefetch(
'transmitter_entries',
queryset=TransmitterSuggestion.objects.all(),
to_attr='suggested_transmitters'
)
newest_sats = Satellite.objects.filter(
associated_satellite__isnull=True
).order_by('-id')[:5].prefetch_related(prefetch_approved, prefetch_suggested)
# Calculate latest contributors
latest_data_satellites = []
found = False
date_from = now() - timedelta(days=1)
data_list = DemodData.objects.filter(timestamp__gte=date_from
).order_by('-pk').select_related('satellite')
paginator = Paginator(data_list, 50)
page = paginator.page(1)
while not found:
for data in page.object_list:
if data.satellite.id not in latest_data_satellites:
latest_data_satellites.append(data.satellite.id)
if len(latest_data_satellites) > 5:
found = True
break
if page.has_next():
page = paginator.page(page.next_page_number())
else:
break
# Check if satellite is merged and if it is then show its associated entry.
latest_data = Satellite.objects.filter(
associated_satellite__isnull=True
).filter(Q(pk__in=latest_data_satellites) | Q(associated_with__pk__in=latest_data_satellites)
).prefetch_related(prefetch_approved, prefetch_suggested)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
# Calculate latest contributors
date_from = now() - timedelta(days=1)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
latest_submitters = DemodData.objects.filter(timestamp__gte=date_from
).values('station').annotate(c=Count('station')
).order_by('-c')
return render(
request, 'base/home.html', {
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
'newest_sats': newest_sats,
'latest_data': latest_data,
'latest_submitters': latest_submitters
}
)
2015-04-25 10:47:22 -06:00
def transmitters_list(request):
"""View to render transmitters list page.
:returns: base/transmitters.html
"""
transmitters = Transmitter.objects.filter(
satellite__associated_satellite__isnull=True, satellite__satellite_entry__approved=True
).exclude(
status='invalid'
).select_related('satellite', 'satellite__satellite_entry', 'satellite__satellite_identifier')
return render(request, 'base/transmitters.html', {'transmitters': transmitters})
2015-07-17 11:56:23 -06:00
def robots(request):
"""robots.txt handler
:returns: robots.txt
"""
2015-07-17 11:56:23 -06:00
data = render(request, 'robots.txt', {'environment': settings.ENVIRONMENT})
response = HttpResponse(data, content_type='text/plain; charset=utf-8')
2015-07-17 11:56:23 -06:00
return response
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def satellites(request):
"""View to render satellites page.
:returns: base/satellites.html
"""
satellite_objects = Satellite.objects.filter(
associated_satellite__isnull=True, satellite_entry__approved=True
).select_related('satellite_entry__operator').prefetch_related(
Prefetch(
'transmitter_entries',
queryset=Transmitter.objects.all(),
to_attr='approved_transmitters'
)
).annotate(
satellite_suggestions_count=Count(
'satellite_identifier__satellite_entries',
filter=Q(satellite_identifier__satellite_entries__reviewed__isnull=True)
)
)
return render(request, 'base/satellites.html', {'satellites': satellite_objects})
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def satellite(request, norad=None, sat_id=None):
"""View to render satellite page.
:returns: base/satellite.html
"""
if norad:
satellite_obj = get_object_or_404(Satellite, satellite_entry__norad_cat_id=norad)
else:
satellite_obj = get_object_or_404(Satellite, satellite_identifier__sat_id=sat_id)
if satellite_obj.associated_satellite:
satellite_obj = satellite_obj.associated_satellite
latest_tle = None
latest_tle_set = None
if hasattr(satellite_obj, 'latest_tle_set'):
latest_tle_set = satellite_obj.latest_tle_set
if latest_tle_set:
if request.user.has_perm('base.access_all_tles'):
latest_tle = latest_tle_set.latest
else:
latest_tle = latest_tle_set.latest_distributable
transmitter_suggestions = TransmitterSuggestion.objects.filter(satellite=satellite_obj)
for suggestion in transmitter_suggestions:
try:
original_transmitter = satellite_obj.transmitters.get(uuid=suggestion.uuid)
suggestion.transmitter = original_transmitter
except Transmitter.DoesNotExist:
suggestion.transmitter = None
2015-08-12 05:54:10 -06:00
satellite_suggestions = SatelliteSuggestion.objects.filter(
satellite_identifier=satellite_obj.satellite_identifier
)
try:
# pull the last 5 observers and their submission timestamps for this
# satellite and for the satellite that are associated with it
recent_observers = DemodData.objects.filter(
Q(satellite=satellite_obj) | Q(satellite__associated_satellite=satellite_obj)
).values('observer').annotate(latest_payload=Max('timestamp')
).order_by('-latest_payload')[:5]
except (ObjectDoesNotExist, IndexError):
recent_observers = ''
# decide whether a map (and map link) will be visible or not (ie: re-entered)
showmap = False
if satellite_obj.satellite_entry.status not in ['re-entered', 'future'] and latest_tle:
showmap = True
return render(
request, 'base/satellite.html', {
'satellite': satellite_obj,
'latest_tle': latest_tle,
'transmitter_suggestions': transmitter_suggestions,
'satellite_suggestions': satellite_suggestions,
'mapbox_token': settings.MAPBOX_TOKEN,
'recent_observers': recent_observers,
'badge_telemetry_count': millify(satellite_obj.telemetry_data_count),
'showmap': showmap
}
)
2015-08-12 05:54:10 -06:00
2015-09-17 07:01:41 -06:00
@login_required
def request_export(request, sat_pk, period=None):
"""View to request frames export download.
This triggers a request to collect and zip up the requested data for
download, which the user is notified of via email when the celery task is
completed.
:returns: the originating satellite page
"""
satellite_obj = get_object_or_404(Satellite, id=sat_pk)
if satellite_obj.associated_satellite:
satellite_obj = satellite_obj.associated_satellite
export_frames.delay(satellite_obj.satellite_identifier.sat_id, request.user.id, period)
messages.success(
request, ('Your download request was received. '
'You will get an email when it\'s ready')
)
return redirect(
reverse('satellite', kwargs={'sat_id': satellite_obj.satellite_identifier.sat_id})
)
@login_required
@require_POST
def satellite_suggestion_handler(request):
"""Returns the Satellite page after approving or rejecting a suggestion if
user has approve permission.
:returns: Satellite page
"""
satellite_entry = get_object_or_404(SatelliteSuggestion, pk=request.POST['pk'])
satellite_obj = get_object_or_404(
Satellite, satellite_identifier=satellite_entry.satellite_identifier
)
if request.user.has_perm('base.approve_satellitesuggestion'):
if 'approve' in request.POST:
satellite_entry.approved = True
messages.success(request, ('Satellite approved.'))
elif 'reject' in request.POST:
satellite_entry.approved = False
messages.success(request, ('Satellite rejected.'))
satellite_entry.reviewed = now()
satellite_entry.reviewer = request.user
satellite_entry.save(update_fields=['approved', 'reviewed', 'reviewer'])
if satellite_entry.approved:
satellite_obj.satellite_entry = satellite_entry
satellite_obj.save(update_fields=['satellite_entry'])
redirect_page = redirect(
reverse('satellite', kwargs={'sat_id': satellite_obj.satellite_identifier.sat_id})
)
return redirect_page
2015-04-25 10:47:22 -06:00
@login_required
@require_POST
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def transmitter_suggestion_handler(request):
"""Returns the Satellite page after approving or rejecting a suggestion if
user has approve permission.
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
:returns: Satellite page
"""
transmitter = get_object_or_404(TransmitterSuggestion, pk=request.POST['pk'])
if request.user.has_perm('base.approve_transmittersuggestion'):
if 'approve' in request.POST:
transmitter.approved = True
messages.success(request, ('Transmitter approved.'))
elif 'reject' in request.POST:
transmitter.approved = False
messages.success(request, ('Transmitter rejected.'))
transmitter.reviewed = now()
transmitter.reviewer = request.user
transmitter.save(update_fields=['approved', 'reviewed', 'reviewer'])
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
redirect_page = redirect(
reverse('satellite', kwargs={'sat_id': transmitter.satellite.satellite_identifier.sat_id})
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
)
return redirect_page
2015-06-10 15:16:38 -06:00
def about(request):
"""View to render about page.
:returns: base/about.html
"""
2015-06-10 15:16:38 -06:00
return render(request, 'base/about.html')
2015-07-02 05:39:27 -06:00
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def satnogs_help(request):
"""View to render help modal. Have to avoid builtin 'help' name
:returns: base/modals/help.html
"""
return render(request, 'base/modals/satnogs_help.html')
def search(request):
"""View to render search page.
:returns: base/search.html
"""
query_string = ''
results = Satellite.objects.none()
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']
if query_string:
results = Satellite.objects.filter(
associated_satellite__isnull=True, satellite_entry__approved=True
).filter(
Q(satellite_entry__name__icontains=query_string)
| Q(satellite_entry__names__icontains=query_string)
| Q(satellite_entry__norad_cat_id__icontains=query_string)
| Q(satellite_identifier__sat_id__icontains=query_string)
| Q(associated_with__satellite_identifier__sat_id__icontains=query_string)
).order_by('satellite_entry__name').prefetch_related(
Prefetch(
'transmitter_entries',
queryset=Transmitter.objects.all(),
to_attr='approved_transmitters'
)
)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
if results.count() == 1:
return redirect(
reverse('satellite', kwargs={'sat_id': results[0].satellite_identifier.sat_id})
)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
return render(request, 'base/search.html', {'results': results, 'q': query_string})
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def stats(request):
"""View to render stats page.
:returns: base/stats.html
"""
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
cached_satellites = []
ids = cache.get('satellites_ids')
2018-12-13 02:07:49 -07:00
observers = cache.get('stats_observers')
if not ids or not observers:
2018-12-13 02:07:49 -07:00
try:
cache_statistics()
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
ids = cache.get('satellites_ids')
observers = cache.get('stats_observers')
2018-12-13 02:07:49 -07:00
except OperationalError:
pass
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
for sid in ids:
stat = cache.get(sid)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
cached_satellites.append(stat)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
return render(
request, 'base/stats.html', {
'satellites': cached_satellites,
'observers': observers
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
}
)
def statistics(request):
"""Triggers a refresh of cached statistics if the cache does not exist
:returns: JsonResponse of statistics
"""
cached_stats = cache.get('stats_transmitters')
if not cached_stats:
cache_statistics()
cached_stats = []
return JsonResponse(cached_stats, safe=False)
2017-03-02 10:57:12 -07:00
@login_required
def users_edit(request):
"""View to render user settings page.
:returns: base/users_edit.html
"""
token = get_api_token(request.user)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
return render(request, 'base/modals/users_edit.html', {'token': token})
def recent_decoded_cnt(request, norad):
"""Returns a query of InfluxDB for a count of points across a given measurement
(norad) over the last 30 days, with a timestamp in unixtime.
:returns: JSON of point counts as JsonResponse
"""
if settings.USE_INFLUX:
results = read_influx(norad)
return JsonResponse(results, safe=False)
return HttpResponseServerError()
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
class TransmitterCreateView(LoginRequiredMixin, BSModalCreateView):
"""A django-bootstrap-modal-forms view for creating transmitter suggestions"""
template_name = 'base/modals/transmitter_create.html'
model = TransmitterEntry
form_class = TransmitterCreateForm
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
success_message = 'Your transmitter suggestion was stored successfully and will be \
reviewed by a moderator. Thanks for contibuting!'
satellite = Satellite()
user = get_user_model()
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def dispatch(self, request, *args, **kwargs):
"""
Overridden so we can make sure the `Satellite` instance exists first
"""
self.satellite = get_object_or_404(Satellite, pk=kwargs['satellite_pk'])
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
self.user = request.user
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
"""
Overridden to add the `Satellite` relation to the `Transmitter` instance.
"""
transmitter = form.instance
transmitter.satellite = self.satellite
transmitter.created = now()
transmitter.created_by = self.user
# Prevents sending notification twice as form_valid is triggered for validation and saving
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
notify_suggestion.delay(
transmitter.satellite.satellite_entry.id, self.user.id, 'transmitter'
)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
return super().form_valid(form)
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')
class TransmitterUpdateView(LoginRequiredMixin, BSModalUpdateView):
"""A django-bootstrap-modal-forms view for updating transmitter entries"""
template_name = 'base/modals/transmitter_update.html'
model = TransmitterEntry
form_class = TransmitterUpdateForm
success_message = 'Your transmitter suggestion was stored successfully and will be \
reviewed by a moderator. Thanks for contributing!'
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
user = get_user_model()
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def dispatch(self, request, *args, **kwargs):
self.user = request.user
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
transmitter = form.instance
# Add update as a new TransmitterEntry object and change fields in order to be a suggestion
transmitter.pk = None
transmitter.reviewed = None
transmitter.reviewer = None
transmitter.approved = False
transmitter.created = now()
transmitter.created_by = self.user
# Prevents sending notification twice as form_valid is triggered for validation and saving
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
notify_suggestion.delay(
transmitter.satellite.satellite_entry.id, self.user.id, 'transmitter'
)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
return super().form_valid(form)
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')
class MergeSatellitesView(LoginRequiredMixin, BSModalFormView):
"""Merges satellites if user has merge permission.
"""
template_name = 'base/modals/satellites_merge.html'
form_class = MergeSatellitesForm
user = get_user_model()
def dispatch(self, request, *args, **kwargs):
self.user = request.user
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
response = super().form_valid(form)
if self.user.has_perm('base.merge_satellites'):
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
primary_satellite = form.cleaned_data['primary_satellite']
associated_satellite = form.cleaned_data['associated_satellite']
associated_satellite.associated_satellite = primary_satellite
associated_satellite.save(update_fields=['associated_satellite'])
messages.success(self.request, ('Satellites have been merged!'))
else:
messages.error(self.request, ('No permission to merge satellites!'))
response = redirect(reverse('satellites'))
return response
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')
class SatelliteCreateView(LoginRequiredMixin, BSModalCreateView):
"""A django-bootstrap-modal-forms view for creating satellite suggestions"""
template_name = 'base/modals/satellite_create.html'
model = SatelliteEntry
form_class = SatelliteCreateForm
success_message = 'Your satellite suggestion was stored successfully and will be \
reviewed by a moderator. Thanks for contributing!'
user = get_user_model()
def dispatch(self, request, *args, **kwargs):
self.user = request.user
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
satellite_entry = form.instance
satellite_obj = None
# Create Satellite Identifier only when POST request is for saving and
# NORAD ID is not used by other Satellite.
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
try:
# If the form doesn't contain NORAD ID, create a new satellite
if satellite_entry.norad_cat_id:
satellite_obj = Satellite.objects.get(
satellite_entry__norad_cat_id=satellite_entry.norad_cat_id
)
satellite_entry.satellite_identifier = satellite_obj.satellite_identifier
else:
satellite_entry.satellite_identifier = SatelliteIdentifier.objects.create()
except Satellite.DoesNotExist:
satellite_entry.satellite_identifier = SatelliteIdentifier.objects.create()
satellite_entry.created = now()
satellite_entry.created_by = self.user
# form_valid triggers also save() allowing us to use satellite_entry
# for creating Satellite object, see comment bellow.
response = super().form_valid(form)
# Prevents sending notification twice as form_valid is triggered for
# validation and saving. Also create and Satellite object only when POST
# request is for saving and NORAD ID is not used by other Satellite.
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
if not satellite_obj:
satellite_obj = Satellite.objects.create(
satellite_identifier=satellite_entry.satellite_identifier,
satellite_entry=satellite_entry
)
notify_suggestion.delay(satellite_obj.satellite_entry.pk, self.user.id, 'satellite')
return response
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')
class SatelliteUpdateView(LoginRequiredMixin, BSModalUpdateView):
"""A django-bootstrap-modal-forms view for updating satellite entries"""
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
template_name = 'base/modals/satellite_update.html'
model = SatelliteEntry
form_class = SatelliteUpdateForm
success_message = 'Your satellite suggestion was stored successfully and will be \
reviewed by a moderator. Thanks for contributing!'
user = get_user_model()
def dispatch(self, request, *args, **kwargs):
self.user = request.user
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
satellite_entry = form.instance
initial_satellite_entry_pk = satellite_entry.pk
# Add update as a new SatelliteEntry object and change fields in order to be a suggestion
satellite_entry.pk = None
satellite_entry.reviewed = None
satellite_entry.reviewer = None
satellite_entry.approved = False
satellite_entry.created = now()
satellite_entry.created_by = self.user
# Prevents sending notification twice as form_valid is triggered for validation and saving
# Check if request is an AJAX one
if not self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
notify_suggestion.delay(initial_satellite_entry_pk, self.user.id, 'satellite')
return super().form_valid(form)
New SatNOGS DB user interface Initial commit of new UI. There is still some work to be done before this goes into dev, but here is the work so far: * Updated dependencies to latest 2.x django * Updated to Bootstrap 4 * New home screen to display most recent satellite entries, most recent data, and contributors * Adopted django-bootstrap-modal-forms for handling satellite and transmitter creation and update, with more of an emphasis on django's model/view/form model - and a dynamic flow where the modals and details are only loaded when the proper icon is clicked, reducing the overall page size * Adopted AdminLTE 3.x framework atop Bootstrap 4 * Created reusable cards for satellite and transmitters * Cards and Modals are organized into subdirectories for template includes and base templates, respectively * New stats display widgets using BS4 and AdminLTE 3 * Satellite search is redesigned and now accessible from any page of the site * Introduced datatables for an "All Satellites" view and a modification of the new "All Transmitters" view * Focus on all UI scaling down to mobile devices * New model created for Operator (/ Owner): name, names, description, website * Added django-countries for support of CountryField * Satellite model expanded to include: Operator, (satellite) website, countries, launched datetime, deployed datetime * Transmitter suggestions can now be approved in the UI by superusers * Satellite entries can now be edited in the UI by users with the change satellite permission * Satellite page is now broken into 'tabbed' panels (Profile, Map, Transmitters, etc) - with the tab menu options appearing in the sidebar or at the top depending on screen size * Other cleanup and changes that I'm missing for sure. Signed-off-by: Corey Shields <cshields@gmail.com>
2020-07-25 16:08:44 -06:00
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')