Commit b9c3bc01 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

Removing dead code

parent 712b4d1c
......@@ -357,24 +357,6 @@ def import_file(*, data_source, file, importation_observer: ImportationObserver
return data_source
def merge_entries(entry_to_keep, entry_to_merge):
if type(entry_to_keep) != type(entry_to_merge):
raise ValueError("Can't merge entries with different type")
if isinstance(entry_to_keep, models.Host):
key = "host"
elif isinstance(entry_to_keep, models.Virus):
key = "virus"
else:
raise ValueError("Can't merge entries of type %s" % type(entry_to_keep))
for o in entry_to_merge.responseindatasource.all():
setattr(o, key, entry_to_keep)
o.save()
for o in entry_to_merge.data_source.all():
entry_to_keep.data_source.add(o)
entry_to_merge.delete()
return entry_to_keep
def reset_mapping(queryset):
not_mapped_yet = models.GlobalViralHostResponseValue.get_not_mapped_yet()
for o in queryset:
......
......@@ -13,7 +13,6 @@ from crispy_forms.layout import HTML, Layout, Row, Column
from django import forms
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import Q, Min, Max
from django.forms import widgets
from django.utils import timezone
......@@ -1245,19 +1244,6 @@ class LiveInputVirusHostForm(forms.Form):
sample_path=os.path.join(settings.MEDIA_ROOT, filename + ".sample.xlsx"),
)
@transaction.atomic
def save(self, data_source):
for key, its_class in (("host", models.Host), ("virus", models.Virus),):
for name, identifier in self.get_as_list(key):
try:
# search obj in db
obj = its_class.objects.filter(name=name, identifier=identifier)[0]
except IndexError:
# create obj in db
obj = its_class.objects.create(name=name, identifier=identifier)
obj.data_source.add(data_source)
obj.save()
class ResponseUpdateForm(forms.ModelForm):
# virus = forms.HiddenInput()
......
......@@ -397,26 +397,6 @@ class MergeTestCase(TestCase):
models.Virus.objects.update(identifier="")
models.Host.objects.update(identifier="")
def test_distinct_type_fails(self):
self.assertRaises(
ValueError,
business_process.merge_entries,
self.three_reponse_simple,
self.three_reponse_simple.virus_set.first(),
)
self.assertRaises(
ValueError,
business_process.merge_entries,
self.three_reponse_simple,
self.three_reponse_simple.host_set.first(),
)
self.assertRaises(
ValueError,
business_process.merge_entries,
self.three_reponse_simple.virus_set.first(),
self.three_reponse_simple.host_set.first(),
)
class ResetMappingTestCase(ViewTestCase):
def test_reset_mapping_ok(self):
......
......@@ -1063,9 +1063,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
def upload_data(self):
return self.get_upload_or_live_input() == 'upload'
def template_data(self):
return self.get_upload_or_live_input() == 'template'
def live_template_data(self):
return self.get_upload_or_live_input() == 'live'
......@@ -1077,7 +1074,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
("Description", forms.DataSourceDescriptionModelForm),
("UploadOrLiveInput", forms.UploadOrLiveInput),
("Upload", forms.UploadDataSourceForm),
("Template", forms.UploadDataSourceForm),
("LiveInput", forms.LiveInputVirusHostForm),
("LiveTemplate", forms.UploadDataSourceForm),
]
......@@ -1086,7 +1082,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
"LiveInput": live_input,
"LiveTemplate": live_template_data,
"Upload": upload_data,
"Template": template_data,
}
template_name = 'viralhostrangedb/wizard_form.html'
file_storage = storage.FileSystemStorage(location=os.path.join(tempfile.gettempdir(), 'viralhostrangedb_wizard'))
......@@ -1100,7 +1095,7 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
context["title"] = _("Provide a new data source")
if step is None:
step = self.steps.current
if step == "Upload" or step == "LiveTemplate" or step == "Template":
if step == "Upload" or step == "LiveTemplate":
context["submit_text"] = _("Save")
elif step == "UploadOrLiveInput":
context["submit_text"] = _("Proceed")
......@@ -1133,26 +1128,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
context["step_message"] = self.get_decorated_message_with_table_example(
ugettext("step_message_Upload%(scheme)s") % dict(scheme=self.compute_scheme())
)
elif step == "Template":
context["step_message"] = mark_safe(
ugettext(
"step_message_Template%(template_file_url)s%(scheme)s%(table_template)s%(table_example)s") %
dict(
scheme=self.compute_scheme(),
template_file_url=static('/media/template.xlsx'),
table_template="".join(self.get_table_for_file(
file_path=os.path.join(settings.STATIC_ROOT, 'media/template.xlsx'),
legend=_("Fig 1: the template<br/>"),
download_message=ugettext('download template file'),
use_color=False,
)),
table_example="".join(self.get_table_for_file(
file_path=os.path.join(settings.STATIC_ROOT, 'media/example.xlsx'),
legend=_("Fig 2: How the template could be filled<br/>"),
use_color=False,
)),
)
)
elif step == "LiveInput":
if form.is_bound:
context["step_message"] = mark_safe(_("step_message_LiveInput when is_bound"))
......@@ -1165,27 +1140,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
f = self.get_form("LiveInput", self.storage.get_step_data("LiveInput"))
f.is_valid()
templates = f.get_template_files()
context["step_message"] = mark_safe(
ugettext(
"step_message_LiveTemplate%(template_file_url)s%(scheme)s%(table_template)s%(table_example)s") %
dict(
scheme=self.compute_scheme(),
template_file_url=static('/media/template.xlsx'),
table_template="".join(self.get_table_for_file(
file_path=templates["sample_path"],
file_url=templates["file_url"],
legend=_("Fig 1: A (subset of) your template<br/>"),
download_message=ugettext('download template file'),
use_color=False,
)),
table_example="".join(self.get_table_for_file(
file_path=os.path.join(settings.STATIC_ROOT, 'media/example.xlsx'),
legend="Fig 2: How the template could be fillede<br/>",
use_color=False,
)),
)
)
context["step_message"] = self.get_decorated_message_with_table_example(
ugettext("step_message_LiveTemplate%(scheme)s%(template_file_url)s") % dict(
scheme=self.compute_scheme(),
......@@ -1223,14 +1177,10 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
@staticmethod
def get_table_for_file(file_path, file_url=None, legend="", download_message=None, use_color=True):
table = None
try:
vhrs_dict = business_process.to_dict(
business_process.parse_file(file_path),
transposed=True,
)
except FileNotFoundError:
vhrs_dict = {}
table = []
vhrs_dict = business_process.to_dict(
business_process.parse_file(file_path),
transposed=True,
)
hosts = []
for v, h_r in vhrs_dict.items():
for h, r in h_r.items():
......@@ -1306,13 +1256,10 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
form_dict["Visibility"].save()
else:
form_dict["Information"].save()
# if self.upload_data() or self.template_data():
if self.upload_data():
key = "Upload"
elif self.live_template_data():
else: # if self.live_template_data():
key = "LiveTemplate"
else:
key = "Template"
form_dict[key].save(importation_observer=MessageImportationObserver(request=self.request))
url = reverse("viralhostrangedb:data-source-mapping-edit", args=[self.instance.pk])
......@@ -1324,11 +1271,6 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
)),
)
return HttpResponseRedirect(url)
# else:
# self.instance.save()
# form_dict["LiveInput"].save(data_source=self.instance)
# return redirect(reverse("viralhostrangedb:data-source-detail", args=[self.instance.pk]))
def response_update(request, ds_pk, virus_pk, host_pk):
......
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