Ejemplo n.º 1
0
def projectapplication_existing(request, application_form=ProjectApplicationForm, mc=MachineCategory.objects.get_default()):

    application = ProjectApplication()
    applicant = request.user.get_profile()
    init_institute = request.GET.get('institute', '')

    if request.method == 'POST':
        form = application_form(request.POST, instance=application)

        if form.is_valid():
            application = form.save(commit=False)
            application.applicant = applicant
            application.save()
            application.submitted_date = datetime.datetime.now()
            application.state = Application.WAITING_FOR_DELEGATE
            application.save()
            application.machine_categories.add(mc)
            send_project_request_email(application)
            return HttpResponseRedirect(reverse('kg_application_done', args=[application.secret_token]))
    else:
        form = application_form(instance=application, initial={'institute': init_institute})
    
    return render_to_response('applications/projectapplication_existing_form.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def do_projectapplication(request, token=None, application_form=ProjectApplicationForm,
                          mc=MachineCategory.objects.get_default(), saml=False):

    if request.user.is_authenticated():
        messages.warning(request, "You are already logged in")
        return HttpResponseRedirect(reverse('kg_user_profile'))

    if saml:
        response = ensure_shib_session(request)
        if response:
            return response

    if token:
        application = get_object_or_404(ProjectApplication, secret_token=token)
        if application.state not in (Application.NEW, Application.OPEN):
            raise Http404
        applicant = application.applicant
        application.state = Application.OPEN
        application.save()
        captcha = False
    else:
        if not settings.ALLOW_REGISTRATIONS:
            return render_to_response('applications/registrations_disabled.html', {}, context_instance=RequestContext(request))
        application = None
        applicant = None
        captcha = True

    if saml:
        captcha = False
        saml_user = get_saml_user(request)
    else:
        saml_user = None
    init_institute = request.GET.get('institute', '')
    if request.method == 'POST':
        form = application_form(request.POST, instance=application, captcha=captcha)
        if saml:
            applicant_form = SAMLApplicantForm(request.POST, instance=applicant)
        else:
            applicant_form = UserApplicantForm(request.POST, instance=applicant)

        if form.is_valid() and applicant_form.is_valid():
            applicant = applicant_form.save(commit=False)
            if saml:
                applicant = add_saml_data(applicant, request)
                applicant.email_verified = True
            applicant.save()
            application = form.save(commit=False)
            application.applicant = applicant
            application.submitted_date = datetime.datetime.now()
            application.state = Application.WAITING_FOR_DELEGATE
            application.save()
            application.machine_categories.add(mc)
            send_project_request_email(application)
            return HttpResponseRedirect(reverse('kg_application_done', args=[application.secret_token]))
    else:
        form = application_form(instance=application, captcha=captcha, initial={'institute': init_institute})
        if saml:
            applicant_form = SAMLApplicantForm(instance=applicant)
        else:
            applicant_form = UserApplicantForm(instance=applicant, initial={'institute': init_institute})

    return render_to_response(
        'applications/projectapplication_form.html',
        {'form': form, 'applicant_form': applicant_form, 'application': application, 'saml': saml, 'saml_user': saml_user},
        context_instance=RequestContext(request))