当前位置: 首页>>代码示例>>Python>>正文


Python StatementValidator.validate_agent方法代码示例

本文整理汇总了Python中StatementValidator.StatementValidator.validate_agent方法的典型用法代码示例。如果您正苦于以下问题:Python StatementValidator.validate_agent方法的具体用法?Python StatementValidator.validate_agent怎么用?Python StatementValidator.validate_agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StatementValidator.StatementValidator的用法示例。


在下文中一共展示了StatementValidator.validate_agent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: agent_profile_delete

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_delete(req_dict):
    rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
    if rogueparams:
        raise ParamError("The delete agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = json.loads(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param for agent profile is not valid")
        validator.validate_agent(agent, "agent param for agent profile")
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict['method']
        raise ParamError(err_msg)

    if not 'profileId' in req_dict['params']:
        err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict['method']
        raise ParamError(err_msg) 
    
    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_state_or_profile_agent(req_dict, "profile")
    return req_dict
开发者ID:roadlit,项目名称:lrs,代码行数:27,代码来源:req_validate.py

示例2: agents_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agents_get(req_dict):
    rogueparams = set(req_dict['params']) - set(["agent"])
    if rogueparams:
        raise ParamError(
            "The get agent request contained unexpected parameters: %s" % ", ".join(rogueparams))

    try:
        req_dict['params']['agent']
    except KeyError:
        err_msg = "Error -- agents url, but no agent parameter.. the agent parameter is required"
        raise ParamError(err_msg)

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param") 

    params = get_agent_ifp(agent)
    if not Agent.objects.filter(**params).exists():
        raise IDNotFoundError(
            "Error with Agent. The agent partial did not match any agents on record")

    req_dict['agent_ifp'] = params
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:30,代码来源:req_validate.py

示例3: activity_state_delete

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_delete(req_dict):
    rogueparams = set(req_dict['params']) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The delete activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'activityId' in req_dict['params']:
        validator.validate_iri(req_dict['params']['activityId'], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict['method']
        raise ParamError(err_msg)

    if 'registration' in req_dict['params']:
        validator.validate_uuid(req_dict['params']['registration'], "registration param for activity state")

    if 'agent' in req_dict['params']:
        try:
            agent = json.loads(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param for activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict['method']
        raise ParamError(err_msg)
    
    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_state_or_profile_agent(req_dict, "state")
    return req_dict
开发者ID:roadlit,项目名称:lrs,代码行数:32,代码来源:req_validate.py

示例4: agent_profile_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_put(req_dict):
    rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
    if rogueparams:
        raise ParamError(
            "The put agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param") 
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'profileId' not in req_dict['params']:
        err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'body' not in req_dict:
        err_msg = "Could not find the profile document"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "agent profile")

    req_dict['profile'] = req_dict.pop('raw_body', req_dict.pop('body', None))
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:37,代码来源:req_validate.py

示例5: agent_profile_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_get(req_dict):
    rogueparams = set(req_dict['params']) - \
        set(["agent", "profileId", "since"])
    if rogueparams:
        raise ParamError(
            "The get agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param") 
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'since' in req_dict['params']:
        try:
            parse_datetime(req_dict['params']['since'])
        except (Exception, ISO8601Error):
            raise ParamError(
                "Since parameter was not a valid ISO8601 timestamp")

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "agent profile")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:34,代码来源:req_validate.py

示例6: agent_profile_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_put(req_dict):
    rogueparams = set(req_dict["params"]) - set(["agent", "profileId"])
    if rogueparams:
        raise ParamError("The put agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if "agent" in req_dict["params"]:
        try:
            agent = json.loads(req_dict["params"]["agent"])
            req_dict["params"]["agent"] = agent
        except Exception:
            raise ParamError("agent param for agent profile is not valid")
        validator.validate_agent(agent, "agent param for agent profile")
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if not "profileId" in req_dict["params"]:
        err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if "body" not in req_dict:
        err_msg = "Could not find the profile document"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "profile")
    req_dict["profile"] = req_dict.pop("raw_body", req_dict.pop("body", None))
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:32,代码来源:req_validate.py

