Esempio n. 1
0
 def index(self, search=None):
     template = env.get_template('index.html')
     if cherrypy.request.method == 'POST':
         stocks = self.get_filter_result(search)
     else:
         stocks = self.get_stocks()
     return template.render(stocks=stocks)
Esempio n. 2
0
 def render_template(self):
     try:
         template = env.get_template(self.template_name)
     except:
         raise NoSuchTemplate("Cannot find template '{0} in templates directory".format(self.template_name))
     output = template.render(self.get_context_data())
     return output
    def index(self):
        tmpl = env.get_template('index.html')
        return tmpl.render( hostaddress=hostaddress, 
		admin_email=admin_email,
		reference=reference,
		servername=servername, 
		hostparent=hostparent,
		exampleid=exampleid, 
		last_updated_time=last_updated_time )
        def __call__( self, jobid ) :
		info = read_user_info( jobid )
		try :
			if self.is_completed(jobid ) :
				tmpl = env.get_template( 'view.html' )
				motifids = range( 1, max_motif_id+1 )
				selection = self.select_tomtom_matches( jobid )
				motifscore = MotifScore( jobid )
				passed_motifids = motifscore.get_passed_motifids()

				return tmpl.render( servername=servername,
					hostaddress=hostaddress,
					hostparent=hostparent,
					jobid=jobid, 
					userInfo=info,
					motifids=motifids, 
					passed_motifids= passed_motifids,
					selection=selection,
					reference=reference, 
					admin_email=admin_email )
			else :
				tmpl = env.get_template( 'view_check.html' )
				check_result = '<b>Your job has not been finished yet. Check few minutes later.</b>'
				return tmpl.render( servername=servername,
					check_result= check_result,
					hostparent=hostparent,
					jobid=jobid, 
					userInfo=info,
					reference=reference, 
					admin_email=admin_email )

		except JobFailureError :
			tmpl = env.get_template( 'view_check.html' )
			check_result = '<strong>A problem occurred while processing your job. We are working on it and we will get back to you shortly.</strong>'
			return tmpl.render( servername=servername,
				check_result= check_result,
				hostparent=hostparent,
				jobid=jobid, 
				userInfo=info,
				reference=reference, 
				admin_email=admin_email )
Esempio n. 5
0
def get_picture_html(records, columns=5, output_html=None):
    template = env.get_template('drug_picture.html')
    object_lists = []

    for i in range(0, len(records), columns):
        object_lists.append(records[i:i + columns])

    html = template.render(object_lists=object_lists)

    if output_html:
        with open(output_html, 'wt', encoding='utf-8') as fp:
            fp.write(html)
    else:
        return html
Esempio n. 6
0
 def render_element(self) -> str:
     super().render_element()
     template = env.get_template(f'{type(self).__name__}.j2')
     render_data: str = template.render(element=self)
     return render_data
Esempio n. 7
0
def error_page(rq, rs, exc):
    logging.exception(exc)
    rs.write(env.get_template("error.html").render())
    rs.headers['Content-Type'] = "text/html"
    rs.set_status(500)
        def __call__( self, myFile, email, db, fileformat, normtype, jobname, cell, treatment, lab, summitcol='' ) :
        # dealing uploaded file.
        # myFile contains file handle for the uploaded peak file
        # email should be given all the time!
        # fileformat value can be either 'narrowpeak' or 'bed'
        # db can be 'hg19' or 'mm9' depending on which genome the experiment were performed.
        # normtype can be 'summit' or 'center'
        # summitcol should be either None or 'col<column number>' where the column number should be
        # in 1 based ordering
        # jobname can be either None or name of the job or TF depending on the user input.

        ## This is very useful trick to check the internal structure of submitted and parsed values.
        #def __call__( self, **kwargs ) :
                #print kwargs
                #return

                tmpl = env.get_template( 'uploaded.html' )

                #1. make the save_dir
                save_dir = mkdtemp( dir=user_dir, prefix='fmp' )
                jobid = basename( save_dir )

                #2. save  uploaded file into the save_dir
                save_fn = join( save_dir, jobid )
                save_fp = open( save_fn, 'w' )

		#old read line to use all lines
                #size = 0
                #while True:
                #    data = myFile.file.read(8192)
                #    if not data:
                #        break
                #    size += len(data)
                #    save_fp.write( data )
                #save_fp.close()

		#new read line to use top N lines
		for i, l in enumerate(myFile.file) :
			if use_top_lines and i >= use_top_lines :
				break
			save_fp.write(l)
		save_fp.close()

		#read the end of the uploaded file and tell the size
		myFile.file.seek(0,2)
		size = myFile.file.tell()

                #3. save user information
                data_fp = open( join( save_dir, user_data_fn ), "w" )
                print >>data_fp, "jobname:", jobname
                print >>data_fp, "cell:", cell
                print >>data_fp, "treatment:", treatment
                print >>data_fp, "lab:", lab
                print >>data_fp, "email:", email
                print >>data_fp, "filename:", myFile.filename
                print >>data_fp, "mime-type:", myFile.content_type
                print >>data_fp, 'db:', db
                print >>data_fp, 'normtype:', normtype
                print >>data_fp, 'fileformat:', fileformat
                print >>data_fp, 'summitcol:', summitcol
                data_fp.close()

                #4. submit the jobscript
                self.submit(jobid)

                return tmpl.render( filename=myFile.filename, jobname=jobname, email=email, jobid=jobid, size=size, mimetype=myFile.content_type )
Esempio n. 9
0
def render_to_string(filename, context={}):
    template = env.get_template(filename)
    rendered = template.render(**context)
    return rendered
Esempio n. 10
0
def render(tpl, context):
    #print(env.loader.list_templates())
    t = env.get_template(tpl)
    return t.render(context)
Esempio n. 11
0
def render(template, data=None, *args, **kw):
    content = env.get_template(template).render(**(data or {}))
    return webapp2.Response(content, *args, **kw)