Commit 92982a99 authored by Samuel GAIST's avatar Samuel GAIST

[databases][signals] Handle both v1 adn v2 databases when refreshing protocols

The handling is a bit different but it allows
to currently use the same infrastructure untouched
for experiment execution.
parent c578694a
......@@ -29,7 +29,9 @@
from django.db import models
from django.dispatch import receiver
from ..common.utils import annotate_full_name
from ..dataformats.models import DataFormat
from ..protocoltemplates.models import ProtocolTemplate
from .models import Database
from .models import DatabaseProtocol
from .models import DatabaseSet
......@@ -89,7 +91,6 @@ def refresh_protocols(sender, instance, **kwargs):
"""Refreshes changed protocols"""
try:
core = validate_database(instance.declaration)
core.name = instance.fullname()
......@@ -112,10 +113,31 @@ def refresh_protocols(sender, instance, **kwargs):
json_protocol = json_protocols[protocol_name]
# creates all the template sets, outputs, etc for the first time
for set_attr in json_protocol["sets"]:
set_data_list = []
for set_name, set_attr in core.sets(protocol_name).items():
set_data = {
# V1 has a dedicated template name while V2 has one unique
# name
"template": set_attr.get("template", set_name),
"name": set_attr["name"],
"outputs": set_attr["outputs"],
}
set_data_list.append(set_data)
for set_attr in set_data_list:
template_name = json_protocol["template"]
try:
protocol_template = annotate_full_name(
ProtocolTemplate.objects
).get(full_name=template_name)
except ProtocolTemplate.DoesNotExist:
pass
else:
protocol_template.databases.add(instance)
tset_name = json_protocol["template"] + "__" + set_attr["template"]
tset_name = template_name + "__" + set_attr["template"]
dataset_template, _ = DatabaseSetTemplate.objects.get_or_create(
name=tset_name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment