Skip to content

Commit

Permalink
generalize nomenclature from Superevent to NonlocalizedEvent
Browse files Browse the repository at this point in the history
This commit includes:
 * the project-level urlpattern path
 * the app_name namespace and it's {% url %} references
 * the DRF registered router for this app
 * the Django and DRF View and ViewSet class names and their references
  • Loading branch information
phycodurus committed Feb 3, 2022
1 parent 640f000 commit b2e82da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tom_superevents/templates/tom_superevents/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>Non-Localized Event Index</h1>
{% for event in object_list %}
<tr>
<td scope="row">
<a href="{% url 'superevents:detail' event.id %}">{{ event.id }}</a>
<a href="{% url 'nonlocalizedevents:detail' event.id %}">{{ event.id }}</a>
</td>
<td>
<a href="{{ event.superevent_url }}">{{ event.superevent_id }}</a>
Expand Down
10 changes: 5 additions & 5 deletions tom_superevents/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'),
]
29 changes: 24 additions & 5 deletions tom_superevents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@
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'


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'

Expand All @@ -23,6 +34,9 @@ class SupereventDetailView(DetailView):
Superevent.SupereventType.GAMMA_RAY_BURST: 'tom_superevents/superevent_detail/gamma_ray_burst.html',
Superevent.SupereventType.NEUTRINO: 'tom_superevents/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 +63,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 +110,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
2 changes: 1 addition & 1 deletion tom_superevents_base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

urlpatterns = [
path('', include('tom_common.urls')),
path('superevents/', include('tom_superevents.urls')),
path('nonlocalizedevents/', include('tom_superevents.urls')),
]

0 comments on commit b2e82da

Please sign in to comment.