Esempio n. 1
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))
Esempio n. 2
0
def new_submission(request):

    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,
                                        request.FILES,
                                        user=request.user)

        if initial_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']
            su.primary_sponsor = initial_form.cleaned_data['primary_sponsor']

            trial.utrn_number = initial_form.cleaned_data['utrn_number']
            trial.language = settings.DEFAULT_SUBMISSION_LANGUAGE
            trial.primary_sponsor = su.primary_sponsor

            if su.language == settings.DEFAULT_SUBMISSION_LANGUAGE:
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation.objects.get_translation_for_object(
                    su.language, trial, create_if_not_exist=True)
                ctt.scientific_title = su.title
                ctt.save()

            trial.save()

            for country in initial_form.cleaned_data['recruitment_country']:
                trial.recruitment_country.add(
                    country)  # What about the removed ones? FIXME
            su.trial = trial

            trial.save()
            su.save()

            # sets the initial status of the fields
            su.init_fields_status()

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

    forms = [initial_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms,
    },
                              context_instance=RequestContext(request))
Esempio n. 3
0
def new_submission(request):

    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST, request.FILES, user=request.user)

        if initial_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']
            su.primary_sponsor = initial_form.cleaned_data['primary_sponsor']
            su.status = STATUS_DRAFT

            trial.utrn_number = initial_form.cleaned_data['utrn_number']
            trial.language = settings.DEFAULT_SUBMISSION_LANGUAGE
            trial.primary_sponsor = su.primary_sponsor

            if su.language == settings.DEFAULT_SUBMISSION_LANGUAGE:
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation.objects.get_translation_for_object(
                        su.language, trial, create_if_not_exist=True
                        )
                ctt.scientific_title = su.title
                ctt.save()

            trial.save()

            for country in initial_form.cleaned_data['recruitment_country']:
                trial.recruitment_country.add(country) # What about the removed ones? FIXME
            su.trial = trial

            trial.save()
            su.save()

            # sets the initial status of the fields
            su.init_fields_status()

            log_actions(request.user,'Created a submission')

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

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