Skip to content
Snippets Groups Projects
Commit bd6b3021 authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

add PCR field edition view

parent 5e2926ce
No related branches found
No related tags found
2 merge requests!13Edit view job,!7Simulator
import insillyclo.main
from crispy_forms import layout
from crispy_forms.helper import FormHelper
from django import forms
......@@ -5,7 +6,7 @@ from django.forms import modelformset_factory
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
from assemblies.models import Assembly, InputPart
from assemblies.models import Assembly, InputPart, SimulatorJob
SEP_CHOICES = (
(".", "Dot"),
......@@ -54,6 +55,31 @@ class SimulatorDataForm(forms.Form):
)
class PCRModelForm(forms.ModelForm):
class Meta:
model = SimulatorJob
fields = ('pcr_pairs_str',)
helper = FormHelper()
helper.form_tag = False
primers_file = forms.FileField(
required=False,
label=_('Primers file'),
help_text=_('A CSV file where the header is \"primerId;sequence\".\nNote that the separator is \";\".'),
)
def save(self, commit=True):
instance: SimulatorJob = super().save(commit=commit)
if not commit or self.cleaned_data['primers_file'] is None:
return instance
output_fp = instance.job_dir / insillyclo.main.DEFAULT_CONCENTRATIONS_FILENAME
with open(output_fp, 'wb') as fh:
for chunk in self.cleaned_data['primers_file'].chunks():
fh.write(chunk)
return instance
class AssemblyForm(forms.ModelForm):
class Meta:
model = Assembly
......
......@@ -68,6 +68,7 @@ urlpatterns = [
path('assembly-simulator/create/<str:step>/', simulator_wizard, name='simulator-create-step'),
path('assembly-simulator/create/', simulator_wizard, name='simulator-create'),
path('assembly-simulator/<slug:uuid>/', views.JobSimulatorResult.as_view(), name='simulator-detail'),
path('assembly-simulator-job/<slug:uuid>/pcr/', views.JobPCREdit.as_view(), name='simulator-pcr-edit'),
path('assembly/<int:pk>/download/', views.AssemblyDetailDownloadView.as_view(), name='assembly-download'),
path('assembly/<int:pk>/delete/', views.AssemblyDeleteView.as_view(), name='assembly-delete'),
path('fragment', views.show_fragment, name='fragment'),
......
......@@ -7,7 +7,7 @@ from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import ListView, DetailView, View, DeleteView
from django.views.generic import ListView, DetailView, View, DeleteView, UpdateView
from django.views.generic.detail import SingleObjectMixin
from . import mixins
......@@ -114,3 +114,23 @@ class JobSimulatorResult(DetailView):
model = models.SimulatorJob
slug_field = 'uuid'
slug_url_kwarg = 'uuid'
class JobPCREdit(
UpdateView,
):
model = models.SimulatorJob
form_class = forms.PCRModelForm
slug_field = 'uuid'
slug_url_kwarg = 'uuid'
success_url = reverse_lazy("assemblies:home")
template_name = "assemblies/form_host.html"
def form_valid(self, form):
self.object.run_simulator()
return super().form_valid(form)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = _("PCR primers to use for gel simulation")
return context
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment