示例#1
0
def batchOutputPage(request, model='none', header='none'):
    viewmodule = importlib.import_module('.views', 'models.'+model)
    batchoutputmodule = importlib.import_module('.'+model+'_batchoutput', 'models.'+model)
    from REST import rest_funcs
    header = viewmodule.header
    linksleft = linksLeft.linksLeft()

    html = render_to_string('04uberbatch_start.html', {
            'model': model,
            'model_attributes': header+' Batch Output'})

    batchOutputPageFunc = getattr(batchoutputmodule, model+'BatchOutputPage')  # function name = 'model'BatchOutputPage  (e.g. 'sipBatchOutputPage')
    batchOutputTuple = batchOutputPageFunc(request)
    if model == 'przm':
        logging.info(batchOutputTuple)
        html = html + ''
    else:
        html = html + batchOutputTuple[0]
        html = html + render_to_string('export.html', {})
        html = html + render_to_string('04uberoutput_end.html', {})

        model_all = batchOutputTuple[1]
        jid_batch = batchOutputTuple[2]
        rest_funcs.batch_save_dic(html, [x.__dict__ for x in model_all], model, 'batch', jid_batch[0], linksleft)

    response = HttpResponse()
    response.write(html)
    return response
示例#2
0
def batchOutputPage(request, model='none', header='none'):

    viewmodule = importlib.import_module('.views', 'models.'+model)
    
    logging.info("===== batch.batchOutputPage")
    from REST import rest_funcs
    header = viewmodule.header
    linksleft = links_left.ordered_list()

    html = render_to_string('04uberbatch_start.html', {
            'model': model,
            'model_attributes': header+' Batch Output'})

    
    # Temporary logic to handle Pandas verions, else use old way
    if model in {'terrplant', 'sip', 'stir', 'trex', 'therps', 'iec',
            'agdrift', 'earthworm', 'rice', 'kabam'}:
        logging.info('=========== New Model Handler - Batch Run ===========')
        # New way
        modelBatch_obj = batchRun(request, model)

        tablesmodule = importlib.import_module('.'+model+'_tables', 'models.'+model)

        html = html + tablesmodule.timestamp(modelBatch_obj[0])

        batch_output_html = ""
        i = 0
        for model in modelBatch_obj:
           batch_output_html += tablesmodule.table_all(modelBatch_obj[i])
           i += 1

        html = html + batch_output_html
        html = html + render_to_string('export.html', {})
        html = html + render_to_string('04uberoutput_end.html', {})

    elif model == 'przm':
        # PRZM way
        logging.info(batchOutputTuple)
        html = html + ''

    else:
        # Old way
        batchoutputmodule = importlib.import_module('.'+model+'_batchoutput', 'models.'+model)
        batchOutputPageFunc = getattr(batchoutputmodule, model+'BatchOutputPage')  # function name = 'model'BatchOutputPage  (e.g. 'sipBatchOutputPage')
        batchOutputTuple = batchOutputPageFunc(request)

        html = html + batchOutputTuple[0]
        html = html + render_to_string('export.html', {})
        html = html + render_to_string('04uberoutput_end.html', {})

        model_all = batchOutputTuple[1]
        jid_batch = batchOutputTuple[2]
        
        try:
            rest_funcs.batch_save_dic(html, [x.__dict__ for x in model_all], model, 'batch', jid_batch[0], linksleft)
        except:
            pass

    response = HttpResponse()
    response.write(html)
    return response