def algorithm_page(request, model='none', header='none'): print(request.path) print('ubertool_app.views.algorithm_page') #get formatted model name and description for description page model = model.lstrip('/') header = get_model_header(model) algorithm = get_model_algorithm(model) html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': header + ' Algorithms'}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL'], 'MODEL': model, 'PAGE': 'algorithm'}) html += render_to_string('04uberalgorithm_start.html', {}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': header + ' Algorithms', 'TEXT_PARAGRAPH': algorithm}) html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list(model, 'algorithms') html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
def historyPage(request, model="none", header="none"): """ Django view render method for model's history page, showing all of the user's previously saved model runs. """ viewmodule = importlib.import_module(".views", "models." + model) header = viewmodule.header html = render_to_string("01uberheader.html", {"site_skin": os.environ["SITE_SKIN"], "title": header + " History"}) html = html + render_to_string( "02uberintroblock_wmodellinks.html", {"site_skin": os.environ["SITE_SKIN"], "model": model, "page": "history"} ) html = html + links_left.ordered_list() html = html + render_to_string("04uberalgorithm_start.html", {"model_attributes": header + " User History"}) # Conditional template loading if model == "sam": html = html + render_to_string("history_query_sam.html", {"model": model}) else: html = html + render_to_string("history_query.html", {"model": model}) # """ # rest_func method call to return user's model runs for the current model # rest_funcs.UserHistory('user_id', 'model_name') # """ # hist_obj = rest_funcs.UserHistory('admin', model) # html = html + table_all(hist_obj) html = html + render_to_string("04ubertext_end.html", {}) html = html + render_to_string("06uberfooter.html", {"links": ""}) response = HttpResponse() response.write(html) return response
def batch_page(request, model='none', header='none'): viewmodule = importlib.import_module('.views', 'models.'+model) header = viewmodule.header html = render_to_string('01uberheader.html', { 'site_skin' : os.environ['SITE_SKIN'], 'title': header+' Batch'}) html = html + render_to_string('02uberintroblock_wmodellinks.html', { 'site_skin' : os.environ['SITE_SKIN'], 'model':model, 'page':'batchinput'}) html = html + links_left.ordered_list() #html = html + render_to_string('04uberbatchinput.html', { # 'model': model, # 'model_attributes': header+' Batch Run'}) #if model == 'przm': # html = html + render_to_string('04uberbatchinput_jquery_przm_batch.html', {'model':model, 'header':header}) #else: # html = html + render_to_string('04uberbatchinput_jquery.html', {'model':model, 'header':header}) #html = html + render_to_string('05ubertext_links_right.html', {}) html = html + render_to_string('06uberfooter.html', {'links': ''}) response = HttpResponse() response.write(html) return response
def output_page(request, model='none', header=''): """ Django HTTP POST handler for output page. Receives form data and validates it. If valid it calls method to render the output page view. If invalid, it returns the error to the model input page. This method maps to: '/ubertool/<model>/output' """ #model_module_location = 'ubertool_app.models.' + model + '.' + model + '_input' model_views_location = 'ubertool_app.models.' + model + '.views' viewmodule = importlib.import_module(model_views_location) header = viewmodule.header model_parameters_location = 'ubertool_app.models.' + model + '.' + model + '_parameters' model_input_location = 'ubertool_app.models.' + model + '.' + model + '_input' parametersmodule = importlib.import_module(model_parameters_location) try: # Class name must be ModelInp, e.g. SipInp or TerrplantInp input_form = getattr(parametersmodule, model.title() + 'Inp') form = input_form(request.POST) # bind user inputs to form object # Form validation testing if form.is_valid(): # If form is valid return the output page view return output_page_view(request, model, header) else: # If Form is not valid, redraw Input page (this is the same as 'input.py', expect for 'form_data') logging.info(form.errors) input_module = importlib.import_module(model_input_location) # Render input page view with POSTed values and show errors html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': header}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL'], 'MODEL': model, 'PAGE': 'input'}) input_page_func = getattr(input_module, model + '_input_page') # function name example: 'sip_input_page' html += input_page_func(request, model, header, form_data=request.POST) # form_data contains the already POSTed form data html += links_left.ordered_list(model, 'run_model') html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response # end form validation testing except Exception, e: logging.exception(e) logging.info("E X C E P T") return output_page_view(request, model, header)
def eco_landing_page_new(request): text_file2 = open(os.path.join(os.environ['PROJECT_PATH'], 'ubertool_app/views/landing_text.txt'), 'r') xx = text_file2.read() #html = render_to_string('01epa_drupal_header.html', {}) html = render_to_string('01epa_drupal_header.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': u"\u00FCbertool" }) #html = render_to_string('01uberheader_main_drupal.html', { # 'SITE_SKIN': os.environ['SITE_SKIN'], # 'TITLE': u"\u00FCbertool" #}) html += render_to_string('02epa_drupal_header_bluestripe.html', {}) html += render_to_string('04uber_drupal_frog_intro.html', {}) #http://jsfiddle.net/9zGQ8/ html += links_left.ordered_list() #fills out 05ubertext_links_left_drupal.html html += render_to_string('06ubertext_start_index_drupal.html', { 'TITLE': u"\u00FCbertool", 'TEXT_PARAGRAPH': xx }) html += render_to_string('07ubertext_end_drupal.html', {}) #html += render_to_string('06uberfooter.html', {}) html += render_to_string('10epa_drupal_footer.html', {}) response = HttpResponse() response.write(html) return response
def qaqcRunView(request, model='none', runID=''): """ View to render the QAQC output page HTML """ viewmodule = importlib.import_module('.views', 'models.'+model) tablesmodule = importlib.import_module('.'+model+'_tables', 'models.'+model) from REST import rest_funcs header = viewmodule.header html = render_to_string('01uberheader.html', { 'site_skin' : os.environ['SITE_SKIN'], 'title': header+' QA/QC'}) html = html + render_to_string('02uberintroblock_wmodellinks.html', { 'site_skin' : os.environ['SITE_SKIN'], 'model':model, 'page':'qaqc'}) html = html + links_left.ordered_list() html = html + render_to_string('04uberoutput_start.html', { 'model':model, 'model_attributes': header+' QAQC'}) # Temporary logic to handle Pandas versions, else use old way if model in {'terrplant', 'sip', 'stir', 'trex', 'therps', 'iec', 'agdrift', 'earthworm', 'rice', 'kabam'}: import logging logging.info('=========== New Model Handler - QAQC Run ===========') modelQAQC_obj = qaqcRun(model) html = html + tablesmodule.timestamp(modelQAQC_obj[0]) qaqc_output_html = "" i = 0 for model in modelQAQC_obj: qaqc_output_html += tablesmodule.table_all_qaqc(modelQAQC_obj[i]) i += 1 html = html + qaqc_output_html else: try: modelQAQC_obj = getattr(qaqcmodule, model+'_obj') # Calling model object, e.g. 'sip_obj' html = html + tablesmodule.timestamp(modelQAQC_obj) html = html + tablesmodule.table_all_qaqc(modelQAQC_obj) except: html += "" try: rest_funcs.save_dic(html, modelQAQC_obj.__dict__, model, 'qaqc') except: pass html = html + render_to_string('export.html', {}) html = html + render_to_string('04uberoutput_end.html', {'sub_title': ''}) html = html + render_to_string('06uberfooter.html', {'links': ''}) response = HttpResponse() response.write(html) return response
def qaqc_page(request, model='none'): """ View to render QAQC page HTML for each model """ print(request.path) print('ubertool_app.views.qaqc_page') model = model.lstrip('/') header = get_model_header(model) qaqc = get_model_qaqc(model) #viewmodule = importlib.import_module('.views', 'ubertool_app.models.'+model) #header = viewmodule.header html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': header + ' QAQC'}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL'], 'MODEL': model, 'PAGE': 'qaqc'}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': header + ' QAQC', 'TEXT_PARAGRAPH': qaqc}) html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list(model, 'qaqc') html += render_to_string('06uberfooter.html', {}) # html = render_to_string('01uberheader.html', { # 'site_skin' : os.environ['SITE_SKIN'], # 'title': header+' QA/QC'}) # html = html + render_to_string('02uberintroblock_wmodellinks.html', { # 'site_skin' : os.environ['SITE_SKIN'], # 'model':model, # 'page':'qaqc'}) # html = html + links_left.ordered_list() # #html = html + render_to_string('04uberqaqc_start.html', { # # 'model':model, # # 'model_attributes': header+' QAQC'}) # html = html + render_to_string('06uberfooter.html', {'links': ''}) response = HttpResponse() response.write(html) return response
def file_not_found(request): html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': 'Error'}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL']}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': 'Error Processing Request', 'TEXT_PARAGRAPH': ""}) html += """<br><img src="/static/images/404error.png" width="300" height="300">""" html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list() html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
def links(request): html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': u"\u00FCbertool Links"}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL']}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': u"\u00FCbertool External Links", 'TEXT_PARAGRAPH': ""}) html += render_to_string('05ubertext_links_right.html') html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list() html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
def login(request): next_page = request.GET['next'] # Page to redirect to with successful login html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': 'Login'}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL']}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': 'User Login', 'TEXT_PARAGRAPH': ""}) html += render_to_string('login_prompt.html', {'next': next_page}) html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list() html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
def output_page_html(header, model, tables_html): """Generates HTML to fill '.articles_output' div on output page""" html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': header}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL'], 'MODEL': model, 'PAGE': 'description'}) html += render_to_string('04uberoutput_start_drupal.html', { 'TITLE': header + ' Output'}) html += tables_html # if model is not "sam": # print " model: " + model # html += render_to_string('export.html', {}) html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list(model, 'run_model') html += render_to_string('06uberfooter.html', {}) return html
def eco_landing_page(request): text_file2 = open(os.path.join(os.environ['PROJECT_PATH'], 'ubertool_app/views/landing_text.txt'), 'r') xx = text_file2.read() html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': u"\u00FCbertool" }) html += render_to_string('02uberintroblock_nomodellinks_drupal.html', {}) html += render_to_string('04ubertext_start_index_drupal.html', { 'TITLE': u"\u00FCbertool", 'TEXT_PARAGRAPH': xx }) html += render_to_string('04ubertext_end_drupal.html', {}) html += links_left.ordered_list() html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
def przm5IntermediatePage(request): data_all = json.loads(request.body) data_html = data_all["data_html"] logger.info(data_html) jid = str(data_all["jid"]) html = render_to_string('01uberheader.html', { 'site_skin' : os.environ['SITE_SKIN'], 'title': 'PRZM5'+' Output'}) html = html + render_to_string('02uberintroblock_wmodellinks.html', { 'site_skin' : os.environ['SITE_SKIN'], 'model':'przm5', 'page':'output'}) html = html + links_left.ordered_list() html = html + render_to_string('04uberoutput_start.html', {}) html = html + data_html html = html + render_to_string('export.html', {}) html = html + render_to_string('04uberoutput_end.html', {}) html = html + render_to_string('06uberfooter.html', {'links': ''}) rest_funcs.update_html(html, jid, 'przm5') response = HttpResponse() response.write(html) return response
def input_page(request, model='none', header='none'): print(request.path) print('ubertool_app.views.input_page') # If on public server, test user authentication # if settings.AUTH: # if settings.MACHINE_ID == secret.MACHINE_ID_PUBLIC: # if not request.user.is_authenticated(): # return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) #viewmodule = importlib.import_module('.views', 'models.'+model) #inputmodule = importlib.import_module('.'+model+'_input', 'models.'+model) #header = viewmodule.header #get formatted model name and description for description page model = model.lstrip('/') header = get_model_header(model) input_module = get_model_input_module(model) # import logging # if formData != None: # logging.info("===================== N O N E ==========================") # html = render_to_string('01uberheader.html', {'title': header+' Inputs'}) # html = html + render_to_string('02uberintroblock_wmodellinks.html', {'model':model,'page':'input'}) # html = html + ordered_list.ordered_list() # input_page_func = getattr(inputmodule, model+'InputPage') # function name = 'model'InputPage (e.g. 'sipInputPage') # html = html + input_page_func(request, model, header, formData) # html = html + render_to_string('06uberfooter.html', {'links': ''}) # response = HttpResponse() # response.write(html) # return response # VALIDATE FORM HERE IF FORM IS POSTED TO THIS VIEW # if request.method == "POST": # parametersmodule = importlib.import_module('.'+model+'_parameters', 'models.'+model) # inputForm = getattr(parametersmodule, model.upper() + 'Inp') # logging.info(inputForm) # form = inputForm(request.POST) # logging.info(form) # if form.is_valid(): # outputmodule = importlib.import_module('.'+model+'_output', 'models.'+model) # return outputmodule(request) # else: # html = render_to_string('01uberheader.html', {'title': header+' Inputs'}) # html = html + render_to_string('02uberintroblock_wmodellinks.html', {'model':model,'page':'input'}) # html = html + ordered_list.ordered_list() # input_page_func = getattr(inputmodule, model+'InputPage') # function name = 'model'InputPage (e.g. 'sipInputPage') # html = html + input_page_func(request, model, header, formData=request.POST) # html = html + render_to_string('06uberfooter.html', {'links': ''}) # response = HttpResponse() # response.write(html) # return response # else: html = render_to_string('01uberheader_main_drupal.html', { 'SITE_SKIN': os.environ['SITE_SKIN'], 'TITLE': header}) html += render_to_string('02uberintroblock_wmodellinks_drupal.html', { 'CONTACT_URL': os.environ['CONTACT_URL'], 'MODEL': model, 'PAGE': 'input'}) # function name example: 'sip_input_page' input_page_func = getattr(input_module, model + '_input_page') html += input_page_func(request, model, header) html += links_left.ordered_list(model, 'run_model') html += render_to_string('06uberfooter.html', {}) response = HttpResponse() response.write(html) return response
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
def output_page_view(request, model='none', header=''): """ Django view render method for model output pages. This method is called by output_page() method. """ # If model is updated to be generic, use generic Model object # if not, use old method with '*_output' module if model in _UPDATED_MODELS: logging.info('=========== New Model Handler - Single Model Run ===========') from ubertool_app.models import model_handler model_obj = model_handler.modelInputPOSTReceiver(request, model) elif model in {'sam'}: logging.info('=========== New Model Handler FORTRAN ===========') from ubertool_app.models import model_handler if model == 'sam': """ SAM takes a long time to run relative to other models; therefore, it will not return model results on form submit, but will instead return a confirmation of model submission to the user. Model results will be available at a later time (e.g. from the History page). """ import ubertool_app.models.sam.sam_tables as tablesmodule if request.POST['scenario_selection'] == '0': """ Custom Run """ # Run SAM - no return expected jid = model_handler.modelInputPOSTReceiverFortran(request, model) disclaimer_html = """ <h3>Disclaimer:</h3> <p>Ecological risk calculations contained here should be used for no purpose other than quality assurance and peer review of the presented web applications. This web site is under development. It is available for the purposes of receiving feedback and quality assurance from personnel in the EPA Office of Chemical Safety and Pollution Prevention and from interested members of the ecological risk assessment community.</p> """ """ Generate Timestamp HTML from "*_tables" module """ model_output_html = tablesmodule.timestamp() """ Generate Model input & output tables HTML from "*_tables" module """ try: tables_output = tablesmodule.table_all(request, jid) except: tables_output = tablesmodule.table_all(request, "20150402133114784000") model_output_html = disclaimer_html + model_output_html + tables_output """ Render output page view HTML """ html = output_page_html(header, model, model_output_html) else: """ Pre-Canned Run """ """ Generate Timestamp HTML from "*_tables" module """ model_output_html = tablesmodule.timestamp() """ Generate Model input & output tables HTML from "*_tables" module """ tables_output = tablesmodule.table_all(request) model_output_html = model_output_html + tables_output """ Render output page view HTML """ html = output_page_html(header, model, model_output_html) response = HttpResponse() response.write(html) return response else: model_obj = model_handler.modelInputPOSTReceiverFortran(request, model) elif model in {'ore'}: """ TEMPORARY FOR ORE TESTING / DEVELOPMENT ON ECO """ import ubertool_app.models.ore.ore_output tables_html = ubertool_app.models.ore.ore_output.oreOutputPage(request) html = render_to_string('01uberheader.html', { 'site_skin': os.environ['SITE_SKIN'], 'title': header + ' Output'}) html += render_to_string('02uberintroblock_wmodellinks.html', { 'site_skin': os.environ['SITE_SKIN'], 'model': model, 'page': 'output'}) html += links_left.ordered_list() html += render_to_string('04uberoutput_start.html', { 'model_attributes': header + ' Output'}) html += tables_html html += render_to_string('export.html', {}) html += render_to_string('04uberoutput_end.html', {'model': model}) html += render_to_string('06uberfooter.html', {'links': ''}) response = HttpResponse() response.write(html) return response else: # TODO: This section should be removed as it is not used anymore...(pre-objectifying method) # All models that use the 'model_output.py' to format the inputs before sending to back end server # Dynamically import the model output module outputmodule = importlib.import_module('.' + model + '_output', 'ubertool_app.models.' + model) # Call '*_output' function; function name = 'model'OutputPage (e.g. 'sipOutputPage') outputPageFunc = getattr(outputmodule, model + 'OutputPage') model_obj = outputPageFunc(request) logging.info(model_obj) if type(model_obj) is tuple: model_output_html = model_obj[0] model_obj = model_obj[1] else: # Dynamically import the model table module tablesmodule = importlib.import_module('.' + model + '_tables', 'ubertool_app.models.' + model) # logging.info(model_obj.__dict__) """ Generate Timestamp HTML from "*_tables" module """ model_output_html = tablesmodule.timestamp(model_obj) """ Generate Model input & output tables HTML from "*_tables" module """ tables_output = tablesmodule.table_all(model_obj) """ Append Timestamp & model input & output table's HTML """ if type(tables_output) is tuple: model_output_html = model_output_html + tables_output[0] elif type(tables_output) is str or type(tables_output) is unicode: model_output_html = model_output_html + tables_output else: model_output_html = "table_all() Returned Wrong Type" """ Render output page view HTML """ html = output_page_html(header, model, model_output_html) # TODO: this is only used for non-Pandas models, and is DEPRECATED and should be removed and not called def saveToMongoDB(model_obj): """ Method to check if model run is to be saved to MongoDB. If true, the fest_func method to save the model object instance is called """ from REST import rest_funcs # Handle Trex, which is not objectified yet; therefore, not saved in MongoDB # if model != 'trex': if model not in {'terrplant', 'sip', 'stir', 'trex', }: logging.info("rest_funcs.save_model_object() called") # save_dic() rest_func method saves HTML & model object rest_funcs.save_dic(html, model_obj.__dict__, model, "single") # TODO: Remove this # Call method to save model object to Mongo DB # saveToMongoDB(model_obj) """ ============================================== """ """ ============================================== """ response = HttpResponse() response.write(html) return response