Commit 65abdddb authored by Bob Haugen's avatar Bob Haugen Committed by Lynn Foster
Browse files

add pagination to agentCommitments and commitmentsMatchingSkills queries

parent 12d9007f
......@@ -1203,7 +1203,7 @@ query($token: String) {
viewer(token: $token) {
person(id:6) {
name
commitmentsMatchingSkills {
commitmentsMatchingSkills(page:1) {
id
action
resourceClassifiedAs {
......@@ -2608,7 +2608,7 @@ query ($token: String) {
}
note
}
agentCommitments(latestNumberOfDays: 30) {
agentCommitments(page:1) {
id
action
plannedStart
......
......@@ -67,7 +67,8 @@ class Agent(graphene.Interface):
month=graphene.Int())
agent_commitments = graphene.List(lambda: types.Commitment,
latest_number_of_days=graphene.Int())
latest_number_of_days=graphene.Int(),
page=graphene.Int())
search_agent_commitments = graphene.List(lambda: types.Commitment,
search_string=graphene.String(),
......@@ -101,7 +102,8 @@ class Agent(graphene.Interface):
agent_skill_relationships = graphene.List(lambda: types.AgentResourceClassification)
commitments_matching_skills = graphene.List(lambda: types.Commitment)
commitments_matching_skills = graphene.List(lambda: types.Commitment,
page=graphene.Int())
validated_events_count = graphene.Int(month=graphene.Int(), year=graphene.Int())
......@@ -240,6 +242,7 @@ class Agent(graphene.Interface):
# returns commitments where an agent is a provider, receiver, or scope agent, excluding exchange related events
def resolve_agent_commitments(self, args, context, info):
agent = _load_identified_agent(self)
page = args.get('page', None)
if agent:
days = args.get('latest_number_of_days', 0)
if days > 0:
......@@ -248,6 +251,17 @@ class Agent(graphene.Interface):
else:
commits = agent.involved_in_commitments()
commits = commits.exclude(event_type__name="Give").exclude(event_type__name="Receive")
if page:
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
paginator = Paginator(commits, 25)
try:
commits = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
commits = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
commits = paginator.page(paginator.num_pages)
return commits
return None
......@@ -375,7 +389,22 @@ class Agent(graphene.Interface):
def resolve_commitments_matching_skills(self, args, context, info):
agent = _load_identified_agent(self)
return agent.commitments_with_my_skills()
page = args.get('page', None)
if agent:
commits = agent.commitments_with_my_skills()
if page:
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
paginator = Paginator(commits, 25)
try:
commits = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
commits = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
commits = paginator.page(paginator.num_pages)
return commits
return None
def resolve_validated_events_count(self, args, *rargs):
agent = _load_identified_agent(self)
......
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