Skip to content

Instantly share code, notes, and snippets.

@berryp
Created June 11, 2014 18:45
Show Gist options
  • Save berryp/6d6de7125c461245817f to your computer and use it in GitHub Desktop.
Save berryp/6d6de7125c461245817f to your computer and use it in GitHub Desktop.
diff --git a/gryphon/control/admin/resources.py b/gryphon/control/admin/resources.py
index da5b546..4dc1679 100755
--- a/gryphon/control/admin/resources.py
+++ b/gryphon/control/admin/resources.py
@@ -468,18 +468,18 @@ class SurveyInfo(InfoResource):
return [
SurveyDetail(
- survey_id, urlparse.urljoin(
+ survey['survey_id'], urlparse.urljoin(
gryphon.config.panman_base_url,
- 'survey/%s' % survey_id
+ 'survey/%s' % survey['survey_id']
),
{'class': 'overflow'} if idx > hide_after else {},
urlparse.urljoin(
gryphon.config.datadirect_base_url,
'/{qxname}/{survey_id}'.format(qxname=qxname,
- survey_id=survey_id)
+ survey_id=survey['survey_id'])
),
)
- for idx, survey_id
+ for idx, survey
in enumerate(reversed(sorted(periods)))
]
@@ -488,11 +488,11 @@ class SurveyInfo(InfoResource):
quex.update_last_accessed()
active_rev = quex.active_version.id if quex.active_version else 'None'
- all_periods = surveys.get_survey_periods(gryphon.cases, quex.id)
+ all_periods = surveys.get_survey_periods(quex.id)
periods = sorted(
- (survey_id, start_date.strftime('%m/%d/%Y')
- if start_date else None)
- for survey_id, start_date in all_periods.items()
+ (p['survey_id'], p['start_date']
+ if p['start_date'] else None)
+ for p in all_periods
)
if rev:
diff --git a/gryphon/models/surveys.py b/gryphon/models/surveys.py
index 543b41d..3a4c71a 100644
--- a/gryphon/models/surveys.py
+++ b/gryphon/models/surveys.py
@@ -2,25 +2,19 @@ from __future__ import absolute_import
import pan
import gryphon
+import requests
-def _get_surveys(cases, name):
- """
- Return pan.Survey objects for surveys which have cases for the given
- questionnaire name.
- """
- return (
- gryphon.panoptic.get_entity(pan.Survey, survey_id)
- for survey_id in cases.get_survey_ids(name)
- )
-def get_survey_periods(cases, name):
+def get_survey_periods(name):
"""
Return a mapping of survey ID to the start date for that survey.
"""
- return {
- # Panman doesn't always store a total_start so fall back to
- # field_start if it exists. Ref #34299
- # TEMPORARY workaround for #35644
- survey_id: pan.models.utcnow()
- for survey_id in cases.get_survey_ids(name)
- }
+ req = requests.get('{panoptic_url}/questionnaires/{name}/timings/'.format(
+ panoptic_url=gryphon.config.panoptic_url, name=name))
+
+ return [
+ {
+ 'survey_id': i['survey_id'],
+ 'start_date': i['total_start'] or i['field_start']
+ } for i in req.json()
+ ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment