Commit 8655183b authored by Lynn Foster's avatar Lynn Foster
Browse files

added query for resource types defined for an agent

parent 6576f969
......@@ -1818,6 +1818,17 @@ query ($token: String) {
}
}
query ($token: String) {
viewer(token: $token) {
agent(id: 146) {
agentDefinedResourceClassifications(action: "work") {
id
name
}
}
}
}
query($token: String) {
viewer(token: $token) {
allRecipes {
......
......@@ -5,7 +5,7 @@
import graphene
from graphene_django.types import DjangoObjectType
from django.db.models import Q
from valuenetwork.valueaccounting.models import EconomicAgent, EconomicResourceType, AgentType, EventTypeManager, EventType, AgentResourceType
from valuenetwork.valueaccounting.models import EconomicAgent, EconomicResourceType, AgentType, EventTypeManager, EventType, AgentResourceType, EconomicResourceType
import valuenetwork.api.types as types
from valuenetwork.api.types.AgentRelationship import AgentRelationship, AgentRelationshipCategory, AgentRelationshipRole
from valuenetwork.api.models import Organization as OrganizationModel, Person as PersonModel, formatAgentList
......@@ -43,6 +43,9 @@ class Agent(graphene.Interface):
search_owned_inventory_resources = graphene.List(lambda: types.EconomicResource,
search_string=graphene.String())
agent_defined_resource_classifications = graphene.List(lambda: types.ResourceClassification,
action=graphene.String())
agent_processes = graphene.List(lambda: types.Process,
is_finished=graphene.Boolean())
......@@ -156,6 +159,37 @@ class Agent(graphene.Interface):
raise ValidationError("A search string is required.")
return agent.search_owned_resources(search_string=search_string)
def resolve_agent_defined_resource_classifications(self, args, context, info):
agent = _load_identified_agent(self)
action = args.get('action', None)
rts = agent.defined_resource_types()
if action == None:
return rts
else:
filtered_rts = []
if action == "work":
for rt in rts:
if rt.behavior == "work":
filtered_rts.append(rt)
if action == "use":
for rt in rts:
if rt.behavior == "used":
filtered_rts.append(rt)
if action == "consume":
for rt in rts:
if rt.behavior == "consumed":
filtered_rts.append(rt)
if action == "cite":
for rt in rts:
if rt.behavior == "cited":
filtered_rts.append(rt)
if action == "produce" or action == "improve" or action == "accept":
for rt in rts:
if rt.behavior == "produced" or rt.behavior == "used" or rt.behavior == "cited" or rt.behavior == "consumed":
filtered_rts.append(rt)
return filtered_rts
# if an organization, this returns processes done in that context
# if a person, this returns proceses the person has worked on
def resolve_agent_processes(self, args, context, info):
......
......@@ -1645,6 +1645,13 @@ class EconomicAgent(models.Model):
parent = parent.parent()
return None
 
def defined_resource_types(self, event_type=None):
agents = list(self.all_ancestors())
rts = []
for agent in agents:
rts.extend(agent.context_resource_types.all())
return list(set(rts))
def virtual_accounts(self):
vars = self.agent_resource_roles.filter(
role__is_owner=True,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment