def view(self, request, application, label, roles, actions):
        """ Django view method. """
        if 'ajax' in request.POST:
            resp = self.handle_ajax(request, application)
            return HttpResponse(
                json.dumps(resp), content_type="application/json")

        form_models = {
            'common': forms.CommonApplicationForm,
            'new': forms.NewProjectApplicationForm,
            'existing': forms.ExistingProjectApplicationForm,
        }

        project_forms = {}

        for key, form in six.iteritems(form_models):
            project_forms[key] = form(
                request.POST or None, instance=application)

        if application.project is not None:
            project_forms["common"].initial = {'application_type': 'U'}
        elif application.name != "":
            project_forms["common"].initial = {'application_type': 'P'}

        if 'application_type' in request.POST:
            at = request.POST['application_type']
            valid = True
            if at == 'U':
                # existing project
                if project_forms['common'].is_valid():
                    project_forms['common'].save(commit=False)
                else:
                    valid = False
                if project_forms['existing'].is_valid():
                    project_forms['existing'].save(commit=False)
                else:
                    valid = False

            elif at == 'P':
                # new project
                if project_forms['common'].is_valid():
                    project_forms['common'].save(commit=False)
                else:
                    valid = False
                if project_forms['new'].is_valid():
                    project_forms['new'].save(commit=False)
                else:
                    valid = False
                application.institute = application.applicant.institute

            else:
                return HttpResponseBadRequest("<h1>Bad Request</h1>")

            # reset hidden forms
            if at != 'U':
                # existing project form was not displayed
                project_forms["existing"] = (
                    form_models["existing"](instance=application))
                application.project = None
            if at != 'P':
                # new project form was not displayed
                project_forms["new"] = form_models["new"](instance=application)
                application.name = ""
                application.institute = None
                application.description = None
                application.additional_req = None
                application.machine_categories = []
                application.pid = None

            # save the values
            application.save()

            if project_forms['new'].is_valid() and at == 'P':
                project_forms["new"].save_m2m()

            # we still need to process cancel and prev even if form were
            # invalid
            if 'cancel' in request.POST:
                return "cancel"
            if 'prev' in request.POST:
                return 'prev'

            # if forms were valid, jump to next state
            if valid:
                for action in actions:
                    if action in request.POST:
                        return action
                return HttpResponseBadRequest("<h1>Bad Request</h1>")
        else:
            # we still need to process cancel, prev even if application type
            # not given
            if 'cancel' in request.POST:
                return "cancel"
            if 'prev' in request.POST:
                return 'prev'

        # lookup the project based on the form data
        project_id = project_forms['existing']['project'].value()
        project = None
        if project_id:
            try:
                project = Project.objects.get(pk=project_id)
            except Project.DoesNotExist:
                pass

        # render the response
        return render(
            template_name='kgapplications/project_aed_project.html',
            context={
                'forms': project_forms,
                'project': project,
                'actions': actions,
                'roles': roles,
                'application': application,
            },
            request=request)
def view ( self , request , application , label , roles , actions ) : if 'ajax' in request . POST : resp = self . handle_ajax ( request , application ) return HttpResponse ( json . dumps ( resp ) , content_type = "application/json" ) form_models = { 'common' : forms . CommonApplicationForm , 'new' : forms . NewProjectApplicationForm , 'existing' : forms . ExistingProjectApplicationForm , } project_forms = { } for key , form in six . iteritems ( form_models ) : project_forms [ key ] = form ( request . POST or None , instance = application ) if application . project is not None : project_forms [ "common" ] . initial = { 'application_type' : 'U' } elif application . name != "" : project_forms [ "common" ] . initial = { 'application_type' : 'P' } if 'application_type' in request . POST : at = request . POST [ 'application_type' ] valid = True if at == 'U' : if project_forms [ 'common' ] . is_valid ( ) : project_forms [ 'common' ] . save ( commit = False ) else : valid = False if project_forms [ 'existing' ] . is_valid ( ) : project_forms [ 'existing' ] . save ( commit = False ) else : valid = False elif at == 'P' : if project_forms [ 'common' ] . is_valid ( ) : project_forms [ 'common' ] . save ( commit = False ) else : valid = False if project_forms [ 'new' ] . is_valid ( ) : project_forms [ 'new' ] . save ( commit = False ) else : valid = False application . institute = application . applicant . institute else : return HttpResponseBadRequest ( "<h1>Bad Request</h1>" ) if at != 'U' : project_forms [ "existing" ] = ( form_models [ "existing" ] ( instance = application ) ) application . project = None if at != 'P' : project_forms [ "new" ] = form_models [ "new" ] ( instance = application ) application . name = "" application . institute = None application . description = None application . additional_req = None application . machine_categories = [ ] application . pid = None application . save ( ) if project_forms [ 'new' ] . is_valid ( ) and at == 'P' : project_forms [ "new" ] . save_m2m ( ) if 'cancel' in request . POST : return "cancel" if 'prev' in request . POST : return 'prev' if valid : for action in actions : if action in request . POST : return action return HttpResponseBadRequest ( "<h1>Bad Request</h1>" ) else : if 'cancel' in request . POST : return "cancel" if 'prev' in request . POST : return 'prev' project_id = project_forms [ 'existing' ] [ 'project' ] . value ( ) project = None if project_id : try : project = Project . objects . get ( pk = project_id ) except Project . DoesNotExist : pass return render ( template_name = 'kgapplications/project_aed_project.html' , context = { 'forms' : project_forms , 'project' : project , 'actions' : actions , 'roles' : roles , 'application' : application , } , request = request )
Django view method.