Exemple #1
0
    def post(self, request, *args, **kwargs):
        layer_formset = self.get_layer_formset()(request.POST, prefix="layers")
        matrix_form = self.get_form(self.form_class)
        ChainFormset = formset_factory(ChainForm)
        chain_formset = ChainFormset(request.POST, prefix="chains")

        virus = Virus.objects.get(entry_id=self.request.session['entry_id'])

        self.mismatched_chains = get_mismatched_chains(virus.entry_key)
        self.viperize_matrix = self.get_viperize_matrix(virus.pk)

        if (matrix_form.is_valid() and chain_formset.is_valid() and 
            layer_formset.is_valid()):
            return self.form_valid(request, virus, matrix_form, chain_formset, 
                                   layer_formset)
        else:
            return self.form_invalid(request, virus, matrix_form, chain_formset, 
                                     layer_formset)
Exemple #2
0
    def get_context_data(self, **kwargs):
        virus = Virus.objects.get(entry_id=self.request.session['entry_id'])
        self.viperize_matrix = self.get_viperize_matrix(virus.pk)
        mismatched_chains = get_mismatched_chains(virus.entry_key)

        layer_formset = self.get_layer_formset()(prefix='layers')
        ChainFormset = formset_factory(ChainForm, extra=len(mismatched_chains))

        chain_formset = ChainFormset(prefix="chains")
        for index, chain_form in enumerate(chain_formset):
            chain_form.chain = mismatched_chains[index]

        kwargs = super(StepThreeView, self).get_context_data(**kwargs)
        kwargs.update({
            'layer_formset': layer_formset,
            'entry_id': self.request.session['entry_id'],
            'viperize_matrix': make_2d_matrix(self.viperize_matrix, with_vector=True),
            'unit_matrix': make_2d_matrix(self.unit_matrix, with_vector=True),
            'chain_formset': chain_formset,
            'matrix_form': self.get_form(self.form_class),
        })
        return kwargs