4
4
import logging
5
5
import os
6
6
7
- from popresearch .models import CmixDataArchive , CmixSurvey , CmixSurveyXml
7
+ from popresearch .models import CmixSurvey
8
8
9
9
from .error import CmixError
10
10
from .parsing import generate_survey_xml_strings_and_secondary_keys
@@ -167,58 +167,58 @@ def add_extra_url_params(self, url, params):
167
167
168
168
return url
169
169
170
- def get_survey_definition (self , cmix_survey_id ):
170
+ def get_survey_definition (self , survey_id ):
171
171
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 )
173
173
definition_response = requests .get (definition_url , headers = self ._authentication_headers )
174
174
return definition_response .json ()
175
175
176
- def get_survey_xml (self , cmix_survey_id ):
176
+ def get_survey_xml (self , survey_id ):
177
177
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 )
179
179
xml_response = requests .get (xml_url , headers = self ._authentication_headers )
180
180
return xml_response .content
181
181
182
- def get_survey_test_url (self , cmix_survey_id ):
182
+ def get_survey_test_url (self , survey_id ):
183
183
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 )
185
185
survey_response = requests .get (survey_url , headers = self ._authentication_headers )
186
186
test_token = survey_response .json ().get ('testToken' , None )
187
187
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 ))
189
189
test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
190
190
CMIX_SERVICES ['test' ]['BASE_URL' ],
191
- cmix_survey_id ,
191
+ survey_id ,
192
192
test_token
193
193
)
194
194
return test_link
195
195
196
- def get_survey_respondents (self , cmix_survey_id , respondent_type , live ):
196
+ def get_survey_respondents (self , survey_id , respondent_type , live ):
197
197
self .check_auth_headers ()
198
198
respondents_url = '{}/surveys/{}/respondents?respondentType={}&respondentStatus={}' .format (
199
199
CMIX_SERVICES ['reporting' ]['BASE_URL' ],
200
- cmix_survey_id ,
200
+ survey_id ,
201
201
"LIVE" if live else "TEST" ,
202
202
respondent_type ,
203
203
)
204
204
respondents_response = requests .get (respondents_url , headers = self ._authentication_headers )
205
205
return respondents_response .json ()
206
206
207
- def get_survey_status (self , cmix_survey_id ):
207
+ def get_survey_status (self , survey_id ):
208
208
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 )
210
210
status_response = requests .get (status_url , headers = self ._authentication_headers )
211
211
status = status_response .json ().get ('status' , None )
212
212
if status is None :
213
213
raise CmixError ('Get Survey Status returned without a status. Response: {}' .format (status_response .json ()))
214
214
return status .lower ()
215
215
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 )
218
218
219
- def create_export_archive (self , cmix_survey , export_type ):
219
+ def create_export_archive (self , survey_id , export_type ):
220
220
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 )
222
222
headers = self ._authentication_headers .copy ()
223
223
headers ['Content-Type' ] = "application/json"
224
224
payload = {
@@ -246,7 +246,7 @@ def create_export_archive(self, cmix_survey, export_type):
246
246
)
247
247
archive_json = archive_response .json ()
248
248
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 )
250
250
layout_response = requests .get (layout_url , headers = self ._authentication_headers )
251
251
if layout_response .status_code != 200 :
252
252
raise CmixError (
@@ -268,25 +268,17 @@ def create_export_archive(self, cmix_survey, export_type):
268
268
)
269
269
270
270
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
280
272
281
273
def update_archive_status (self , archive ):
282
274
self .check_auth_headers ()
283
275
layout_id = archive .json .get ('dataLayoutId' , None )
284
276
archive_id = archive .json .get ('id' , None )
285
277
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 ))
287
279
if archive_id is None :
288
280
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 )
290
282
)
291
283
archive_url = '{}/surveys/{}/data-layouts/{}/archives/{}' .format (
292
284
CMIX_SERVICES ['survey' ]["BASE_URL" ],
@@ -301,7 +293,6 @@ def update_archive_status(self, archive):
301
293
archive_response ['id' ] = archive_id
302
294
archive .json = archive_response
303
295
else :
304
- archive .status = CmixDataArchive .PROCESSED
305
296
archive .download_url = archive_response .get ('archiveUrl' )
306
297
archive .save ()
307
298
return archive
@@ -377,12 +368,6 @@ def create_survey(self, survey, wave_number=None):
377
368
results_requested = False ,
378
369
secondary_key = secondary_key ,
379
370
)
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
- )
386
371
387
372
self .update_project (response_json .get ('projectId' ), status = self .SURVEY_STATUS_DESIGN )
388
373
0 commit comments