@redirect_legacy_projects
def q_get_existing(request, project_name=None, ontology_key=None, document_type=None):
    '\n    this is meant to be used from external requests (ie: further_info_url)\n    where uniquely identifying model fields (including pk) are passed\n    if a unique realization cannot be found then an error is returned\n    otherwise the response is routed to "q_edit_existing"\n    :param request:\n    :param project_name:\n    :param ontology_key:\n    :param document_type:\n    :param realization_pk:\n    :return:\n    '
    (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)
    model_realizations = QModelRealization.objects.filter(project=project, proxy=model_proxy)
    additional_parameters = request.GET.copy()
    for (key, value) in additional_parameters.iteritems():
        if ((key == 'pk') or (key == 'guid')):
            try:
                return HttpResponseRedirect(reverse('edit_existing', kwargs={'project_name': project_name, 'ontology_key': ontology_key, 'document_type': document_type, 'realization_pk': model_realizations.get(**{key: value}).pk}))
            except (ObjectDoesNotExist, ValueError):
                msg = "There is no '{0}' document with a {1} of '{2}'".format(model_proxy, key, value)
                return q_error(request, msg)
        else:
            try:
                property_proxy = model_proxy.property_proxies.get(name=key)
                if (property_proxy.field_type == 'ATOMIC'):
                    model_realizations = model_realizations.filter(properties__proxy=property_proxy).has_atomic_value(value)
                elif (property_proxy.field_type == 'ENUMERATION'):
                    formatted_values = [fv for fv in map((lambda v: v.strip()), value.split(',')) if fv]
                    model_realizations = model_realizations.filter(properties__proxy=property_proxy).has_enumeration_values(formatted_values)
                else:
                    msg = 'Unable to support getting a document by relationship_field'
                    return q_error(request, msg)
            except ObjectDoesNotExist:
                msg = "There is no '{0}' property for the '{0}' document_type".format(key, model_proxy)
                return q_error(request, msg)
    if (model_realizations.count() != 1):
        msg = "Unable to uniquely identify '{0}' document_type with the following properties: '{1}'".format(model_proxy, ', '.join(['{0}: {1}'.format(p[0], p[1]) for p in additional_parameters.items()]))
        return q_error(request, msg)
    return HttpResponseRedirect(reverse('edit_existing', kwargs={'project_name': project_name, 'ontology_key': ontology_key, 'document_type': document_type, 'realization_pk': model_realizations.first().pk}))
this is meant to be used from external requests (ie: further_info_url)
where uniquely identifying model fields (including pk) are passed
if a unique realization cannot be found then an error is returned
otherwise the response is routed to "q_edit_existing"
:param request:
:param project_name:
:param ontology_key:
:param document_type:
:param realization_pk:
:return:
@redirect_legacy_projects
def q_get_existing(request, project_name=None, ontology_key=None, document_type=None):
    '\n    this is meant to be used from external requests (ie: further_info_url)\n    where uniquely identifying model fields (including pk) are passed\n    if a unique realization cannot be found then an error is returned\n    otherwise the response is routed to "q_edit_existing"\n    :param request:\n    :param project_name:\n    :param ontology_key:\n    :param document_type:\n    :param realization_pk:\n    :return:\n    '
    (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)
    model_realizations = QModelRealization.objects.filter(project=project, proxy=model_proxy)
    additional_parameters = request.GET.copy()
    for (key, value) in additional_parameters.iteritems():
        if ((key == 'pk') or (key == 'guid')):
            try:
                return HttpResponseRedirect(reverse('edit_existing', kwargs={'project_name': project_name, 'ontology_key': ontology_key, 'document_type': document_type, 'realization_pk': model_realizations.get(**{key: value}).pk}))
            except (ObjectDoesNotExist, ValueError):
                msg = "There is no '{0}' document with a {1} of '{2}'".format(model_proxy, key, value)
                return q_error(request, msg)
        else:
            try:
                property_proxy = model_proxy.property_proxies.get(name=key)
                if (property_proxy.field_type == 'ATOMIC'):
                    model_realizations = model_realizations.filter(properties__proxy=property_proxy).has_atomic_value(value)
                elif (property_proxy.field_type == 'ENUMERATION'):
                    formatted_values = [fv for fv in map((lambda v: v.strip()), value.split(',')) if fv]
                    model_realizations = model_realizations.filter(properties__proxy=property_proxy).has_enumeration_values(formatted_values)
                else:
                    msg = 'Unable to support getting a document by relationship_field'
                    return q_error(request, msg)
            except ObjectDoesNotExist:
                msg = "There is no '{0}' property for the '{0}' document_type".format(key, model_proxy)
                return q_error(request, msg)
    if (model_realizations.count() != 1):
        msg = "Unable to uniquely identify '{0}' document_type with the following properties: '{1}'".format(model_proxy, ', '.join(['{0}: {1}'.format(p[0], p[1]) for p in additional_parameters.items()]))
        return q_error(request, msg)
    return HttpResponseRedirect(reverse('edit_existing', kwargs={'project_name': project_name, 'ontology_key': ontology_key, 'document_type': document_type, 'realization_pk': model_realizations.first().pk}))