<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def process( self, request, application, expected_state, label, extra_roles=None):
 """ Process the view request at the current state. """


        # Get the authentication of the current user
        roles = self._get_roles_for_request(request, application)
        if extra_roles is not None:
            roles.update(extra_roles)

        # Ensure current user is authenticated. If user isn't applicant,
        # leader, delegate or admin, they probably shouldn't be here.
        if 'is_authorised' not in roles:
            return HttpResponseForbidden('<h1>Access Denied</h1>')

        # If user didn't supply state on URL, redirect to full URL.
        if expected_state is None:
            url = get_url(request, application, roles, label)
            return HttpResponseRedirect(url)

        # Check that the current state is valid.
        if application.state not in self._config:
            raise RuntimeError("Invalid current state '%s'" % application.state)

        # If state user expected is different to state we are in, warn user
        # and jump to expected state.
        if expected_state != application.state:
            # post data will be lost
            if request.method == "POST":
                messages.warning(
                    request,
                    "Discarding request and jumping to current state.")
            # note we discard the label, it probably isn't relevant for new
            # state
            url = get_url(request, application, roles)
            return HttpResponseRedirect(url)

        # Get the current state for this application
        state_config = self._config[application.state]

        # Finally do something
        instance = load_state_instance(state_config)
        if request.method == "GET":
            # if method is GET, state does not ever change.
            response = instance.get_next_config(request, application, label, roles)
            assert isinstance(response, HttpResponse)
            return response

        elif request.method == "POST":
            # if method is POST, it can return a HttpResponse or a string
            response = instance.get_next_config(request, application, label, roles)
            if isinstance(response, HttpResponse):
                # If it returned a HttpResponse, state not changed, just
                # display
                return response
            else:
                # If it returned a string, lookit up in the actions for this
                # state
                next_config = response
                # Go to the next state
                return self._next(request, application, roles, next_config)

        else:
            # Shouldn't happen, user did something weird
            return HttpResponseBadRequest("<h1>Bad Request</h1>")