示例7: agent_profile_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_get(req_dict):
    rogueparams = set(req_dict["params"]) - set(["agent", "profileId", "since"])
    if rogueparams:
        raise ParamError("The get agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if "agent" in req_dict["params"]:
        try:
            agent = json.loads(req_dict["params"]["agent"])
            req_dict["params"]["agent"] = agent
        except Exception:
            raise ParamError("agent param for agent profile is not valid")
        validator.validate_agent(agent, "agent param for agent profile")
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if "since" in req_dict["params"]:
        try:
            parse_datetime(req_dict["params"]["since"])
        except (Exception, ISO8601Error):
            raise ParamError("Since parameter was not a valid ISO8601 timestamp")

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "profile")
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:29,代码来源:req_validate.py

示例8: activity_state_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_put(req_dict):
    rogueparams = set(req_dict['params']) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The put activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'activityId' in req_dict['params']:
        validator.validate_uri(req_dict['params']['activityId'], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict['method']
        raise ParamError(err_msg)

    if not 'stateId' in req_dict['params']:
        err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict['method']
        raise ParamError(err_msg)    

    if 'registration' in req_dict['params']:
        if not validate_uuid(req_dict['params']['registration']):
            raise ParamError("%s is not a valid uuid for the registration parameter")

    if 'agent' in req_dict['params']:
        try:
            agent = json.loads(req_dict['params']['agent'])
        except Exception, e:
            raise ParamError("agent param for activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
开发者ID:DistanceLearning,项目名称:ADL_LRS,代码行数:28,代码来源:req_validate.py

示例9: agent_profile_delete

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_delete(req_dict):
    rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
    if rogueparams:
        raise ParamError("The delete agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = json.loads(req_dict['params']['agent'])
        except Exception, e:
            raise ParamError("agent param for agent profile is not valid")
        validator.validate_agent(agent, "agent param for agent profile")
开发者ID:DistanceLearning,项目名称:ADL_LRS,代码行数:14,代码来源:req_validate.py

示例10: activity_state_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_put(req_dict):
    rogueparams = set(req_dict['params']) - \
        set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError(
            "The put activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'activityId' in req_dict['params']:
        validator.validate_iri(
            req_dict['params']['activityId'], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'stateId' not in req_dict['params']:
        err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'registration' in req_dict['params']:
        validator.validate_uuid(
            req_dict['params']['registration'], "registration param for activity state")

    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param") 
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    # Must have body included for state
    if 'body' not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "state")

    # Set state
    req_dict['state'] = req_dict.pop('raw_body', req_dict.pop('body', None))
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:52,代码来源:req_validate.py

示例11: activity_state_put

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_put(req_dict):
    rogueparams = set(req_dict["params"]) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The put activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if "activityId" in req_dict["params"]:
        validator.validate_iri(req_dict["params"]["activityId"], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if not "stateId" in req_dict["params"]:
        err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if "registration" in req_dict["params"]:
        validator.validate_uuid(req_dict["params"]["registration"], "registration param for activity state")

    if "agent" in req_dict["params"]:
        try:
            agent = json.loads(req_dict["params"]["agent"])
            req_dict["params"]["agent"] = agent
        except Exception:
            raise ParamError("agent param for activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    # Must have body included for state
    if "body" not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "state")

    # Set state
    req_dict["state"] = req_dict.pop("raw_body", req_dict.pop("body", None))
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:44,代码来源:req_validate.py

示例12: agent_profile_post

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def agent_profile_post(req_dict):
    rogueparams = set(req_dict['params']) - set(["agent", "profileId"])
    if rogueparams:
        raise ParamError(
            "The post agent profile request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param") 
    else:
        err_msg = "Error -- agent_profile - method = %s, but agent parameter missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'profileId' not in req_dict['params']:
        err_msg = "Error -- agent_profile - method = %s, but profileId parameter missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'body' not in req_dict:
        err_msg = "Could not find the profile document"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "agent profile")

    # Check json for incoming POSTed document
    if "application/json" not in req_dict['headers']['CONTENT_TYPE']:
        raise ParamError(
            "Agent profile document to be posted does not have a Content-Type of 'application/json'")

    # expected to be json
    try:
        raw_profile = req_dict.pop('raw_body', req_dict.pop('body', None))
        convert_to_datatype(raw_profile)
    except Exception:
        raise ParamError("Agent profile document is not valid JSON")
    else:
        req_dict['profile'] = raw_profile

    # Check the content type if the document already exists
    exists = False
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve_or_create(**agent)[0]
    try:
        p = AgentProfile.objects.get(
            profile_id=req_dict['params']['profileId'], agent=a)
        exists = True
    except AgentProfile.DoesNotExist:
        pass

    # Since document to be POSTed has to be json, so does the existing document
    if exists and str(p.content_type) != "application/json":
        raise ParamError("Agent profile already exists but is not JSON, cannot update it with new JSON document")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:64,代码来源:req_validate.py

示例13: activity_state_post

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_post(req_dict):
    rogueparams = set(req_dict['params']) - \
        set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError(
            "The post activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'activityId' in req_dict['params']:
        validator.validate_iri(
            req_dict['params']['activityId'], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'stateId' not in req_dict['params']:
        err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    if 'registration' in req_dict['params']:
        validator.validate_uuid(
            req_dict['params']['registration'], "registration param for activity state")

    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param")        
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict[
            'method']
        raise ParamError(err_msg)

    # Must have body included for state
    if 'body' not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict['auth']['type'] == 'oauth':
        validate_oauth_for_documents(req_dict, "state")

    # Check json for incoming POSTed document
    if "application/json" not in req_dict['headers']['CONTENT_TYPE']:
        raise ParamError(
            "Activity state document to be posted does not have a Content-Type of 'application/json'")

    # expected to be json
    try:
        raw_state = req_dict.pop('raw_body', req_dict.pop('body', None))
        convert_to_datatype(raw_state)
    except Exception:
        raise ParamError("Activity state document is not valid JSON")
    else:
        req_dict['state'] = raw_state

    # Check the content type if the document already exists
    registration = req_dict['params'].get('registration', None)
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve_or_create(**agent)[0]
    exists = False
    if registration:
        try:
            s = ActivityState.objects.get(state_id=req_dict['params']['stateId'], agent=a,
                                          activity_id=req_dict['params']['activityId'], registration_id=req_dict['params']['registration'])
            exists = True
        except ActivityState.DoesNotExist:
            pass
    else:
        try:
            s = ActivityState.objects.get(state_id=req_dict['params']['stateId'], agent=a,
                                          activity_id=req_dict['params']['activityId'])
            exists = True
        except ActivityState.DoesNotExist:
            pass
    
    if exists and str(s.content_type) != "application/json":
        raise ParamError("Activity state already exists but is not JSON, cannot update it with new JSON document")
    return req_dict
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:86,代码来源:req_validate.py

示例14: statements_get

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def statements_get(req_dict):
    rogueparams = set(req_dict['params']) - set(["statementId", "voidedStatementId", "agent", "verb", "activity", "registration",
                                                 "related_activities", "related_agents", "since",
                                                 "until", "limit", "format", "attachments", "ascending"])
    if rogueparams:
        raise ParamError(
            "The get statements request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if 'agent' in req_dict['params']:
        try:
            agent = convert_to_datatype(req_dict['params']['agent'])
            req_dict['params']['agent'] = agent
        except Exception:
            raise ParamError("agent param %s is not valid" % \
                req_dict['params']['agent'])
        validator.validate_agent(agent, "Agent param")    

    formats = ['exact', 'canonical', 'ids']
    if 'format' in req_dict['params']:
        if req_dict['params']['format'] not in formats:
            raise ParamError("The format filter value (%s) was not one of the known values: %s" % (
                req_dict['params']['format'], ','.join(formats)))
    else:
        req_dict['params']['format'] = 'exact'

    # StatementId could be for voided statement as well
    if 'statementId' in req_dict['params'] or 'voidedStatementId' in req_dict['params']:
        req_dict['statementId'] = validate_statementId(req_dict)

    if 'since' in req_dict['params']:
        try:
            parse_datetime(req_dict['params']['since'])
        except (Exception, ISO8601Error):
            raise ParamError(
                "since parameter was not a valid ISO8601 timestamp")

    if 'until' in req_dict['params']:
        try:
            parse_datetime(req_dict['params']['until'])
        except (Exception, ISO8601Error):
            raise ParamError(
                "until parameter was not a valid ISO8601 timestamp")

    if 'ascending' in req_dict['params']:
        if req_dict['params']['ascending'].lower() == 'true':
            req_dict['params']['ascending'] = True
        elif req_dict['params']['ascending'].lower() == 'false':
            req_dict['params']['ascending'] = False
        else:
            raise ParamError(
                "ascending parameter was not a boolean value")
    else:
        req_dict['params']['ascending'] = False

    if 'related_agents' in req_dict['params']:
        if req_dict['params']['related_agents'].lower() == 'true':
            req_dict['params']['related_agents'] = True
        elif req_dict['params']['related_agents'].lower() == 'false':
            req_dict['params']['related_agents'] = False
        else:
            raise ParamError(
                "related_agents parameter was not a boolean value")
    else:
        req_dict['params']['related_agents'] = False

    if 'related_activities' in req_dict['params']:
        if req_dict['params']['related_activities'].lower() == 'true':
            req_dict['params']['related_activities'] = True
        elif req_dict['params']['related_activities'].lower() == 'false':
            req_dict['params']['related_activities'] = False
        else:
            raise ParamError(
                "related_activities parameter was not a boolean value")
    else:
        req_dict['params']['related_activities'] = False

    if 'attachments' in req_dict['params']:
        if req_dict['params']['attachments'].lower() == 'true':
            req_dict['params']['attachments'] = True
        elif req_dict['params']['attachments'].lower() == 'false':
            req_dict['params']['attachments'] = False
        else:
            raise ParamError(
                "attachments parameter was not a boolean value")
    else:
        req_dict['params']['attachments'] = False

    if 'limit' in req_dict['params']:
        try:
            req_dict['params']['limit'] = int(req_dict['params']['limit'])
        except Exception:
            raise ParamError(
                "limit parameter was not a non-negative integer")
        else:
            if req_dict['params']['limit'] < 0:
                raise ParamError(
                    "limit parameter was not a non-negative integer")                
    else:
        req_dict['params']['limit'] = 0
#.........这里部分代码省略.........
开发者ID:adlnet,项目名称:ADL_LRS,代码行数:103,代码来源:req_validate.py

示例15: activity_state_post

# 需要导入模块: from StatementValidator import StatementValidator [as 别名]
# 或者: from StatementValidator.StatementValidator import validate_agent [as 别名]
def activity_state_post(req_dict):
    rogueparams = set(req_dict["params"]) - set(["activityId", "agent", "stateId", "registration"])
    if rogueparams:
        raise ParamError("The post activity state request contained unexpected parameters: %s" % ", ".join(rogueparams))

    validator = StatementValidator()
    if "activityId" in req_dict["params"]:
        validator.validate_iri(req_dict["params"]["activityId"], "activityId param for activity state")
    else:
        err_msg = "Error -- activity_state - method = %s, but activityId parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if not "stateId" in req_dict["params"]:
        err_msg = "Error -- activity_state - method = %s, but stateId parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    if "registration" in req_dict["params"]:
        validator.validate_uuid(req_dict["params"]["registration"], "registration param for activity state")

    if "agent" in req_dict["params"]:
        try:
            agent = json.loads(req_dict["params"]["agent"])
            req_dict["params"]["agent"] = agent
        except Exception:
            raise ParamError("agent param for activity state is not valid")
        validator.validate_agent(agent, "Activity state agent param")
    else:
        err_msg = "Error -- activity_state - method = %s, but agent parameter is missing.." % req_dict["method"]
        raise ParamError(err_msg)

    # Must have body included for state
    if "body" not in req_dict:
        err_msg = "Could not find the state"
        raise ParamError(err_msg)

    # Extra validation if oauth
    if req_dict["auth"]["type"] == "oauth":
        validate_oauth_state_or_profile_agent(req_dict, "state")

    # Check the content type if the document already exists
    registration = req_dict["params"].get("registration", None)
    agent = req_dict["params"]["agent"]
    a = Agent.objects.retrieve_or_create(**agent)[0]
    exists = False
    if registration:
        try:
            s = ActivityState.objects.get(
                state_id=req_dict["params"]["stateId"],
                agent=a,
                activity_id=req_dict["params"]["activityId"],
                registration_id=req_dict["params"]["registration"],
            )
            exists = True
        except ActivityState.DoesNotExist:
            pass
    else:
        try:
            s = ActivityState.objects.get(
                state_id=req_dict["params"]["stateId"], agent=a, activity_id=req_dict["params"]["activityId"]
            )
            exists = True
        except ActivityState.DoesNotExist:
            pass
    if exists:
        if str(s.content_type) != "application/json" or (
            "application/json" not in req_dict["headers"]["CONTENT_TYPE"]
            or req_dict["headers"]["CONTENT_TYPE"] != "application/json"
        ):
            raise ParamError(
                "Neither original document or document to be posted has a Content-Type of 'application/json'"
            )

    # Set state
    req_dict["state"] = req_dict.pop("raw_body", req_dict.pop("body", None))
    return req_dict
开发者ID:xiaolidefeidao,项目名称:iccnu_adl_lrs,代码行数:77,代码来源:req_validate.py


注:本文中的StatementValidator.StatementValidator.validate_agent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。