Skip to content

Commit 61714ec

Browse files
authored
Merge branch 'dev' into 1258-create-integration-point-for-target-detail-tabs
2 parents da44758 + f3eeaeb commit 61714ec

31 files changed

Lines changed: 1209 additions & 67 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ jobs:
1818
- name: Style Checks
1919
run: poetry run flake8 tom_* --exclude=*/migrations/* --max-line-length=120
2020

21+
check_migrations:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-python@v2
26+
with:
27+
python-version: "3.12"
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install "poetry>=2.0,<3.0"
32+
poetry install
33+
- name: Missing Migrations
34+
run: |
35+
poetry run python manage.py makemigrations --check
36+
2137
run_tests:
2238
runs-on: ubuntu-latest
2339
strategy:

tom_alerts/brokers/tns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def fetch_tns_transients(cls, parameters):
171171
parameters: dictionary containing days_ago (str), min_date (str)
172172
and either:
173173
174-
- Right Ascention, declination (can be deg, deg or h:m:s, d:m:s) of the target,
174+
- Right Ascension, declination (can be deg, deg or h:m:s, d:m:s) of the target,
175175
and search radius and search radius unit ("arcmin", "arcsec", or "deg"), or
176176
177177
- TNS name without the prefix (eg. 2024aa instead of AT2024aa)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% comment %}}
2+
Empty partial to serve as a placeholder for backwards compatibility in the case that
3+
tom_dataservices is not installed.
4+
{% endcomment %}

tom_catalogs/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django import template
2+
from django.apps import apps
3+
from django.template.loader import get_template
4+
5+
from tom_catalogs.harvester import get_service_classes
6+
7+
8+
def catalog_query_menu():
9+
context = {'catalogs': get_service_classes().keys()}
10+
return context
11+
12+
13+
# Added for backwards compatibility in case tom_dataservices is not installed.
14+
if 'tom_dataservices' not in [app.name for app in apps.get_app_configs()]:
15+
register = template.Library()
16+
t = get_template('tom_catalogs/partials/catalog_query_menu.html')
17+
register.inclusion_tag(t)(catalog_query_menu)

tom_common/templates/tom_common/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
</ul>
5252
<ul class="navbar-nav ml-auto" id="login-buttons">
53-
{% navbar_login %}
53+
{% include 'tom_common/partials/navbar_login.html' %}
5454
</ul>
5555
</div>
5656
</nav>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
{% for nav_item in nav_item_list %}
2-
{% include nav_item.partial %}
1+
{% load tom_common_extras %}
2+
{% for nav_item in nav_items_to_display %}
3+
{% show_individual_app_partial nav_item %}
34
{% endfor %}

tom_common/templates/tom_common/partials/navbar_login.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
{% for nav_item in nav_item_list %}
2-
{% include nav_item.partial %}
3-
{% endfor %}
1+
{% load tom_common_extras %}
2+
{% navbar_app_addons 'right' %}
43
{% if user.is_authenticated %}
54
<li class="nav-item">
65
{% if user.first_name or user.last_name %}

tom_common/templatetags/tom_common_extras.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import textwrap
2+
import logging
23

34
from django import template
45
from django.db.models import IntegerField
@@ -8,51 +9,48 @@
89
from django.apps import apps
910
from django.core.exceptions import FieldDoesNotExist
1011
from guardian.shortcuts import get_objects_for_user
12+
from django.utils.module_loading import import_string
1113

1214
from tom_targets.models import Target
1315

14-
register = template.Library()
15-
16+
logger = logging.getLogger(__name__)
1617

17-
@register.inclusion_tag('tom_common/partials/navbar_login.html', takes_context=True)
18-
def navbar_login(context):
19-
"""
20-
Renders the username as a link to the user page, as well as the login button. Can be overridden to render additional
21-
account-related buttons.
22-
"""
23-
nav_item_list = []
24-
for app in apps.get_app_configs():
25-
try:
26-
nav_items = app.nav_items()
27-
if nav_items:
28-
for item in nav_items:
29-
if item.get('position', 'left') == 'right':
30-
nav_item_list.append(item)
31-
except AttributeError:
32-
pass
33-
return {'user': context['user'],
34-
'nav_item_list': nav_item_list}
18+
register = template.Library()
3519

3620

3721
@register.inclusion_tag('tom_common/partials/navbar_app_addons.html', takes_context=True)
38-
def navbar_app_addons(context):
22+
def navbar_app_addons(context, position='left'):
3923
"""
4024
Imports the navbar content from appropriate apps
4125
This should be a list of partials containing an <li> element that you would like displayed in the navbar with the
4226
following format:
4327
`<li class="nav-item"> <a class="nav-link" href="{% url 'namespace:view_name' %}">Link Text</a> </li>`
4428
"""
45-
nav_item_list = []
29+
nav_items_to_display = []
4630
for app in apps.get_app_configs():
4731
try:
4832
nav_items = app.nav_items()
49-
if nav_items:
50-
for item in nav_items:
51-
if item.get('position', 'left') != 'right':
52-
nav_item_list.append(item)
5333
except AttributeError:
54-
pass
55-
return {'nav_item_list': nav_item_list}
34+
continue
35+
if nav_items:
36+
for item in nav_items:
37+
context_method_path = item.get('context', None)
38+
if context_method_path:
39+
try:
40+
context_method = import_string(item.get('context'))
41+
new_context = context_method({})
42+
except ImportError as e:
43+
logger.warning(f'WARNING: Could not import context for {app.name} navbar item from '
44+
f'{item["context"]}: \n'
45+
f'{e}')
46+
continue
47+
else:
48+
new_context = {}
49+
if item.get('position', 'left') == position:
50+
nav_items_to_display.append({'partial': item['partial'], 'context': new_context})
51+
52+
context['nav_items_to_display'] = nav_items_to_display
53+
return context
5654

5755

5856
@register.simple_tag

tom_dataservices/apps.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
from django.apps import AppConfig
2+
from django.urls import path, include
23

34

45
class TomDataservicesConfig(AppConfig):
56
default_auto_field = 'django.db.models.BigAutoField'
67
name = 'tom_dataservices'
8+
trimmed_name = 'dataservices'
9+
10+
def include_url_paths(self):
11+
"""
12+
Integration point for adding URL patterns to the Tom Common URL configuration.
13+
This method should return a list of URL patterns to be included in the main URL configuration.
14+
"""
15+
urlpatterns = [
16+
path(f'{self.label}/', include(f'{self.name}.urls', namespace=f'{self.trimmed_name}'))
17+
]
18+
return urlpatterns
19+
20+
def nav_items(self):
21+
"""
22+
Integration point for adding items to the navbar.
23+
This method should return a list of partial templates to be included in the navbar.
24+
"""
25+
return [{'partial': 'tom_dataservices/partials/navbar_list.html',
26+
'context': 'tom_dataservices.templatetags.dataservices_extras.dataservices_list'}]
27+
28+
def data_services(self):
29+
"""
30+
integration point for including data services in the TOM
31+
This method should return a list of dictionaries containing dot separated DataService classes
32+
"""
33+
return [{'class': f'{self.name}.data_services.tns.TNSDataService'}]

0 commit comments

Comments
 (0)