Skip to content

Commit

Permalink
DATA_TYPE_OPTIONS -> DATA_TYPE_CHOICES
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey Chatelain committed Mar 18, 2024
1 parent 7398a07 commit cec06a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions tom_dataproducts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.models import Group
from django.conf import settings

from tom_dataproducts.models import DataProductGroup, DataProduct, DATA_TYPE_OPTIONS
from tom_dataproducts.models import DataProductGroup, DataProduct, DATA_TYPE_CHOICES
from tom_observations.models import ObservationRecord
from tom_targets.models import Target
from tom_dataproducts.sharing import get_sharing_destination_options
Expand Down Expand Up @@ -31,7 +31,7 @@ class DataProductUploadForm(forms.Form):
widget=forms.ClearableFileInput()
)
data_product_type = forms.ChoiceField(
choices=DATA_TYPE_OPTIONS,
choices=DATA_TYPE_CHOICES,
widget=forms.RadioSelect(),
required=True
)
Expand All @@ -52,7 +52,7 @@ class DataShareForm(forms.Form):
share_title = forms.CharField(required=False, label="Title")
share_message = forms.CharField(required=False, label="Message", widget=forms.Textarea(attrs={'rows': 4}))
share_authors = forms.CharField(required=False, widget=forms.HiddenInput())
data_type = forms.ChoiceField(required=False, choices=DATA_TYPE_OPTIONS, label="Data Type")
data_type = forms.ChoiceField(required=False, choices=DATA_TYPE_CHOICES, label="Data Type")
target = forms.ModelChoiceField(
Target.objects.all(),
widget=forms.HiddenInput(),
Expand Down
14 changes: 7 additions & 7 deletions tom_dataproducts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@


# Check settings.py for DATA_PRODUCT_TYPES, and provide defaults if not found
DEFAULT_DATA_TYPE_OPTIONS = (('photometry', 'Photometry'), ('spectroscopy', 'Spectroscopy'))
DEFAULT_DATA_TYPE_CHOICES = (('photometry', 'Photometry'), ('spectroscopy', 'Spectroscopy'))
try:
# Pull out tuples from settings.DATA_PRODUCT_TYPES dictionary to build choice fields for DataProduct Types
DATA_TYPE_OPTIONS = settings.DATA_PRODUCT_TYPES.values()
DATA_TYPE_CHOICES = settings.DATA_PRODUCT_TYPES.values()
except AttributeError:
DATA_TYPE_OPTIONS = DEFAULT_DATA_TYPE_OPTIONS
DATA_TYPE_CHOICES = DEFAULT_DATA_TYPE_CHOICES


def find_fits_img_size(filename):
Expand Down Expand Up @@ -220,8 +220,8 @@ def save(self, *args, **kwargs):
Saves the current `DataProduct` instance. Before saving, validates the `data_product_type` against those
specified in `settings.py`.
"""
# DATA_TYPE_OPTIONS from either settings.py or default types: (value, display)
for dp_value, _ in DATA_TYPE_OPTIONS:
# DATA_TYPE_CHOICES from either settings.py or default types: (value, display)
for dp_value, _ in DATA_TYPE_CHOICES:
if not self.data_product_type or self.data_product_type == dp_value:
break
else:
Expand All @@ -235,7 +235,7 @@ def get_type_display(self):
:returns: Display value for a given data_product_type.
:rtype: str
"""
data_product_type_dict = {dp_type: dp_display for dp_type, dp_display in DATA_TYPE_OPTIONS}
data_product_type_dict = {dp_type: dp_display for dp_type, dp_display in DATA_TYPE_CHOICES}
return data_product_type_dict[self.data_product_type]

def get_file_name(self):
Expand Down Expand Up @@ -380,7 +380,7 @@ class Meta:

def save(self, *args, **kwargs):
# Validate data_type based on options in settings.py or default types: (value, display)
for dp_value, _ in DATA_TYPE_OPTIONS:
for dp_value, _ in DATA_TYPE_CHOICES:
if self.data_type and self.data_type == dp_value:
break
else:
Expand Down

0 comments on commit cec06a2

Please sign in to comment.