@redirect_legacy_projects
def q_edit_new(request, project_name=None, ontology_key=None, document_type=None):
    context = add_parameters_to_context(request)
    (validity, project, ontology, model_proxy, model_customization, msg) = validate_view_arguments(project_name=project_name, ontology_key=ontology_key, document_type=document_type)
    if (not validity):
        return q_error(request, msg)
    current_user = request.user
    if project.authenticated:
        if (not current_user.is_authenticated()):
            next_page = add_parameters_to_url(reverse('account_login'), next=request.path)
            return HttpResponseRedirect(next_page)
        if (not is_user_of(current_user, project)):
            next_page = reverse('project', kwargs={'project_name': project_name})
            msg = 'You have tried to view a restricted resource for this project.  Please consider joining.'
            messages.add_message(request, messages.WARNING, msg)
            return HttpResponseRedirect(next_page)
    session_key = get_key_from_request(request)
    cached_realizations_key = '{0}_realizations'.format(session_key)
    model_realization = get_or_create_cached_object(request.session, cached_realizations_key, get_new_realizations, **{'project': project, 'ontology': ontology, 'model_proxy': model_proxy, 'key': model_proxy.name})
    if current_user.is_authenticated():
        set_owner(model_realization, evaluate_lazy_object(current_user))
    model_realization.is_root = True
    view_url_dirname = request.path.rsplit('/', 1)[0]
    api_url_dirname = reverse('realization-list').rsplit('/', 1)[0]
    template_context = {'project': project, 'ontology': ontology, 'proxy': model_proxy, 'view_url_dirname': view_url_dirname, 'api_url_dirname': api_url_dirname, 'session_key': session_key, 'customization': model_customization, 'realization': model_realization, 'read_only': 'false'}
    return render_to_response('questionnaire/q_edit.html', template_context, context_instance=context)
@redirect_legacy_projects
def q_edit_new(request, project_name=None, ontology_key=None, document_type=None):
    context = add_parameters_to_context(request)
    (validity, project, ontology, model_proxy, model_customization, msg) = validate_view_arguments(project_name=project_name, ontology_key=ontology_key, document_type=document_type)
    if (not validity):
        return q_error(request, msg)
    current_user = request.user
    if project.authenticated:
        if (not current_user.is_authenticated()):
            next_page = add_parameters_to_url(reverse('account_login'), next=request.path)
            return HttpResponseRedirect(next_page)
        if (not is_user_of(current_user, project)):
            next_page = reverse('project', kwargs={'project_name': project_name})
            msg = 'You have tried to view a restricted resource for this project.  Please consider joining.'
            messages.add_message(request, messages.WARNING, msg)
            return HttpResponseRedirect(next_page)
    session_key = get_key_from_request(request)
    cached_realizations_key = '{0}_realizations'.format(session_key)
    model_realization = get_or_create_cached_object(request.session, cached_realizations_key, get_new_realizations, **{'project': project, 'ontology': ontology, 'model_proxy': model_proxy, 'key': model_proxy.name})
    if current_user.is_authenticated():
        set_owner(model_realization, evaluate_lazy_object(current_user))
    model_realization.is_root = True
    view_url_dirname = request.path.rsplit('/', 1)[0]
    api_url_dirname = reverse('realization-list').rsplit('/', 1)[0]
    template_context = {'project': project, 'ontology': ontology, 'proxy': model_proxy, 'view_url_dirname': view_url_dirname, 'api_url_dirname': api_url_dirname, 'session_key': session_key, 'customization': model_customization, 'realization': model_realization, 'read_only': 'false'}
    return render_to_response('questionnaire/q_edit.html', template_context, context_instance=context)