• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TOMToolkit / tom_base / 6713509976

31 Oct 2023 11:13PM UTC coverage: 86.773% (+0.7%) from 86.072%
6713509976

push

github-actions

web-flow
Merge pull request #699 from TOMToolkit/dev

Multi-Feature Merge. Please Review Carefully.

795 of 795 new or added lines in 39 files covered. (100.0%)

8253 of 9511 relevant lines covered (86.77%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.15
/tom_dataproducts/forced_photometry/forced_photometry_service.py
1
from abc import ABC, abstractmethod
1✔
2
import logging
1✔
3

4
from crispy_forms.helper import FormHelper
1✔
5
from crispy_forms.layout import ButtonHolder, Layout, Submit
1✔
6
from django import forms
1✔
7
from django.conf import settings
1✔
8
from django.utils.module_loading import import_string
1✔
9

10
logger = logging.getLogger(__name__)
1✔
11

12

13
def get_service_classes():
1✔
14
    try:
1✔
15
        forced_photometry_services = settings.FORCED_PHOTOMETRY_SERVICES
1✔
16
    except AttributeError:
1✔
17
        return {}
1✔
18

19
    service_choices = {}
×
20
    for service in forced_photometry_services.values():
×
21
        try:
×
22
            clazz = import_string(service.get('class'))
×
23
        except (ImportError, AttributeError):
×
24
            raise ImportError(f'Could not import {service}. Did you provide the correct path?')
×
25
        service_choices[clazz.name] = clazz
×
26
    return service_choices
×
27

28

29
def get_service_class(name):
1✔
30
    available_classes = get_service_classes()
×
31
    try:
×
32
        return available_classes[name]
×
33
    except KeyError:
×
34
        raise ImportError((
×
35
            f'Could not a find a forced photometry service with the name {name}. '
36
            'Did you add it to TOM_FORCED_PHOTOMETRY_CLASSES?'))
37

38

39
class ForcedPhotometryServiceException(Exception):
1✔
40
    pass
1✔
41

42

43
class BaseForcedPhotometryQueryForm(forms.Form):
1✔
44
    """
45
    This is the class that is responsible for displaying the forced photometry request form.
46
    This form is meant to be subclassed by more specific classes that represent a
47
    form for a specific forced photometry service, including the query parameters it supports.
48

49
    For an implementation example please see
50
    https://github.com/TOMToolkit/tom_base/blob/main/tom_dataproducts/forced_photometry/atlas.py
51
    """
52
    service = forms.CharField(required=True, max_length=50, widget=forms.HiddenInput())
1✔
53
    target_id = forms.IntegerField(required=True, widget=forms.HiddenInput())
1✔
54

55
    def __init__(self, *args, **kwargs):
1✔
56
        super().__init__(*args, **kwargs)
×
57
        self.helper = FormHelper()
×
58
        self.common_layout = Layout('service', 'target_id')
×
59
        self.helper.layout = Layout(
×
60
            self.common_layout,
61
            self.layout(),
62
            self.button_layout()
63
        )
64

65
    def layout(self):
1✔
66
        return
×
67

68
    def button_layout(self):
1✔
69
        return ButtonHolder(
×
70
            Submit('submit', 'Submit'),
71
        )
72

73

74
class BaseForcedPhotometryService(ABC):
1✔
75
    """
76
    This is the class that is responsible for defining the base forced photometry service class.
77
    This form is meant to be subclassed by more specific classes that represent a
78
    form for a particular forced photometry service.
79
    """
80
    name = 'BaseForcedPhotometryService'
1✔
81

82
    @abstractmethod
1✔
83
    def get_form(self):
1✔
84
        """
85
        This method returns the form for querying this service.
86
        """
87

88
    @abstractmethod
1✔
89
    def query_service(self, query_parameters):
1✔
90
        """
91
        This method takes in the serialized data from the query form and actually
92
        submits the query to the service
93
        """
94

95
    @abstractmethod
1✔
96
    def validate_form(self, query_parameters):
1✔
97
        """
98
        Same thing as query_service, but a dry run. You can
99
        skip this in different modules by just using "pass"
100

101
        Typically called by the .is_valid() method.
102
        """
103

104
    @abstractmethod
1✔
105
    def get_success_message(self):
1✔
106
        """
107
        This should return a message that shows up in the UI after making the query.
108
        It should explain what is happening / next steps, i.e. if the results will be
109
        emailed to you it should say that and that you must upload them once received.
110
        """
111

112
    @abstractmethod
1✔
113
    def get_data_product_type(self):
1✔
114
        """
115
        This should return the data_product_type for data products produced by this service
116
        Make sure to also add this type in your settings to DATA_PRODUCT_TYPES and
117
        DATA_PROCESSORS.
118
        """
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc