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

145 lines
5.4 KiB
Python
Raw Normal View History

"""SatNOGS DB django base Forms class"""
from bootstrap_modal_forms.forms import BSModalForm, BSModalModelForm
from django.core.exceptions import ValidationError
from django.forms import ModelChoiceField, TextInput
from django.utils.translation import gettext_lazy as _
2015-04-25 10:47:22 -06:00
from db.base.models import Satellite, SatelliteEntry, Transmitter, TransmitterEntry
2015-04-25 10:47:22 -06:00
def existing_uuid(value):
"""ensures the UUID is existing and valid"""
try:
Transmitter.objects.get(uuid=value)
except Transmitter.DoesNotExist as error:
raise ValidationError(
_('%(value)s is not a valid uuid'),
code='invalid',
params={'value': value},
) from error
class TransmitterCreateForm(BSModalModelForm): # pylint: disable=too-many-ancestors
"""Model Form class for TransmitterEntry objects"""
2015-04-25 10:47:22 -06:00
class Meta:
model = TransmitterEntry
fields = [
'description', 'type', 'status', 'uplink_low', 'uplink_high', 'uplink_drift',
'uplink_mode', 'downlink_low', 'downlink_high', 'downlink_drift', 'downlink_mode',
'invert', 'baud', 'citation', 'service', 'coordination', 'coordination_url'
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
]
labels = {
'downlink_low': _('Downlink freq.'),
'uplink_low': _('Uplink freq.'),
'invert': _('Inverted Transponder?'),
}
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
widgets = {
'description': TextInput(),
}
class TransmitterUpdateForm(BSModalModelForm): # pylint: disable=too-many-ancestors
"""Model Form class for TransmitterEntry objects"""
class Meta:
model = TransmitterEntry
fields = [
'description', 'type', 'status', 'uplink_low', 'uplink_high', 'uplink_drift',
'uplink_mode', 'downlink_low', 'downlink_high', 'downlink_drift', 'downlink_mode',
'invert', 'baud', 'citation', 'service', 'coordination', 'coordination_url'
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
]
labels = {
'downlink_low': _('Downlink freq.'),
'uplink_low': _('Uplink freq.'),
'invert': _('Inverted Transponder?'),
}
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
widgets = {
'description': TextInput(),
}
class SatelliteCreateForm(BSModalModelForm): # pylint: disable=too-many-ancestors
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
"""Form that uses django-bootstrap-modal-forms for satellite editing"""
class Meta:
model = SatelliteEntry
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
fields = [
'norad_cat_id', 'norad_follow_id', 'name', 'names', 'description', 'operator',
'status', 'countries', 'website', 'dashboard_url', 'launched', 'deployed', 'decayed',
'image', 'citation'
]
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
labels = {
'norad_cat_id': _('Norad ID'),
'norad_follow_id': _('Followed Norad 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
'names': _('Other names'),
'countries': _('Countries of Origin'),
'launched': _('Launch Date'),
'deployed': _('Deploy Date'),
'decayed': _('Re-entry Date'),
'description': _('Description'),
'dashboard_url': _('Dashboard URL'),
'operator': _('Owner/Operator'),
}
widgets = {'names': TextInput()}
class SatelliteUpdateForm(BSModalModelForm): # pylint: disable=too-many-ancestors
"""Form that uses django-bootstrap-modal-forms for satellite editing"""
class Meta:
model = SatelliteEntry
fields = [
'norad_cat_id', 'norad_follow_id', 'name', 'names', 'description', 'operator',
'status', 'countries', 'website', 'dashboard_url', 'launched', 'deployed', 'decayed',
'image', 'citation'
]
labels = {
'norad_cat_id': _('Norad ID'),
'norad_follow_id': _('Followed Norad ID'),
'names': _('Other names'),
'countries': _('Countries of Origin'),
'launched': _('Launch Date'),
'deployed': _('Deploy Date'),
'decayed': _('Re-entry Date'),
'description': _('Description'),
'dashboard_url': _('Dashboard URL'),
'operator': _('Owner/Operator'),
}
widgets = {'names': TextInput()}
class MergeSatellitesForm(BSModalForm):
"""Form that uses django-bootstrap-modal-forms for merging satellites"""
primary_satellite = ModelChoiceField(
label=_('Primary Satellite'),
queryset=Satellite.objects.filter(
associated_satellite__isnull=True, satellite_entry__approved=True
),
empty_label="Select the Primary Satellite"
)
associated_satellite = ModelChoiceField(
label=_('Associated Satellite'),
queryset=Satellite.objects.filter(
associated_satellite__isnull=True, satellite_entry__approved=True
),
empty_label="Select the Associated Satellite"
)
def clean(self):
if any(self.errors):
# If there are errors in forms validation no need for validating the formset
return
cleaned_data = super().clean()
primary_satellite = cleaned_data.get("primary_satellite")
associated_satellite = cleaned_data.get("associated_satellite")
if primary_satellite == associated_satellite:
self.add_error(
'associated_satellite',
ValidationError(
_('Associated Satellite can not be the same with the Primary Satellite'),
code='invalid'
)
)
class Meta:
fields = ['primary_satellite', 'associated_satellite']