From ec1d4f02cfd05b9b433fdecc079f7727d7a5f90a Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Mon, 29 Jul 2024 15:16:07 -0400 Subject: [PATCH] formatting updating --- jwql/website/apps/jwql/data_containers.py | 71 +++++++++++++++-------- jwql/website/apps/jwql/forms.py | 40 +++++++++---- 2 files changed, 76 insertions(+), 35 deletions(-) diff --git a/jwql/website/apps/jwql/data_containers.py b/jwql/website/apps/jwql/data_containers.py index cc79b1ee4..2a971fd17 100644 --- a/jwql/website/apps/jwql/data_containers.py +++ b/jwql/website/apps/jwql/data_containers.py @@ -27,45 +27,61 @@ """ import copy -from collections import OrderedDict import glob import json -from operator import getitem +import logging import os import re import tempfile -import logging +from collections import OrderedDict +from datetime import datetime +from operator import getitem, itemgetter +import numpy as np +import pandas as pd +import pyvo as vo +import requests from astropy.io import fits from astropy.time import Time +from astroquery.mast import Mast from bs4 import BeautifulSoup from django import setup from django.conf import settings from django.contrib import messages from django.core.exceptions import ObjectDoesNotExist from django.db.models.query import QuerySet -import numpy as np -from operator import itemgetter -import pandas as pd -import pyvo as vo -import requests -from datetime import datetime from jwql.database import database_interface as di from jwql.database.database_interface import load_connection from jwql.edb.engineering_database import get_mnemonic, get_mnemonic_info, mnemonic_inventory -from jwql.utils.utils import check_config_for_key, ensure_dir_exists, filesystem_path, filename_parser, get_config -from jwql.utils.constants import MAST_QUERY_LIMIT, MONITORS, THUMBNAIL_LISTFILE, THUMBNAIL_FILTER_LOOK -from jwql.utils.constants import EXPOSURE_PAGE_SUFFIX_ORDER, IGNORED_SUFFIXES, INSTRUMENT_SERVICE_MATCH -from jwql.utils.constants import JWST_INSTRUMENT_NAMES_MIXEDCASE, JWST_INSTRUMENT_NAMES -from jwql.utils.constants import REPORT_KEYS_PER_INSTRUMENT -from jwql.utils.constants import SUFFIXES_TO_ADD_ASSOCIATION, SUFFIXES_WITH_AVERAGED_INTS, QueryConfigKeys -from jwql.utils.constants import ON_GITHUB_ACTIONS, ON_READTHEDOCS -from jwql.utils.constants import DEFAULT_MODEL_COMMENT +from jwql.utils.constants import ( + DEFAULT_MODEL_COMMENT, + EXPOSURE_PAGE_SUFFIX_ORDER, + IGNORED_SUFFIXES, + INSTRUMENT_SERVICE_MATCH, + JWST_INSTRUMENT_NAMES, + JWST_INSTRUMENT_NAMES_MIXEDCASE, + MAST_QUERY_LIMIT, + MONITORS, + ON_GITHUB_ACTIONS, + ON_READTHEDOCS, + REPORT_KEYS_PER_INSTRUMENT, + SUFFIXES_TO_ADD_ASSOCIATION, + SUFFIXES_WITH_AVERAGED_INTS, + THUMBNAIL_FILTER_LOOK, + THUMBNAIL_LISTFILE, + QueryConfigKeys, +) from jwql.utils.credentials import get_mast_token from jwql.utils.permissions import set_permissions -from jwql.utils.utils import get_rootnames_for_instrument_proposal -from astroquery.mast import Mast +from jwql.utils.utils import ( + check_config_for_key, + ensure_dir_exists, + filename_parser, + filesystem_path, + get_config, + get_rootnames_for_instrument_proposal, +) # Increase the limit on the number of entries that can be returned by # a MAST query. @@ -80,8 +96,16 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jwql.website.jwql_proj.settings") setup() - from .forms import MnemonicSearchForm, MnemonicQueryForm, MnemonicExplorationForm, InstrumentAnomalySubmitForm, RootFileInfoCommentSubmitForm, RootFileInfoExposureCommentSubmitForm - from jwql.website.apps.jwql.models import Observation, Proposal, RootFileInfo, Anomalies + from jwql.website.apps.jwql.models import Anomalies, Observation, Proposal, RootFileInfo + + from .forms import ( + InstrumentAnomalySubmitForm, + MnemonicExplorationForm, + MnemonicQueryForm, + MnemonicSearchForm, + RootFileInfoCommentSubmitForm, + RootFileInfoExposureCommentSubmitForm, + ) check_config_for_key('auth_mast') configs = get_config() auth_mast = configs['auth_mast'] @@ -403,7 +427,7 @@ def get_additional_exposure_info(root_file_infos, image_info): filter_value = root_file_info.filter pupil_value = root_file_info.pupil grating_value = root_file_info.grating - exp_comment = root_file_info.exp_comment + exp_comment = root_file_info.exp_comment # Print N/A if no exposure comment is used exp_comment = exp_comment if exp_comment != DEFAULT_MODEL_COMMENT else "N/A" @@ -673,6 +697,7 @@ def get_anomaly_form(request, inst, file_root): return form + def get_comment_form(request, file_root): """Generate form data for comment form @@ -701,6 +726,7 @@ def get_comment_form(request, file_root): return comment_form + def get_exp_comment_form(request, file_root): """Generate form data for exposure comment This form updates all exposure level comments in each related rootfileimage model. @@ -761,7 +787,6 @@ def get_group_anomalies(file_root): anomalies_string += f" -- Comments: {rootfileinfo.comment}" group_anomaly_dict[rootfileinfo.root_name] = anomalies_string - return group_anomaly_dict diff --git a/jwql/website/apps/jwql/forms.py b/jwql/website/apps/jwql/forms.py index f7edb2999..c7a4bdc38 100644 --- a/jwql/website/apps/jwql/forms.py +++ b/jwql/website/apps/jwql/forms.py @@ -44,31 +44,44 @@ def view_function(request): placed in the ``jwql`` directory. """ -from collections import defaultdict import datetime import glob -import os import logging +import os +from collections import defaultdict from astropy.time import Time, TimeDelta from django import forms from django.shortcuts import redirect from django.utils.html import format_html from django.utils.safestring import mark_safe +from wtforms import StringField, SubmitField + from jwql.edb.engineering_database import is_valid_mnemonic +from jwql.utils.constants import ( + ANOMALIES_PER_INSTRUMENT, + ANOMALY_CHOICES_PER_INSTRUMENT, + APERTURES_PER_INSTRUMENT, + DETECTOR_PER_INSTRUMENT, + EXP_TYPE_PER_INSTRUMENT, + FILTERS_PER_INSTRUMENT, + GENERIC_SUFFIX_TYPES, + GRATING_PER_INSTRUMENT, + GUIDER_FILENAME_TYPE, + IGNORED_SUFFIXES, + JWST_INSTRUMENT_NAMES_MIXEDCASE, + JWST_INSTRUMENT_NAMES_SHORTHAND, + LOOK_OPTIONS, + PROPOSAL_CATEGORIES, + PUPILS_PER_INSTRUMENT, + READPATT_PER_INSTRUMENT, + SORT_OPTIONS, + SUBARRAYS_PER_INSTRUMENT, +) +from jwql.utils.utils import filename_parser, get_config, get_rootnames_for_instrument_proposal, query_format from jwql.website.apps.jwql.models import Anomalies, RootFileInfo -from jwql.utils.constants import (ANOMALY_CHOICES_PER_INSTRUMENT, ANOMALIES_PER_INSTRUMENT, APERTURES_PER_INSTRUMENT, DETECTOR_PER_INSTRUMENT, - EXP_TYPE_PER_INSTRUMENT, FILTERS_PER_INSTRUMENT, GENERIC_SUFFIX_TYPES, GRATING_PER_INSTRUMENT, - GUIDER_FILENAME_TYPE, JWST_INSTRUMENT_NAMES_MIXEDCASE, JWST_INSTRUMENT_NAMES_SHORTHAND, - READPATT_PER_INSTRUMENT, IGNORED_SUFFIXES, SUBARRAYS_PER_INSTRUMENT, PUPILS_PER_INSTRUMENT, - LOOK_OPTIONS, SORT_OPTIONS, PROPOSAL_CATEGORIES) -from jwql.utils.utils import (get_config, get_rootnames_for_instrument_proposal, filename_parser, query_format) - -from wtforms import SubmitField, StringField - - class BaseForm(forms.Form): """A generic form with target resolve built in""" # Target Resolve @@ -78,6 +91,7 @@ class BaseForm(forms.Form): # Submit button resolve_submit = SubmitField('Resolve Target') + class RootFileInfoCommentSubmitForm(forms.ModelForm): """Creates a ``Comment Form`` object that allows for text input in a form field. This uses forms.ModelForm which is good for simplifying direct access to @@ -87,6 +101,7 @@ class Meta: model = RootFileInfo fields = ['comment'] + class RootFileInfoExposureCommentSubmitForm(forms.ModelForm): """Creates a ``Comment Form`` object that allows for text input in a form field. This uses forms.ModelForm which is good for simplifying direct access to @@ -96,6 +111,7 @@ class Meta: model = RootFileInfo fields = ['exp_comment'] + class JwqlQueryForm(BaseForm): """Form validation for the JWQL Query viewing tool"""