Skip to content

Commit

Permalink
Merge branch 'dev' into main; update meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
phycodurus committed Feb 8, 2022
2 parents efb3bd2 + 5ec1ec8 commit 32826c2
Show file tree
Hide file tree
Showing 41 changed files with 114 additions and 91 deletions.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include LICENSE
include README.md
recursive-include tom_superevents/static *
recursive-include tom_superevents/templates *
recursive-include tom_nonlocalizedevents/static *
recursive-include tom_nonlocalizedevents/templates *
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
[![pypi](https://img.shields.io/pypi/v/tom-superevents.svg)](https://pypi.python.org/pypi/tom-superevents)
[![run-tests](https://github.com/TOMToolkit/tom_superevents/actions/workflows/run-tests.yml/badge.svg)](https://github.com/TOMToolkit/tom_superevents/actions/workflows/run-tests.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cbcf7ce565d8450f86fff863ef061ff9)](https://www.codacy.com/gh/TOMToolkit/tom_superevents/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TOMToolkit/tom_superevents&utm_campaign=Badge_Grade)
[![Coverage Status](https://coveralls.io/repos/github/TOMToolkit/tom_superevents/badge.svg?branch=main)](https://coveralls.io/github/TOMToolkit/tom_superevents?branch=main)
[![run-tests](https://github.com/TOMToolkit/tom_nonlocalizedevents/actions/workflows/run-tests.yml/badge.svg)](https://github.com/TOMToolkit/tom_nonlocalizedevents/actions/workflows/run-tests.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cbcf7ce565d8450f86fff863ef061ff9)](https://www.codacy.com/gh/TOMToolkit/tom_nonlocalizedevents/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TOMToolkit/tom_nonlocalizedevents&utm_campaign=Badge_Grade)
[![Coverage Status](https://coveralls.io/repos/github/TOMToolkit/tom_nonlocalizedevents/badge.svg?branch=main)](https://coveralls.io/github/TOMToolkit/tom_nonlocalizedevents?branch=main)

# GW Superevent (or GRB, Neutrino) EM follow-up

This reusable TOM Toolkit app provides support for gravitational wave (GW)
superevent electromagnetic (EM) follow up observations.
This reusable TOM Toolkit app provides support for gravitational wave (GW) superevent
and other non-localized event electromagnetic (EM) follow up observations.

## Installation

1. Install the package into your TOM environment:
```bash
pip install tom_superevents
pip install tom_nonlocalizedevents
```

2. In your project `settings.py`, add `tom_superevents` to your `INSTALLED_APPS` setting:
2. In your project `settings.py`, add `tom_nonlocalizedevents` to your `INSTALLED_APPS` setting:

```python
INSTALLED_APPS = [
...
'tom_superevents',
'tom_nonlocalizedevents',
]
```

3. Include the tom_superevent URLconf in your project `urls.py`:
3. Include the tom_nonlocalizedevent URLconf in your project `urls.py`:
```python
urlpatterns = [
...
path('superevents/', include('tom_superevents.urls')),
path('nonlocalizedevents/', include('tom_nonlocalizedevents.urls')),
]
```

4. Copy ``tom_superevents/templates/tom_common/base.html`` into your project root's ``templates/tom_common/base.html``.
4. Copy ``tom_nonlocalizedevents/templates/tom_common/base.html`` into your project root's ``templates/tom_common/base.html``.

5. Run ``python manage.py migrate`` to create the tom_superevent models.
5. Run ``python manage.py migrate`` to create the tom_nonlocalizedevents models.


## Running the tests

In order to run the tests, run the following in your virtualenv:

`python tom_superevent/tests/run_tests.py`
`python tom_superevents/tests/run_tests.py`

2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tom_superevents_base.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tom_nonlocalizedevents_base.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[metadata]
name = tom_superevents
version = 0.3.1
description = Reusable TOMToolkit app to support gravitational wave superevent EM follow-up observations.
name = tom_nonlocalizedevents
version = 0.4.0
description = Reusable TOMToolkit app to support gravitational wave superevent and other nonlocalized event EM follow-up observations.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/TOMToolkit/tom_superevents
url = https://github.com/TOMToolkit/tom_nonlocalizedevents
author = TOM Toolkit Project
author_email = dcollom@lco.global, llindstrom@lco.global
license = GPL-3.0 License
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tom_superevents/apps.py → tom_nonlocalizedevents/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class TomSupereventsConfig(AppConfig):
name = 'tom_superevents'
name = 'tom_nonlocalizedevents'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0001_initial'),
('tom_nonlocalizedevents', '0001_initial'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0002_superevent'),
('tom_nonlocalizedevents', '0002_superevent'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0003_auto_20210225_0034'),
('tom_nonlocalizedevents', '0003_auto_20210225_0034'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0004_superevent_superevent_type'),
('tom_nonlocalizedevents', '0004_superevent_superevent_type'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Migration(migrations.Migration):

dependencies = [
('tom_targets', '0019_auto_20210811_0018'),
('tom_superevents', '0005_auto_20210319_2241'),
('tom_nonlocalizedevents', '0005_auto_20210319_2241'),
]

operations = [
migrations.CreateModel(
name='EventCandidate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('superevent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tom_superevents.superevent')),
('superevent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tom_nonlocalizedevents.superevent')),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tom_targets.target')),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0006_auto_20210827_2346'),
('tom_nonlocalizedevents', '0006_auto_20210827_2346'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('tom_superevents', '0007_eventcandidate_viable'),
('tom_nonlocalizedevents', '0007_eventcandidate_viable'),
]

operations = [
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tom_targets.models import Target
from tom_targets.serializers import TargetSerializer

from tom_superevents.models import EventCandidate, EventLocalization, Superevent
from tom_nonlocalizedevents.models import EventCandidate, EventLocalization, Superevent


class BulkCreateEventCandidateListSerializer(serializers.ListSerializer):
Expand Down
34 changes: 34 additions & 0 deletions tom_nonlocalizedevents/templates/tom_nonlocalizedevents/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'tom_common/index.html' %}
<!-- tom_superevent/index.html -->
{% block content %}
<!-- block content -->
<h1>Non-Localized Event Index</h1>
{% if object_list %}
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Event ID</th>
<th scope="col">Event Type</th>
</tr>
</thead>
<tbody>
{% for event in object_list %}
<tr>
<td scope="row">
<a href="{% url 'nonlocalizedevents:detail' event.id %}">{{ event.id }}</a>
</td>
<td>
<a href="{{ event.superevent_url }}">{{ event.superevent_id }}</a>
</td>
<td>{{ event.superevent_type }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No events have been created. Create Superevents via the admin interface or REST API.</p>
<p>Coming soon: event creation from the <a href="{% url 'tom_alerts:list' %}">SCiMMA Alert Broker</a>.</p>
{% endif %}

{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load bootstrap4 static superevent_extras tom_common_extras %}

{% block additional_css %}
<link rel="stylesheet" href="{% static 'tom_superevents/css/main.css' %}">
<link rel="stylesheet" href="{% static 'tom_nonlocalizedevents/css/main.css' %}">
<!-- put template-specific css here -->
<style type="text/css">
</style>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def percentage_filter(value):
return value


@register.inclusion_tag('tom_superevents/partials/alert_table.html', takes_context=True)
@register.inclusion_tag('tom_nonlocalizedevents/partials/alert_table.html', takes_context=True)
def alert_table(context):
"""
Displays the alerts of an event.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import factory

from tom_superevents.models import Superevent, EventLocalization
from tom_nonlocalizedevents.models import Superevent, EventLocalization


class SupereventFactory(factory.django.DjangoModelFactory):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.urls import reverse
from rest_framework.test import APITestCase

from tom_superevents.tests.factories import SupereventFactory, EventLocalizationFactory
from tom_nonlocalizedevents.tests.factories import SupereventFactory, EventLocalizationFactory


class SupereventAPITestCase(APITestCase):
Expand Down
10 changes: 5 additions & 5 deletions tom_superevents/urls.py → tom_nonlocalizedevents/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
# for any of the INSTALLED_APPS (i.e. the routes are added because the APP is
# INSTALLED -- nothing else is required))
router = SharedAPIRootRouter()
router.register(r'superevents', views.SupereventViewSet)
router.register(r'nonlocalizedevents', views.NonlocalizedEventViewSet)
router.register(r'eventlocalizations', views.EventLocalizationViewSet)
router.register(r'eventcandidates', views.EventCandidateViewSet)

# app_name provides namespace in {% url %} template tag
# (i.e. {% url 'superevents:detail' <pk> %}
app_name = 'superevents'
# (i.e. {% url 'nonlocalizedevents:detail' <pk> %}
app_name = 'nonlocalizedevents'

urlpatterns = [
path('', views.SupereventListView.as_view(), name='index'),
path('<int:pk>/', views.SupereventDetailView.as_view(), name='detail'),
path('', views.NonlocalizedEventListView.as_view(), name='index'),
path('<int:pk>/', views.NonlocalizedEventDetailView.as_view(), name='detail'),
]
44 changes: 33 additions & 11 deletions tom_superevents/views.py → tom_nonlocalizedevents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@

from rest_framework import permissions, viewsets

from tom_superevents.superevent_clients.gravitational_wave import GravitationalWaveClient
from tom_nonlocalizedevents.superevent_clients.gravitational_wave import GravitationalWaveClient

from .models import EventCandidate, EventLocalization, Superevent
from .serializers import EventCandidateSerializer, EventLocalizationSerializer, SupereventSerializer


class SupereventListView(ListView):
class NonlocalizedEventListView(ListView):
"""
Unadorned Django ListView subclass for Superevent model.
(To be updated when Superevent model is renamed to NonlocalizedEvent).
"""
model = Superevent
template_name = 'tom_superevents/index.html'
template_name = 'tom_nonlocalizedevents/index.html'


class SupereventDetailView(DetailView):
class NonlocalizedEventDetailView(DetailView):
"""
Django DetailView subclass for SuperEvent model.
(To be updated when Superevent model is renamed to NonlocalizedEvent).
Has mechanism to supply templates specific to the type of NonlocalizedEvent
(GW, GRB, Nutrino).
"""
model = Superevent
template_name = 'tom_superevents/detail.html'
template_name = 'tom_nonlocalizedevents/detail.html'

# TODO: consider combining these dictionaries
template_mapping = {
Superevent.SupereventType.GRAVITATIONAL_WAVE: 'tom_superevents/superevent_detail/gravitational_wave.html',
Superevent.SupereventType.GAMMA_RAY_BURST: 'tom_superevents/superevent_detail/gamma_ray_burst.html',
Superevent.SupereventType.NEUTRINO: 'tom_superevents/superevent_detail/neutrino.html',
Superevent.SupereventType.GRAVITATIONAL_WAVE:
'tom_nonlocalizedevents/superevent_detail/gravitational_wave.html',
Superevent.SupereventType.GAMMA_RAY_BURST:
'tom_nonlocalizedevents/superevent_detail/gamma_ray_burst.html',
Superevent.SupereventType.NEUTRINO:
'tom_nonlocalizedevents/superevent_detail/neutrino.html',
}

# A client in this context is the interface to the service providing event info.
# (i.e GraceDB for gravitational wave events)
client_mapping = {
Superevent.SupereventType.GRAVITATIONAL_WAVE: GravitationalWaveClient(),
Superevent.SupereventType.GAMMA_RAY_BURST: None,
Expand All @@ -49,16 +66,21 @@ def get_context_data(self, **kwargs):
# Django Rest Framework Views


class SupereventViewSet(viewsets.ModelViewSet):
class NonlocalizedEventViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows Superevents to be viewed or edited.
DRF API endpoint that allows Superevents to be viewed or edited.
"""
queryset = Superevent.objects.all()
serializer_class = SupereventSerializer
permission_classes = []


class EventCandidateViewSet(viewsets.ModelViewSet):
"""
DRF API endpoint for EventCandidate model.
Implementation has changes for bulk_create and update/PATCH EventCandidate instances.
"""
queryset = EventCandidate.objects.all()
serializer_class = EventCandidateSerializer
permission_classes = [] # TODO: re-implement auth permissions
Expand Down Expand Up @@ -91,7 +113,7 @@ def update(self, request, *args, **kwargs):

class EventLocalizationViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows EventLocalizations to be viewed or edited.
DRF API endpoint that allows EventLocalizations to be viewed or edited.
"""
queryset = EventLocalization.objects.all()
serializer_class = EventLocalizationSerializer
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ASGI config for tom_superevents_base project.
ASGI config for tom_nonlocalizedevents_base project.
It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tom_superevents_base.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tom_nonlocalizedevents_base.settings')

application = get_asgi_application()
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'tom_catalogs',
'tom_observations',
'tom_dataproducts',
'tom_superevents',
'tom_nonlocalizedevents',
]

SITE_ID = 1
Expand All @@ -73,7 +73,7 @@
'tom_common.middleware.AuthStrategyMiddleware',
]

ROOT_URLCONF = 'tom_superevents_base.urls'
ROOT_URLCONF = 'tom_nonlocalizedevents_base.urls'

TEMPLATES = [
{
Expand All @@ -93,7 +93,7 @@

CRISPY_TEMPLATE_PACK = 'bootstrap4'

WSGI_APPLICATION = 'tom_superevents_base.wsgi.application'
WSGI_APPLICATION = 'tom_nonlocalizedevents_base.wsgi.application'


# Database
Expand Down
Loading

0 comments on commit 32826c2

Please sign in to comment.