Skip to content

Commit

Permalink
Merge pull request #11 from uw-it-aca/feature/activity-log-filtering
Browse files Browse the repository at this point in the history
Feature/activity log filtering
  • Loading branch information
devights committed Sep 22, 2020
2 parents c24eee5 + de0e738 commit d465181
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 4 deletions.
48 changes: 44 additions & 4 deletions uw_adsel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from uw_adsel.models import Major, Cohort, Quarter, Activity, Application
import dateutil.parser
from datetime import datetime
import urllib.parse


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -96,11 +97,50 @@ def _get_applications_from_json(self, response):
applications.append(application)
return applications

def get_activities(self, **kwargs):
def get_filtered_activities(self,
netid=None,
assignment_type=None,
cohort=None,
major=None,
start_date=None,
end_date=None,
system_key=None,
collection_type=None,
assignment_period=None,
comment=None):
url = "{}/activities".format(self.API)
response = self._get_resource(url)
activities = self._activities_from_json(response)
return activities
filters = {}
if netid is not None:
filters['netid'] = netid
if assignment_type is not None:
filters['assignmentType'] = assignment_type
if cohort is not None:
filters['cohort'] = cohort
if major is not None:
filters['cohort'] = major
if start_date is not None:
filters['startDate'] = start_date
if end_date is not None:
filters['endDate'] = end_date
if system_key is not None:
filters['systemKey'] = system_key
if collection_type is not None:
filters['collectionType'] = collection_type
if assignment_period is not None:
filters['assignmentPeriod'] = assignment_period
if comment is not None:
filters['comment'] = comment
filter_url = urllib.parse.urlencode(filters)
if len(filter_url) > 0:
url = url + "?" + filter_url
try:
response = self._get_resource(url)
return self._activities_from_json(response)
except DataFailureException:
return []

def get_activities(self, **kwargs):
return self.get_filtered_activities()

def _activities_from_json(self, response):
activities = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"decisions": [
{
"assignmentMadeOn": "2019-12-04T23:44:49.494Z",
"comment": "Making some assignments",
"assignmentMadeBy": "javerage",
"assignmentType": "major",
"cohortNbr": 42,
"majorAbbr": "",
"majorProgramCode": "",
"totalSubmitted": 20,
"totalAssigned": 19
}
],
"nextPage": "2",
"previousPage": "1",
"totalCount": 2
}
29 changes: 29 additions & 0 deletions uw_adsel/resources/adsel/file/api/v1/activities?netid=javerage
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"decisions": [
{
"assignmentMadeOn": "2019-12-04T23:44:49.494Z",
"comment": "Making some assignments",
"assignmentMadeBy": "javerage",
"assignmentType": "Type 1",
"cohortNbr": 42,
"majorAbbr": "",
"majorProgramCode": "",
"totalSubmitted": 20,
"totalAssigned": 19
},
{
"assignmentMadeOn": "2019-02-24T03:44:49.494Z",
"comment": "Making some assignments",
"assignmentMadeBy": "javerage",
"assignmentType": "who knows",
"cohortNbr": 0,
"majorAbbr": "CHEM",
"majorProgramCode": "CHEM",
"totalSubmitted": 20044,
"totalAssigned": 1547
}
],
"nextPage": "2",
"previousPage": "1",
"totalCount": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"decisions": [
{
"assignmentMadeOn": "2019-12-04T23:44:49.494Z",
"comment": "Making some assignments",
"assignmentMadeBy": "javerage",
"assignmentType": "Type 1",
"cohortNbr": 42,
"majorAbbr": "",
"majorProgramCode": "",
"totalSubmitted": 20,
"totalAssigned": 19
},
{
"assignmentMadeOn": "2019-12-04T19:44:49.494Z",
"comment": "More assignment work",
"assignmentMadeBy": "javerage",
"assignmentType": "Type 3",
"cohortNbr": 13,
"majorAbbr": "",
"majorProgramCode": "",
"totalSubmitted": 35,
"totalAssigned": 35
},
{
"assignmentMadeOn": "2019-12-09T21:44:49.494Z",
"comment": "Setting up a major",
"assignmentMadeBy": "javerage",
"assignmentType": "Type 2",
"cohortNbr": 0,
"majorAbbr": "CSE",
"majorProgramCode": "CSE",
"totalSubmitted": 2,
"totalAssigned": 2
},
{
"assignmentMadeOn": "2019-02-24T03:44:49.494Z",
"comment": "Making some assignments",
"assignmentMadeBy": "javerage",
"assignmentType": "who knows",
"cohortNbr": 0,
"majorAbbr": "CHEM",
"majorProgramCode": "CHEM",
"totalSubmitted": 20044,
"totalAssigned": 1547
}
],
"nextPage": "2",
"previousPage": "1",
"totalCount": 2
}
12 changes: 12 additions & 0 deletions uw_adsel/tests/test_adsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def test_get_activities(self):
self.assertEqual(len(activities), 4)
self.assertEqual(activities[0].user, "javerage")

def test_get_filtered_activities(self):
# netid filter
activities = self.adsel.get_filtered_activities(netid="javerage")
self.assertEqual(len(activities), 2)
# No results
activities = self.adsel.get_filtered_activities(netid="foo")
self.assertEqual(len(activities), 0)
# dual filter
activities = self.adsel.get_filtered_activities(netid="javerage",
system_key=12345)
self.assertEqual(len(activities), 4)

def test_get_application(self):
applications = self.adsel.get_applications_by_qtr_syskey(0, 123)
self.assertEqual(len(applications), 4)
Expand Down

0 comments on commit d465181

Please sign in to comment.