Beispiel #1
0
 def to_xlsx(self, data, options=None):
     logger.info(
         'serialize Non-streamed Screenresult using generic serialization')
     response = get_xls_response(data, 'generic_file')
     return self.get_content(response)
Beispiel #2
0
 def to_xlsx(self, data, options=None):
     logger.info(
         'serialize Non-streamed Screenresult using generic serialization')
     response = get_xls_response(data, 'generic_file')
     return self.get_content(response)
Beispiel #3
0
    def stream_response_from_cursor(
            self,request,result,output_filename, field_hash={}, param_hash={}, 
            is_for_detail=False, downloadID=None, title_function=None, 
            meta=None):
          
        try:

            list_brackets = LIST_BRACKETS
            if ( param_hash.get(HTTP_PARAM_DATA_INTERCHANGE, False)
                or request.GET.get(HTTP_PARAM_RAW_LISTS, False)):
                list_brackets = None
    
            content_type = self.get_accept_content_type(
                request, format=param_hash.get('format', None))
            logger.debug('content_type: %s',content_type)
            
            image_keys = [key for key,field in field_hash.items()
                if field.get('display_type', None) == 'image']
            ordered_keys = sorted(field_hash.keys(), 
                key=lambda x: field_hash[x].get('ordinal',key))
            list_fields = [ key for (key,field) in field_hash.items() 
                if( field.get('json_field_type',None) == 'fields.ListField' 
                    or field.get('linked_field_type',None) == 'fields.ListField'
                    or field.get('data_type', None) == 'list' ) ]
            value_templates = {key:field['value_template'] 
                for key,field in field_hash.items() if field.get('value_template', None)}
            data = cursor_generator(
                result,ordered_keys,list_fields=list_fields,
                value_templates=value_templates)
                
            response = None
            if content_type == JSON_MIMETYPE:
                response = StreamingHttpResponse(
                    ChunkIterWrapper(
                        json_generator(
                            image_generator(data, image_keys, request), 
                            meta, is_for_detail=is_for_detail)))
                response['Content-Type'] = content_type
            
            elif( content_type == XLS_MIMETYPE or
                content_type == XLSX_MIMETYPE ): 

                data = {
                    'data': data 
                }
                response = get_xls_response(
                    data, output_filename, request=request, 
                    title_function=title_function, image_keys=image_keys,
                    list_brackets=list_brackets)

            elif content_type == SDF_MIMETYPE:
                
                response = StreamingHttpResponse(
                    ChunkIterWrapper(
                        sdf_generator(
                            image_generator(data,image_keys, request), 
                            title_function=title_function)),
                    content_type=content_type)
                response['Content-Disposition'] = \
                    'attachment; filename=%s.sdf' % output_filename
            
            elif content_type == CSV_MIMETYPE:
                response = StreamingHttpResponse(
                    ChunkIterWrapper(
                        csv_generator(
                            image_generator(data, image_keys, request), 
                            title_function=title_function, 
                            list_brackets=list_brackets)),
                    content_type=content_type)
                response['Content-Disposition'] = \
                    'attachment; filename=%s.csv' % output_filename
            else:
                msg = 'unknown content_type: %r' % content_type
                raise BadRequest(msg)
            return response

        except Exception, e:
            logger.exception('on stream response')
            raise e