Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IGWN Computing and Software
GraceDB
GraceDB Server
Commits
ec1444a1
Commit
ec1444a1
authored
7 years ago
by
Tanner Prestegard
Committed by
gracedb-dev1
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
updating api and associated event creation functions to allow events to be created with labels
parent
e65f9815
No related branches found
No related tags found
1 merge request
!3
Allow events to be created with labels
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gracedb/api.py
+3
-2
3 additions, 2 deletions
gracedb/api.py
gracedb/forms.py
+4
-2
4 additions, 2 deletions
gracedb/forms.py
gracedb/view_logic.py
+36
-1
36 additions, 1 deletion
gracedb/view_logic.py
with
43 additions
and
5 deletions
gracedb/api.py
+
3
−
2
View file @
ec1444a1
...
...
@@ -12,7 +12,7 @@ import json
from
django.contrib.auth.models
import
User
,
Permission
from
django.contrib.auth.models
import
Group
as
AuthGroup
from
django.contrib.contenttypes.models
import
ContentType
from
gracedb.models
import
Event
,
Group
,
Search
,
Pipeline
,
EventLog
,
Tag
from
gracedb.models
import
Event
,
Group
,
Search
,
Pipeline
,
EventLog
,
Tag
,
Label
from
gracedb.models
import
EMGroup
,
EMBBEventLog
,
EMSPECTRUM
#from gracedb.models import EMObservation, EMFootprint
from
gracedb.models
import
VOEvent
...
...
@@ -508,7 +508,7 @@ class EventList(APIView):
status
=
status
.
HTTP_400_BAD_REQUEST
)
if
not
user_has_perm
(
request
.
user
,
"
populate
"
,
pipeline
):
return
HttpResponseForbidden
(
"
You don
'
t have permission on this pipeline.
"
)
# The following looks a bit funny but it is actually necessary. The
# django form expects a dict containing the POST data as the first
# arg, and a dict containing the FILE data as the second. In the
...
...
@@ -1561,6 +1561,7 @@ class GracedbRoot(APIView):
"
groups
"
:
[
group
.
name
for
group
in
Group
.
objects
.
all
()],
"
pipelines
"
:
[
pipeline
.
name
for
pipeline
in
Pipeline
.
objects
.
all
()],
"
searches
"
:
[
search
.
name
for
search
in
Search
.
objects
.
all
()],
"
labels
"
:
[
label
.
name
for
label
in
Label
.
objects
.
all
()],
"
em-groups
"
:
[
g
.
name
for
g
in
EMGroup
.
objects
.
all
()],
"
wavebands
"
:
dict
(
EMSPECTRUM
),
"
eel-statuses
"
:
dict
(
EMBBEventLog
.
EEL_STATUS_CHOICES
),
...
...
This diff is collapsed.
Click to expand it.
gracedb/forms.py
+
4
−
2
View file @
ec1444a1
...
...
@@ -48,11 +48,13 @@ class CreateEventForm(forms.Form):
#typeChoices= [("","")]+list(Event.ANALYSIS_TYPE_CHOICES)
pipelineChoices
=
[(
""
,
""
)]
+
[(
p
.
name
,
p
.
name
)
for
p
in
Pipeline
.
objects
.
all
()]
searchChoices
=
[(
""
,
""
)]
+
[(
s
.
name
,
s
.
name
)
for
s
in
Search
.
objects
.
all
()]
eventFile
=
forms
.
FileField
()
eventFile
=
forms
.
FileField
()
group
=
forms
.
ChoiceField
(
groupChoices
)
pipeline
=
forms
.
ChoiceField
(
pipelineChoices
)
search
=
forms
.
ChoiceField
(
searchChoices
,
required
=
False
)
# List of labels as a comma-separated string
labels
=
forms
.
CharField
(
required
=
False
)
#type = forms.ChoiceField(choices=typeChoices)
...
...
This diff is collapsed.
Click to expand it.
gracedb/view_logic.py
+
36
−
1
View file @
ec1444a1
...
...
@@ -35,7 +35,7 @@ from django.utils import timezone
import
logging
import
pytz
logger
=
logging
.
getLogger
(
'
gracedb.view_logic
'
)
logger
=
logging
.
getLogger
(
__name__
)
def
_createEventFromForm
(
request
,
form
):
saved
=
False
...
...
@@ -44,6 +44,7 @@ def _createEventFromForm(request, form):
group
=
Group
.
objects
.
get
(
name
=
form
.
cleaned_data
[
'
group
'
])
pipeline
=
Pipeline
.
objects
.
get
(
name
=
form
.
cleaned_data
[
'
pipeline
'
])
search_name
=
form
.
cleaned_data
[
'
search
'
]
label_str
=
form
.
cleaned_data
[
'
labels
'
]
if
search_name
:
search
=
Search
.
objects
.
get
(
name
=
form
.
cleaned_data
[
'
search
'
])
else
:
...
...
@@ -120,6 +121,40 @@ def _createEventFromForm(request, form):
temp_data_loc
,
translator_warnings
=
handle_uploaded_data
(
event
,
uploadDestination
,
file_contents
=
file_contents
)
warnings
+=
translator_warnings
# Add labels here - need event to have been saved already
for
label
in
label_str
.
split
(
"
,
"
):
# Handle case where no labels are sent (labels=[] in
# gracedb-client), here label_str.split(",") will be [""]
if
not
label
:
break
# Try to get label from database. gracedb-client has a test for
# this, but we should have a safeguard on the server.
try
:
label_obj
=
Label
.
objects
.
get
(
name
=
label
)
except
Label
.
DoesNotExist
:
msg
=
"
Label {0} does not exist and was not applied
"
\
.
format
(
label
)
warnings
.
append
(
msg
)
continue
# If event already has this label, don't do anything.
# Append a warning message.
if
label_obj
in
event
.
labels
.
all
():
warnings
.
append
(
"
Event {0} already labeled with
'
{1}
'"
\
.
format
(
event
.
graceid
(),
label
))
else
:
# Otherwise, create label
labelling
=
Labelling
(
event
=
event
,
label
=
label_obj
,
creator
=
event
.
submitter
)
labelling
.
save
()
# Create log message about label
message
=
"
Event created with label: {0}
"
.
format
(
label
)
log
=
EventLog
(
event
=
event
,
issuer
=
event
.
submitter
,
comment
=
message
)
log
.
save
()
try
:
# Send an alert.
# XXX This reverse will give the web-interface URL, not the REST URL.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment