Exemplo n.º 1
0
def new_application(request):
    """ A new application by a user to start a new project. """
    # Note default applications/index.html will display error if user logged
    # in.
    if not settings.ALLOW_REGISTRATIONS:
        return render_to_response(
            'applications/project_common_disabled.html',
            {},
            context_instance=RequestContext(request))

    if not request.user.is_authenticated():
        form = forms.UnauthenticatedInviteUserApplicationForm(
            request.POST or None)
        if request.method == 'POST':
            if form.is_valid():
                email = form.cleaned_data['email']
                applicant, existing_person = get_applicant_from_email(email)
                assert not existing_person

                application = ProjectApplication()
                application.applicant = applicant
                application.save()

                state_machine = get_application_state_machine()
                state_machine.start(
                    request, application, {'is_applicant': True})
                # we do not show unauthenticated users the application at this
                # stage.
                url = reverse('index')
                return HttpResponseRedirect(url)
        return render_to_response(
            'applications/project_common_invite_unauthenticated.html',
            {'form': form, },
            context_instance=RequestContext(request))
    else:
        if request.method == 'POST':
                person = request.user

                application = ProjectApplication()
                application.applicant = person
                application.save()

                state_machine = get_application_state_machine()
                response = state_machine.start(
                    request, application, {'is_applicant': True})
                return response
        return render_to_response(
            'applications/project_common_invite_authenticated.html',
            {},
            context_instance=RequestContext(request))
Exemplo n.º 2
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))