Skip to content

Commit fd0fd4e

Browse files
committed
removing PopResearch models...
1 parent 8d070c1 commit fd0fd4e

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<a href="https://github.com/dynata/python-cmixapi-client"><img alt="GitHub Actions status" src="https://github.com/dynata/python-cmixapi-client/workflows/python-tests/badge.svg"></a>
44

5-
A Python client library for the Dynata Cmix API.
5+
A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/display/CA/Getting+started).
66

77
## Setup
88

src/api.py

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import os
66

7-
from popresearch.models import CmixDataArchive, CmixSurvey, CmixSurveyXml
7+
from popresearch.models import CmixSurvey
88

99
from .error import CmixError
1010
from .parsing import generate_survey_xml_strings_and_secondary_keys
@@ -167,58 +167,58 @@ def add_extra_url_params(self, url, params):
167167

168168
return url
169169

170-
def get_survey_definition(self, cmix_survey_id):
170+
def get_survey_definition(self, survey_id):
171171
self.check_auth_headers()
172-
definition_url = '{}/surveys/{}/definition'.format(CMIX_SERVICES['survey']['BASE_URL'], cmix_survey_id)
172+
definition_url = '{}/surveys/{}/definition'.format(CMIX_SERVICES['survey']['BASE_URL'], survey_id)
173173
definition_response = requests.get(definition_url, headers=self._authentication_headers)
174174
return definition_response.json()
175175

176-
def get_survey_xml(self, cmix_survey_id):
176+
def get_survey_xml(self, survey_id):
177177
self.check_auth_headers()
178-
xml_url = '{}/surveys/{}'.format(CMIX_SERVICES['file']['BASE_URL'], cmix_survey_id)
178+
xml_url = '{}/surveys/{}'.format(CMIX_SERVICES['file']['BASE_URL'], survey_id)
179179
xml_response = requests.get(xml_url, headers=self._authentication_headers)
180180
return xml_response.content
181181

182-
def get_survey_test_url(self, cmix_survey_id):
182+
def get_survey_test_url(self, survey_id):
183183
self.check_auth_headers()
184-
survey_url = '{}/surveys/{}'.format(CMIX_SERVICES['survey']['BASE_URL'], cmix_survey_id)
184+
survey_url = '{}/surveys/{}'.format(CMIX_SERVICES['survey']['BASE_URL'], survey_id)
185185
survey_response = requests.get(survey_url, headers=self._authentication_headers)
186186
test_token = survey_response.json().get('testToken', None)
187187
if test_token is None:
188-
raise CmixError('Survey endpoint for CMIX ID {} did not return a test token.'.format(cmix_survey_id))
188+
raise CmixError('Survey endpoint for CMIX ID {} did not return a test token.'.format(survey_id))
189189
test_link = '{}/#/?cmixSvy={}&cmixTest={}'.format(
190190
CMIX_SERVICES['test']['BASE_URL'],
191-
cmix_survey_id,
191+
survey_id,
192192
test_token
193193
)
194194
return test_link
195195

196-
def get_survey_respondents(self, cmix_survey_id, respondent_type, live):
196+
def get_survey_respondents(self, survey_id, respondent_type, live):
197197
self.check_auth_headers()
198198
respondents_url = '{}/surveys/{}/respondents?respondentType={}&respondentStatus={}'.format(
199199
CMIX_SERVICES['reporting']['BASE_URL'],
200-
cmix_survey_id,
200+
survey_id,
201201
"LIVE" if live else "TEST",
202202
respondent_type,
203203
)
204204
respondents_response = requests.get(respondents_url, headers=self._authentication_headers)
205205
return respondents_response.json()
206206

207-
def get_survey_status(self, cmix_survey_id):
207+
def get_survey_status(self, survey_id):
208208
self.check_auth_headers()
209-
status_url = '{}/surveys/{}'.format(CMIX_SERVICES['survey']['BASE_URL'], cmix_survey_id)
209+
status_url = '{}/surveys/{}'.format(CMIX_SERVICES['survey']['BASE_URL'], survey_id)
210210
status_response = requests.get(status_url, headers=self._authentication_headers)
211211
status = status_response.json().get('status', None)
212212
if status is None:
213213
raise CmixError('Get Survey Status returned without a status. Response: {}'.format(status_response.json()))
214214
return status.lower()
215215

