Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        self.object = None
        process_form = WizardFullProcessForm(request.POST, prefix='process')
        growth_info_form = WizardGrowthInfoForm(request.POST, prefix='growth')
        checklist_form = WizardPrerunChecklistForm(request.POST,
                                                   prefix='checklist')
        source_form = SourcesForm(request.POST, prefix='source')
        sample_formset = SampleFormSet(request.POST, prefix='sample')
        reservation_form = ReservationCloseForm(request.POST,
                                                prefix='reservation')

        if all([
                process_form.is_valid(),
                growth_info_form.is_valid(),
                source_form.is_valid(),
                checklist_form.is_valid(),
                sample_formset.is_valid(),
                reservation_form.is_valid()
        ]):
            logger.debug('Creating new growth')
            self.object = process_form.save()
            info = growth_info_form.save(commit=False)
            info.process = self.object
            info.save()
            logger.debug('Created process {} ({}) for {} samples'.format(
                self.object.uuid_full, self.object.legacy_identifier,
                len(sample_formset)))
            source_form.save()
            for n, s in enumerate(sample_formset):
                sample = s.save()
                logger.debug('Created sample {}'.format(sample.uuid))
                piece = s.cleaned_data['piece']
                sample.run_process(self.object, piece, n + 1)
            reservation = Reservation.get_latest(user=self.request.user,
                                                 process_type=self.object.type)
            if reservation and not reservation_form.cleaned_data['hold_open']:
                reservation.deactivate()

            return HttpResponseRedirect(reverse('create_growth_d180_readings'))
        else:
            process_form = WizardBasicProcessForm(self.request.user,
                                                  request.POST,
                                                  prefix='process')
            growth_info_form = WizardGrowthInfoForm(request.POST,
                                                    prefix='growth')
            comment_form = CommentsForm(request.POST, prefix='process')
            return self.render_to_response(
                self.get_context_data(info_form=process_form,
                                      growth_form=growth_info_form,
                                      checklist_form=checklist_form,
                                      source_form=source_form,
                                      comment_form=comment_form,
                                      sample_formset=sample_formset,
                                      reservation_form=reservation_form,
                                      reservation=Reservation.get_latest(
                                          user=self.request.user,
                                          process_type='d180-growth')))
Esempio n. 2
0
 def build_forms(self, **kwargs):
     comment_form = CommentsForm(prefix='comment',
                                 initial={
                                     'title': self.object.title,
                                     'comment': self.object.comment
                                 })
     readings = self.object.readings.get_queryset()
     readings_formset = D180ReadingsFormSet(queryset=readings,
                                            prefix='reading')
     return {
         'comment_form': comment_form,
         'readings_formset': readings_formset,
     }
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        checklist_form = WizardPostrunChecklistForm(request.POST,
                                                    prefix='checklist')
        source_form = SourcesForm(request.POST, prefix='source')
        comment_form = CommentsForm(request.POST, prefix='comment')

        if all([
                comment_form.is_valid(),
                source_form.is_valid(),
                checklist_form.is_valid()
        ]):
            self.object.comment = comment_form.cleaned_data['comment']
            self.object.title = comment_form.cleaned_data['title']
            self.object.save()
            source_form.save()
            return HttpResponseRedirect(
                reverse('process_detail', args=(self.object.uuid, )))
        else:
            return self.render_to_response(
                self.get_context_data(checklist_form=checklist_form,
                                      source_form=source_form,
                                      comment_form=comment_form))
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        comment_form = CommentsForm(request.POST, prefix='comment')
        readings = self.object.readings.get_queryset()
        readings_formset = D180ReadingsFormSet(request.POST,
                                               queryset=readings,
                                               prefix='reading')

        if comment_form.is_valid() and readings_formset.is_valid():
            if comment_form.has_changed():
                self.object.comment = comment_form.cleaned_data['comment']
                self.object.title = comment_form.cleaned_data['title']
                self.object.save()
            for reading_form in readings_formset:
                if reading_form.has_changed():
                    reading_form.save(process=self.object)
            return HttpResponseRedirect(reverse('create_growth_d180_readings'))
        else:
            return self.render_to_response(
                self.get_context_data(
                    comment_form=comment_form,
                    readings_formset=readings_formset,
                ))
Esempio n. 5
0
    def build_forms(self):
        try:
            previous_source = D180Source.objects.latest('created')
        except ObjectDoesNotExist:
            previous_source = None

        comment_form = CommentsForm(prefix='comment',
                                    initial={
                                        'title': self.object.title,
                                        'comment': self.object.comment
                                    })
        return {
            'checklist_form': WizardPostrunChecklistForm(prefix='checklist'),
            'source_form': SourcesForm(instance=previous_source,
                                       prefix='source'),
            'comment_form': comment_form,
        }
Esempio n. 6
0
    def build_forms(self):
        try:
            previous_source = D180Source.objects.latest('created')
        except ObjectDoesNotExist:
            previous_source = None

        try:
            previous_growth = (Process.objects.filter(
                type_id='d180-growth').latest('created'))
            growth_number = 'g{}'.format(
                str(int(previous_growth.legacy_identifier[1:]) + 1).zfill(4))
        except ObjectDoesNotExist:
            growth_number = 'g1000'
        except ValueError:
            growth_number = 'g1000'

        return {
            'info_form':
            WizardBasicProcessForm(initial={
                'user':
                self.request.user,
                'legacy_identifier':
                growth_number,
                'type':
                ProcessType.objects.get(type='d180-growth'),
            },
                                   user=self.request.user,
                                   prefix='process'),
            'growth_form':
            WizardGrowthInfoForm(prefix='growth'),
            'checklist_form':
            WizardPrerunChecklistForm(prefix='checklist'),
            'source_form':
            SourcesForm(instance=previous_source, prefix='source'),
            'comment_form':
            CommentsForm(prefix='process'),
            'sample_formset':
            SampleFormSet(prefix='sample'),
            'reservation_form':
            ReservationCloseForm(prefix='reservation'),
        }
Esempio n. 7
0
 def build_forms(self):
     if 'id' in self.kwargs:
         comment = ProcessTemplate.objects.get(
             id=self.kwargs.get('id', None)).comment
         process = ProcessTemplate.objects.get(
             id=self.kwargs.get('id', None)).process
     elif 'uuid' in self.kwargs:
         process = Process.objects.get(
             uuid_full__startswith=Process.strip_uuid(
                 self.kwargs.get('uuid', None)))
         comment = process.comment
     output = super(TemplateWizardStartView, self).build_forms()
     output['comment_form'] = CommentsForm(initial={'comment': comment},
                                           prefix='process')
     growth_info = {
         attr: getattr(process.info, attr)
         for attr in WizardGrowthInfoForm.Meta.fields
     }
     output['growth_form'] = WizardGrowthInfoForm(initial=growth_info,
                                                  prefix='growth')
     return output