def get_xform_from_submission(xml, username, uuid=None):
        # check alternative form submission ids
        uuid = uuid or get_uuid_from_submission(xml)

        if not username and not uuid:
            raise InstanceInvalidUserError()

        if uuid:
            # try find the form by its uuid which is the ideal condition
            if XForm.objects.filter(uuid=uuid).count() > 0:
                xform = XForm.objects.get(uuid=uuid)

                return xform

        id_string = get_id_string_from_xml_str(xml)

        return get_object_or_404(XForm, id_string__exact=id_string,
                                 user__username=username)
dataset/ETHPy150Open kobotoolbox/kobocat/onadata/libs/utils/logger_tools.py/get_xform_from_submission/original