216-
def get_survey_completes(self, cmix_survey_id):
217-
return self.get_survey_respondents(cmix_survey_id, "COMPLETE", True)
216+
def get_survey_completes(self, survey_id):
217+
return self.get_survey_respondents(survey_id, "COMPLETE", True)
218218

219-
def create_export_archive(self, cmix_survey, export_type):
219+
def create_export_archive(self, survey_id, export_type):
220220
self.check_auth_headers()
221-
archive_url = '{}/surveys/{}/archives'.format(CMIX_SERVICES['survey']['BASE_URL'], cmix_survey.cmix_id)
221+
archive_url = '{}/surveys/{}/archives'.format(CMIX_SERVICES['survey']['BASE_URL'], survey_id)
222222
headers = self._authentication_headers.copy()
223223
headers['Content-Type'] = "application/json"
224224
payload = {
@@ -246,7 +246,7 @@ def create_export_archive(self, cmix_survey, export_type):
246246
)
247247
archive_json = archive_response.json()
248248

249-
layout_url = '{}/surveys/{}/data-layouts/'.format(CMIX_SERVICES['survey']["BASE_URL"], cmix_survey.cmix_id)
249+
layout_url = '{}/surveys/{}/data-layouts/'.format(CMIX_SERVICES['survey']["BASE_URL"], survey_id)
250250
layout_response = requests.get(layout_url, headers=self._authentication_headers)
251251
if layout_response.status_code != 200:
252252
raise CmixError(
@@ -268,25 +268,17 @@ def create_export_archive(self, cmix_survey, export_type):
268268
)
269269

270270
archive_json['dataLayoutId'] = layout_id
271-
cda = CmixDataArchive.objects.create(
272-
cmix_survey=cmix_survey,
273-
status=CmixDataArchive.UNPROCESSED,
274-
json=archive_json,
275-
download_url="",
276-
deleted=False,
277-
file_type=export_type,
278-
)
279-
return cda
271+
return archive_json
280272

281273
def update_archive_status(self, archive):
282274
self.check_auth_headers()
283275
layout_id = archive.json.get('dataLayoutId', None)
284276
archive_id = archive.json.get('id', None)
285277
if layout_id is None:
286-
raise CmixError('Error while updating archie status: layout ID is None. Archive ID: {}'.format(archive.id))
278+
raise CmixError('Error while updating archie status: layout ID is None. Archive ID: {}'.format(archive_id))
287279
if archive_id is None:
288280
raise CmixError(
289-
'Error while updating archie status: CMIX archive ID is None. Pop Archive ID: {}'.format(archive.id)
281+
'Error while updating archie status: CMIX archive ID is None. Pop Archive ID: {}'.format(archive_id)
290282
)
291283
archive_url = '{}/surveys/{}/data-layouts/{}/archives/{}'.format(
292284
CMIX_SERVICES['survey']["BASE_URL"],
@@ -301,7 +293,6 @@ def update_archive_status(self, archive):
301293
archive_response['id'] = archive_id
302294
archive.json = archive_response
303295
else:
304-
archive.status = CmixDataArchive.PROCESSED
305296
archive.download_url = archive_response.get('archiveUrl')
306297
archive.save()
307298
return archive
@@ -377,12 +368,6 @@ def create_survey(self, survey, wave_number=None):
377368
results_requested=False,
378369
secondary_key=secondary_key,
379370
)
380-
CmixSurveyXml.objects.create(
381-
cmix_id=cmix_id,
382-
cmix_project_id=cmix_project_id,
383-
xml=xml_string,
384-
when_recorded='sent',
385-
)
386371

387372
self.update_project(response_json.get('projectId'), status=self.SURVEY_STATUS_DESIGN)
388373

0 commit comments

Comments
 (0)