本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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")
示例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")
示例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
示例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
示例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
示例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
示例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
#.........这里部分代码省略.........
示例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