def _process_request(self, request, update_instance=None): data = deepcopy(request.data) if 'profile' in data and data['profile'] == 'flow-results-package': data['profile'] = 'data-package' descriptor = BytesIO(json.dumps(data).encode('utf-8')) descriptor.seek(0, os.SEEK_END) floip_file = InMemoryUploadedFile(descriptor, 'floip_file', request.data.get('name') + '.json', 'application/json', descriptor.tell(), charset=None) kwargs = { 'user': request.user, 'post': None, 'files': { 'floip_file': floip_file }, 'owner': request.user, } if update_instance: kwargs['id_string'] = update_instance.id_string kwargs['project'] = update_instance.project instance = do_publish_xlsform(**kwargs) if isinstance(instance, XForm): return instance raise serializers.ValidationError(instance)
def publish_xlsform_async(self, user_id, post_data, owner_id, file_data): try: files = MultiValueDict() files[u'xls_file'] = default_storage.open(file_data.get('path')) owner = User.objects.get(id=owner_id) if owner_id == user_id: user = owner else: user = User.objects.get(id=user_id) survey = tools.do_publish_xlsform(user, post_data, files, owner) default_storage.delete(file_data.get('path')) if isinstance(survey, XForm): return {"pk": survey.pk} return survey except Exception as exc: if isinstance(exc, MemoryError): if self.request.retries < 3: self.retry(exc=exc, countdown=1) else: error_message = ( u'Service temporarily unavailable, please try to ' 'publish the form again') else: error_message = str(sys.exc_info()[1]) return {u'error': error_message}
def publish_xlsform_async(self, user, post_data, owner, file_data): try: files = MultiValueDict() files[u'xls_file'] = \ (InMemoryUploadedFile( BytesIO(file_data.get('data')), None, file_data.get('name'), u'application/octet-stream', len(file_data.get('data')), None) if file_data.get('data') else recreate_tmp_file(file_data.get('name'), file_data.get('path'), u'application/octet-stream')) survey = tools.do_publish_xlsform(user, post_data, files, owner) if isinstance(survey, XForm): return {"pk": survey.pk} return survey except Exception, exc: if isinstance(exc, MemoryError): if self.request.retries < 3: self.retry(exc=exc, countdown=1) else: error_message = ( u'Service temporarily unavailable, please try to ' 'publish the form again' ) else: error_message = unicode(sys.exc_info()[1]) return {u'error': error_message}
def publish_xlsform_async(self, user, post_data, owner, file_data): try: files = MultiValueDict() files[u'xls_file'] = \ (InMemoryUploadedFile( BytesIO(file_data.get('data')), None, file_data.get('name'), u'application/octet-stream', len(file_data.get('data')), None) if file_data.get('data') else recreate_tmp_file(file_data.get('name'), file_data.get('path'), u'application/octet-stream')) survey = tools.do_publish_xlsform(user, post_data, files, owner) if isinstance(survey, XForm): return {"pk": survey.pk} return survey except Exception as exc: if isinstance(exc, MemoryError): if self.request.retries < 3: self.retry(exc=exc, countdown=1) else: error_message = ( u'Service temporarily unavailable, please try to ' 'publish the form again' ) else: error_message = str(sys.exc_info()[1]) return {u'error': error_message}
def _process_request(self, request, update_instance=None): data = deepcopy(request.data) if 'profile' in data and data['profile'] == 'flow-results-package': data['profile'] = 'data-package' descriptor = BytesIO(json.dumps(data).encode('utf-8')) descriptor.seek(0, os.SEEK_END) floip_file = InMemoryUploadedFile( descriptor, 'floip_file', request.data.get('name') + '.json', 'application/json', descriptor.tell(), charset=None) kwargs = { 'user': request.user, 'post': None, 'files': {'floip_file': floip_file}, 'owner': request.user, } if update_instance: kwargs['id_string'] = update_instance.id_string kwargs['project'] = update_instance.project instance = do_publish_xlsform(**kwargs) if isinstance(instance, XForm): return instance raise serializers.ValidationError(instance)
def publish_xlsform_async(user, post_data, owner, file_data): try: files = MultiValueDict() files[u'xls_file'] = \ (InMemoryUploadedFile( BytesIO(file_data.get('data')), None, file_data.get('name'), u'application/octet-stream', len(file_data.get('data')), None) if file_data.get('data') else recreate_tmp_file(file_data.get('name'), file_data.get('path'), u'application/octet-stream')) survey = tools.do_publish_xlsform(user, post_data, files, owner) if isinstance(survey, XForm): return {"pk": survey.pk} return survey except: e = sys.exc_info()[0] return {u'error': str(e)}