def new_submission(request):
    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,request.FILES)
        sponsor_form = PrimarySponsorForm(request.POST)

        if initial_form.is_valid() and sponsor_form.is_valid():
            trial = ClinicalTrial()
            su = Submission(creator=request.user)

            trial.scientific_title = su.title = initial_form.cleaned_data['scientific_title']

            trial.save()
            su.save()

            trial.primary_sponsor = su.primary_sponsor = sponsor_form.save()
            trial.recruitment_country = [CountryCode.objects.get(pk=id) for id in initial_form.cleaned_data['recruitment_country']]
            su.trial = trial

            trial.save()
            su.save()

            return HttpResponseRedirect(reverse('repository.edittrial',args=[trial.id]))
    else:
        initial_form = InitialTrialForm()
        sponsor_form = PrimarySponsorForm()


    forms = [initial_form, sponsor_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms,
        'username':request.user.username,
    })
Beispiel #2
0
def new_submission(request):
    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,request.FILES)
        sponsor_form = PrimarySponsorForm(request.POST)

        if initial_form.is_valid() and sponsor_form.is_valid():
            trial = ClinicalTrial()
            su = Submission(creator=request.user)
            su.language = initial_form.cleaned_data['language']
            su.title = initial_form.cleaned_data['scientific_title']
            if su.language == 'en':
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation()
                ctt.language = su.language
                ctt.scientific_title = su.title
                trial.translations.add(ctt)

            trial.save()
            su.save()
            
            sponsor = sponsor_form.save(commit=False)
            sponsor.creator = request.user
            sponsor.save()
            
            trial.primary_sponsor = su.primary_sponsor = sponsor
            trial.recruitment_country = [CountryCode.objects.get(pk=id) for id in initial_form.cleaned_data['recruitment_country']]
            su.trial = trial

            trial.save()
            su.save()
            
            # sets the initial status of the fields
            fields_status = {}
            FIELDS = {
                TRIAL_FORMS[0]: MISSING, TRIAL_FORMS[1]: PARTIAL, TRIAL_FORMS[2]: MISSING,
                TRIAL_FORMS[3]: MISSING, TRIAL_FORMS[4]: MISSING, TRIAL_FORMS[5]: MISSING, 
                TRIAL_FORMS[6]: MISSING, TRIAL_FORMS[7]: MISSING, TRIAL_FORMS[8]: PARTIAL
            }
            for lang in su.get_mandatory_languages():
                lang = lang.lower()
                fields_status.update({lang: dict(FIELDS)})
                if lang == su.language.lower():
                    fields_status[lang].update({TRIAL_FORMS[0]: PARTIAL})
            
            su.fields_status = pickle.dumps(fields_status)
            su.save()

            return HttpResponseRedirect(reverse('repository.edittrial',args=[trial.id]))
    else:
        initial_form = InitialTrialForm(user=request.user)
        sponsor_form = PrimarySponsorForm()

    forms = [initial_form, sponsor_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms },
        context_instance=RequestContext(request))