From 2620d66509038ab73e00dae243d215e9c943f22c Mon Sep 17 00:00:00 2001 From: Tanner Prestegard <tanner.prestegard@ligo.org> Date: Tue, 7 Nov 2017 10:11:47 -0600 Subject: [PATCH] allowing events to be searchable by offline status --- gracedb/forms.py | 6 ++++++ gracedb/views.py | 29 ++++++++++------------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/gracedb/forms.py b/gracedb/forms.py index 6458883f5..7341c2aaf 100644 --- a/gracedb/forms.py +++ b/gracedb/forms.py @@ -79,6 +79,12 @@ class EventSearchForm(forms.Form): required=False) get_neighbors = forms.BooleanField(required=False) + offline = forms.NullBooleanField( + required=False, + help_text=("Select \"Unknown\" to search for both online and offline " + "events.") + ) + class SignoffForm(ModelForm): class Meta: model = Signoff diff --git a/gracedb/views.py b/gracedb/views.py index afb52eb88..89df60bfe 100644 --- a/gracedb/views.py +++ b/gracedb/views.py @@ -581,9 +581,14 @@ def oldsearch(request): gpsStart = form.cleaned_data['gpsStart'] gpsEnd = form.cleaned_data['gpsEnd'] get_neighbors = form.cleaned_data['get_neighbors'] + offline = form.cleaned_data['offline'] textQuery = [] + # XXX: this whole thing could be redone by defining Q objects + # and doing a single query. I think that might simplify the + # database queries. (Tanner) + if not groupname: # don't show test events unless explicitly requested # Scales? Or should we find test group and do group= ? @@ -591,25 +596,6 @@ def oldsearch(request): else: objects = Event.objects.all() - # XXX Note, the uid field doesn't exist anymore. I'm not sure why this - # stuff is in here. (Branson) -# if start: -# if start[0] != 'G': -# # XXX This is the deprecated uid stuff. Take it out when uid is gone. -# objects = objects.filter(uid__gte=start) -# objects = objects.filter(uid__startswith="0") -# else: -# objects = objects.filter(id__gte=int(start[1:])) -# objects = objects.filter(uid="") -# if end: -# if end[0] != 'G': -# # XXX This is the deprecated uid stuff. Take it out when uid is gone. -# objects = objects.filter(uid__lte=end) -# objects = objects.filter(uid__startswith="0") -# else: -# objects = objects.filter(id__lte=int(end[1:])) -# objects = objects.filter(uid="") - if start: if start[0] in 'GEHMT': objects = objects.filter(id__gte=int(start[1:])) @@ -669,6 +655,11 @@ def oldsearch(request): # Need this because events with multiple labels can appear multiple times! objects = objects.distinct() + # Offline + if offline is not None: + objects = objects.filter(offline=offline) + textQuery.append("offline: \"{0}\"".format(offline)) + # Filter for user. objects = filter_events_for_user(objects, request.user, 'view') -- GitLab