def view(qdict, argdict): # This function is currently implemented to generate a text document containing # summary of the form data. # Generate html document header. print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<body>' # Generate preview. print '<pre>' for line in gentext(argdict).splitlines(): sline = line.rstrip() print sline print '</pre>' # Add hidden form data with some buttons. print '<form action="%s/request.py" method="post" target="_self">' % dbconfig.rel_url # Add hidden form data. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) for key in argdict: if key != 'view': print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(argdict[key])) # Add buttons. print '<input type="submit" name="submit" value="Submit">' print '<input type="submit" name="reload" value="Back">' # Done with form. print '</form>' # Generate document trailer. print '</body>' print '</html>' # Done. return
def convert_args(argdict, k=None, v=None): result = '' for key in argdict: if result != '': result += '&' value = None if key == k: value = v else: value = argdict[key] result += '%s=%s' % (dbutil.convert_str(key), dbutil.convert_str(value)) # Done return result
def request_form(cnx, qdict, argdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed() and dbutil.restricted_access( cnx, 'projects', id): disabled = 'disabled' #for key in qdict: # print '%s = %s' % (key, qdict[key]) # print '<br>' #print '<br>' #for key in argdict: # print '%s = %s' % (key, argdict[key]) # print '<br>' #print '<br>' # Generate form. print '<h2>Sample Request</h2>' print '<form action="%s/request.py" method="post" target="_self">' % dbconfig.rel_url print '<input type="submit" name="reload" value="Reload">' print '<br>' print '<br>' # Put input fields in a table. print '<table border=1 style="border-collapse:collapse">' # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Add readonly requester field. user = '' if 'SSO_USERID' in os.environ: user = os.environ['SSO_USERID'] print '<tr>' print '<td><label for="user">Requester: </label></td>' print '<td><input type="text" id="user" name="user" value="%s" readonly></td>' % user print '</tr>' # Sample name field. name = '' if 'name' in argdict: name = argdict['name'] print '<tr>' print '<td><label for="name">Sample name: </label></td>' print '<td><input type="text" id="name" name="name" size=80 value="%s"></td>' % name print '</tr>' # Sample description field. desc = '' if 'description' in argdict: desc = argdict['description'] print '<tr>' print '<td><label for="description">Sample description: </label></td>' print '<td><textarea id="description" name="description" rows=2 cols=80>' print desc, print '</textarea></td>' print '</tr>' # Version field. version = '' if 'version' in argdict: version = argdict['version'] print '<tr>' print '<td><label for="version">Release version: </label></td>' print '<td><input type="text" id="version" name="version" size=80 value="%s"></td>' % version print '</tr>' # Input dataset field. input = '' if 'input' in argdict: input = argdict['input'] print '<tr>' print '<td><label for="input">Input dataset: </label></td>' print '<td><input type="text" id="input" name="input" size=80 value="%s"></td>' % input print '</tr>' # Experiment field. selexp = '' if 'exp' in argdict: selexp = argdict['exp'] print '<tr>' print '<td><label for="exp">Experiment: </label></td>' print '<td><select id="exp" name="exp" size=0>' for experiment in dbconfig.pulldowns['experiment']: sel = '' if experiment == selexp: sel = 'selected' print '<option value="%s" %s>%s</option>' % (experiment, sel, experiment) print '</select></td>' print '</tr>' # File type field. selftype = '' if 'ftype' in argdict: selftype = argdict['ftype'] print '<tr>' print '<td><label for="ftype">File type: </label></td>' print '<td><select id="ftype" name="ftype" size=0>' for file_type in dbconfig.pulldowns['file_type']: sel = '' if file_type == selftype: sel = 'selected' print '<option value="%s" %s>%s</option>' % (file_type, sel, file_type) print '</select></td>' print '</tr>' # Role field. selrole = '' if 'role' in argdict: selrole = argdict['role'] print '<tr>' print '<td><label for="role">Role: </label></td>' print '<td><select id="role" name="role" size=0>' for role in dbconfig.pulldowns['role']: sel = '' if role == selrole: sel = 'selected' print '<option value="%s" %s>%s</option>' % (role, sel, role) print '</select></td>' print '</tr>' # Campaign field. selcamp = '' if 'camp' in argdict: selcamp = argdict['camp'] print '<tr>' print '<td><label for="camp">Campaign: </label></td>' print '<td><select id="camp" name="camp" size=0>' for campaign in dbconfig.pulldowns['campaign']: sel = '' if campaign == selcamp: sel = 'selected' print '<option value="%s" %s>%s</option>' % (campaign, sel, campaign) print '</select></td>' print '</tr>' # Working group field. selgrp = '' if 'wgroup' in argdict: selgrp = argdict['wgroup'] print '<tr>' print '<td><label for="wgroup">Working group: </label></td>' print '<td><select id="wgroup" name="wgroup" size=0>' for group in dbconfig.pulldowns['physics_group']: sel = '' if group == selgrp: sel = 'selected' print '<option value="%s" %s>%s</option>' % (group, sel, group) print '</select></td>' print '</tr>' # Target date field. date = '' if 'date' in argdict: date = argdict['date'] print '<tr>' print '<td><label for="date">Target date: </label></td>' print '<td><input type="date" id="date" name="date" value="%s"></td>' % date print '</tr>' # Priority field. selpri = 'low' if 'priority' in argdict: selpri = argdict['priority'] print '<tr>' print '<td><label for="priority">Priority: </label></td>' print '<td><select id="priority" name="priority" size=0>' for priority in ('low', 'medium', 'high'): sel = '' if priority == selpri: sel = 'selected' print '<option value="%s" %s>%s</option>' % (priority, sel, priority) print '</select></td>' print '</tr>' # Number of events field. num_events = 0 if 'num_events' in argdict: num_events = int(argdict['num_events']) print '<tr>' print '<td><label for="num_events">Number of events: </label></td>' print '<td><input type="number" id="num_events" name="num_events" value=%d></td>' % num_events print '</tr>' # Number of jobs. num_jobs = 0 if 'num_jobs' in argdict: num_jobs = int(argdict['num_jobs']) print '<tr>' print '<td><label for="num_jobs">Number of jobs: </label></td>' print '<td><input type="number" id="num_jobs" name="num_jobs" value=%d></td>' % num_jobs print '</tr>' # Maximum files per job. max_files = 0 if 'max_files' in argdict: max_files = int(argdict['max_files']) print '<tr>' print '<td><label for="max_files">Maximum files per job: </label></td>' print '<td><input type="number" id="max_files" name="max_files" value=%d></td>' % max_files print '</tr>' # Schema field. selschema = '' if 'schema' in argdict: selschema = argdict['schema'] print '<tr>' print '<td><label for="schema">Schema: </label></td>' print '<td><select id="schema" name="schema" size=0>' for schema in dbconfig.pulldowns['schema']: sel = '' if schema == selschema: sel = 'selected' print '<option value="%s" %s>%s</option>' % (schema, sel, schema) print '</select></td>' print '</tr>' # Valication check 1 - Grid print '<tr>' print '<td><label for="validation">Validation: </label></td>' print '<td>' checked = '' if 'gridtest' in argdict: checked = 'checked' print '<input type="checkbox" id="gridtest" name="gridtest" value="yes" %s>' % checked print '<label for="gridtest"> Work flow has been tested on grid</label>' print '<br>' checked = '' if 'samtest' in argdict: checked = 'checked' print '<input type="checkbox" id="samtest" name="samtest" value="yes" %s>' % checked print '<label for="samtest"> Output files have proper sam metadata</label>' print '<br>' checked = '' if 'nametest' in argdict: checked = 'checked' print '<input type="checkbox" id="nametest" name="nametest" value="yes" %s>' % checked print '<label for="nametest"> Artroot output files have unique names</label>' print '</td>' print '</tr>' # Sample instructions field. inst = '' if 'instructions' in argdict: inst = argdict['instructions'] print '<tr>' print '<td><label for="instructions">Special instructions: </label></td>' print '<td><textarea id="instructions" name="instructions" rows=2 cols=80>' print inst, print '</textarea></td>' print '</tr>' # End of main table. print '</table>' # Generate an ordered list of existing fcls. # Each element of the list will be a 5-tuple (stage, fcl, memory, time, size). empty_tuple = ('', '', 0, 0, 0) fcl_keys = [] for key in argdict: if key.startswith('fcl_'): fcl_keys.append(key) fcllist = [] for fcl_key in sorted(fcl_keys): stage_key = 'stage_%s' % fcl_key[4:] if stage_key in argdict: stage = argdict[stage_key] fcl = argdict[fcl_key] mem_key = 'memory_%d' % len(fcllist) memory = 0 if mem_key in argdict: memory = int(argdict[mem_key]) time_key = 'time_%d' % len(fcllist) time_event = 0 if time_key in argdict: time_event = int(argdict[time_key]) size_key = 'size_%d' % len(fcllist) size_event = 0 if size_key in argdict: size_event = float(argdict[size_key]) fcl_tuple = (stage, fcl, memory, time_event, size_event) # Check for insert fcl. insert_key = 'insert_%d' % len(fcllist) if insert_key in argdict: fcllist.append(empty_tuple) # Check for clone fcl. clone_key = 'clone_%d' % len(fcllist) if clone_key in argdict: fcllist.append(fcl_tuple) # Check for delete fcl. delete_key = 'delete_%d' % len(fcllist) if delete_key in argdict: # Only process this delete action once. del argdict[delete_key] continue # Check move up/down. if len(fcllist) > 0: up_key = 'up_%d' % len(fcllist) down_key = 'down_%d' % (len(fcllist) - 1) if up_key in argdict or down_key in argdict: # Insert this (stage, key) in the next to last position. fcllist.insert(len(fcllist) - 1, fcl_tuple) continue # Add this (stage, fcl). fcllist.append(fcl_tuple) # If the number of fcl files is zero, or the last stage is not blank, # add a new blank stage at the end. if len(fcllist) == 0 or fcllist[-1][0] != '': fcllist.append(empty_tuple) # Generate FCL table. print '<h3>FCL Files</h3>' print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<th>Stage</th>' print '<th>FCL File</th>' print '<th> Memory (MB) </th>' print '<th> Time/ev (sec) </th>' print '<th> Size/ev (MB) </th>' print '</tr>' # Add editable fields for existing fcl files. n = 0 for fcltuple in fcllist: stage = fcltuple[0] fcl = fcltuple[1] memory = fcltuple[2] time_event = fcltuple[3] size_event = fcltuple[4] print '<tr>' print '<td><input type="text" id="stage_%d" name="stage_%d" size-20 value="%s"></td>' % ( n, n, stage) print '<td><input type="text" id="fcl_%d" name="fcl_%d" size=80 value="%s"></td>' % ( n, n, fcl) print '<td><input type="number" id="memory_%d" name="memory_%d" size=12 value=%d></td>' % ( n, n, memory) print '<td><input type="number" id="time_%d" name="time_%d" size=12 value=%d></td>' % ( n, n, time_event) print '<td><input type="number" id="size_%d" name="size_%d" size=12 step=0.01 value=%8.2f></td>' % ( n, n, size_event) # Add insert button. print '<td>' print '<div title="Insert FCL">' print '<input type="submit" id="insert_%d" name="insert_%d" value="➕">' % ( n, n) print '</div>' print '</td>' # Add clone button. print '<td>' print '<div title="Clone FCL">' print '<input type="submit" id="clone_%d" name="clone_%d" value="⎘">' % ( n, n) print '</div>' print '</td>' # Add delete button. print '<td>' print '<div title="Delete FCL">' print '<input type="submit" id="delete_%d" name="delete_%d" value="🗑">' % ( n, n) print '</div>' print '</td>' # Add Up button. print '<td>' print '<div title="Move up">' print '<input type="submit" id="up_%d" name="up_%d" value="▲">' % ( n, n) print '</div>' print '</td>' # Add Down button. print '<td>' print '<div title="Move down">' print '<input type="submit" id="down_%d" name="down_%d" value="▼">' % ( n, n) print '</div>' print '</td>' print '</tr>' n += 1 # End of FCL table. print '</table>' # Add submit and cancel buttons. print '<br>' print '<input type="submit" name="submit" value="Submit" %s>' % disabled print '<input type="submit" name="view" value="View" %s>' % disabled print '<input type="submit" name="clear" value="Clear">' print '<input type="submit" name="cancel" value="Cancel">' # End of form. print '</form>' # Done. return
def submit(qdict, argdict): # This function is currently implemented to do the following actions. # # 1. Add a project to the production database. # 2. Optionally store a text document on the web server. # 3. Optionally send an email containing a text summary. # # Whether actions 2 and 3 are taken depends on parameters "email" and "request_dir" # in dbconfig.py. # Generate a request name. # The request name is used to generate the name of the saved text file, # the subject of the email, and the project name in the database. # The request name is required to be different from any existing project name # in the database. The request name is also required to be different from any # request file in the request directory. # Generate a base project name based on project name specified in form, if specified, # or based on a time stamp otherwise. base_name = '' if argdict.has_key('name'): base_name = argdict['name'] else: base_name = 'request_%s' % datetime.datetime.now().strftime( '%Y%m%d_%H%M%S') # Generate a non-existing project name based off base name. n = 0 done = False request_name = '' cnx = dbconfig.connect(readonly=False, devel=qdict['dev']) c = cnx.cursor() while not done: if n == 0: request_name = base_name else: request_name = '%s_%d' % (base_name, n) # See if this candidate name already exists. q = 'SELECT COUNT(*) FROM projects WHERE name=%s' c.execute(q, (request_name, )) row = c.fetchone() count = row[0] if count == 0: done = True else: n += 1 # Check request directory. if done and dbconfig.request_dir != '': rfn = '%s/%s.txt' % (dbconfig.request_dir, request_name) if os.path.exists(rfn): done = False n += 1 # Generate html document header. print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<body>' # Maybe add request file. if dbconfig.request_dir != '': if not os.path.isdir(dbconfig.request_dir): os.makedirs(dbconfig.request_dir) # Make new request file. rfn = '%s/%s.txt' % (dbconfig.request_dir, request_name) f = open(rfn, 'w') f.write(gentext(argdict)) f.close() # Maybe send email. if dbconfig.email != '': p = subprocess.Popen(['sendmail', dbconfig.email], stdin=subprocess.PIPE) message = 'Subject:Sample request %s\n%s' % (request_name, gentext(argdict)) p.communicate(input=message) p.wait() # Construct query to add project. # Use values from form, or defaults. cols = databaseDict['projects'] q = 'INSERT INTO projects SET name=%s' params = [request_name] # Loop over columns. for n in range(2, len(cols)): coltup = cols[n] colname = coltup[0] coltype = coltup[2] colarray = coltup[3] value = coltup[5] # Update default values. if colname == 'username' and argdict.has_key('user'): value = argdict['user'] elif colname == 'description' and argdict.has_key('description'): value = argdict['description'] elif colname == 'experiment' and argdict.has_key('exp'): value = argdict['exp'] elif colname == 'file_type' and argdict.has_key('ftype'): value = argdict['ftype'] elif colname == 'role' and argdict.has_key('role'): value = argdict['role'] elif colname == 'campaign' and argdict.has_key('camp'): value = argdict['camp'] elif colname == 'physics_group' and argdict.has_key('wgroup'): value = argdict['wgroup'] elif colname == 'status': value = 'Requested' elif colname == 'num_events' and argdict.has_key('num_events'): value = argdict['num_events'] elif colname == 'num_jobs' and argdict.has_key('num_jobs'): value = argdict['num_jobs'] elif colname == 'max_files_per_job' and argdict.has_key('max_files'): value = argdict['max_files'] elif colname == 'release_tag' and argdict.has_key('version'): value = argdict['version'] elif colname == 'version' and argdict.has_key('version'): value = 'test_%s' % argdict['version'] elif colname == 'validate_on_worker': value = 1 # Update query to include this column if colarray: q += ',%s=%%s' % colname params.append(value) elif coltype[:3] == 'INT': q += ',%s=%%s' % colname params.append(value) elif coltype[:7] == 'VARCHAR': if value != None: q += ',%s=%%s' % colname params.append(value.replace('&', '&')) elif coltype[:6] == 'DOUBLE': q += ',%s=%%s' % colname params.append(value) # Execute query. c.execute(q, params) # Get id of inserted row. q = 'SELECT LAST_INSERT_ID()' c.execute(q) row = c.fetchone() new_project_id = row[0] # Generate a list of stage keys in argdict. stage_keys = [] for key in argdict: if key.startswith('stage_'): stage_keys.append(key) # Loop over stage keys in ascending order. stage_names = set() for stage_key in sorted(stage_keys): # Get the stage name for this key. stage_name = argdict[stage_key] # Only process this stage name if it hasn't already been seen. if stage_name not in stage_names: stage_names.add(stage_name) # Construct a query to insert a new stage row in database. stage_cols = databaseDict['stages'] q = 'INSERT INTO stages SET name=%s,project_id=%s,seqnum=%s' params = [stage_name, new_project_id, len(stage_names)] # Loop over columns. for n in range(4, len(stage_cols)): stage_coltup = stage_cols[n] stage_colname = stage_coltup[0] stage_coltype = stage_coltup[2] stage_colarray = stage_coltup[3] value = stage_coltup[5] # Update default values. mem_key = 'memory_%s' % stage_key[6:] project_name = '' if argdict.has_key('name'): project_name = argdict['name'] else: project_name = request_name if stage_colname == 'memory' and argdict.has_key(mem_key): value = argdict[mem_key] elif stage_colname == 'inputdef' and len( stage_names) == 1 and argdict.has_key('input'): value = argdict['input'] elif (stage_colname == 'outdir' or stage_colname == 'logdir') and \ argdict.has_key('user') and argdict.has_key('exp'): value = '/pnfs/%s/scratch/users/%s/output/%s/%s' % ( argdict['exp'], argdict['user'], project_name, stage_name) elif stage_colname == 'workdir' and argdict.has_key( 'user') and argdict.has_key('exp'): value = '/pnfs/%s/resilient/users/%s/work/%s/%s' % ( argdict['exp'], argdict['user'], project_name, stage_name) elif stage_colname == 'bookdir' and argdict.has_key( 'user') and argdict.has_key('exp'): value = '/%s/data/users/%s/book/%s/%s' % ( argdict['exp'], argdict['user'], project_name, stage_name) elif stage_colname == 'num_events' and argdict.has_key( 'num_events'): value = argdict['num_events'] elif stage_colname == 'num_jobs' and argdict.has_key( 'num_jobs'): value = argdict['num_jobs'] elif stage_colname == 'max_files_per_job' and argdict.has_key( 'max_files'): value = argdict['max_files'] elif stage_colname == 'schema_' and argdict.has_key('schema'): value = argdict['schema'] # Update query to include this column if stage_colarray: q += ',%s=%%s' % stage_colname params.append(value) elif stage_coltype[:3] == 'INT': q += ',%s=%%s' % stage_colname params.append(value) elif stage_coltype[:7] == 'VARCHAR': if value != None: q += ',%s=%%s' % stage_colname params.append(value.replace('&', '&')) elif stage_coltype[:6] == 'DOUBLE': q += ',%s=%%s' % stage_colname params.append(value) # Execute query. c.execute(q, params) # Get id of inserted row. q = 'SELECT LAST_INSERT_ID()' c.execute(q) row = c.fetchone() new_stage_id = row[0] # Find fcl files associated with this stage name. fcl_keys = [] for key in argdict.keys(): if key.startswith('stage_') and argdict[key] == stage_name: fcl_key = 'fcl_%s' % key[6:] if argdict.has_key(fcl_key): fcl_keys.append(fcl_key) # Loop over fcl keys in ascending order. seq = 0 for fcl_key in sorted(fcl_keys): seq += 1 # Get fcl name for this key. fcl_name = argdict[fcl_key] # Construct a query to insert a new substage row in the database. substage_cols = databaseDict['substages'] q = 'INSERT INTO substages SET fclname=%s,stage_id=%s,seqnum=%s' params = [fcl_name, new_stage_id, seq] # Loop over columns. for n in range(4, len(substage_cols)): substage_coltup = substage_cols[n] substage_colname = substage_coltup[0] substage_coltype = substage_coltup[2] substage_colarray = substage_coltup[3] value = substage_coltup[5] # Update query to include this column if substage_colarray: q += ',%s=%%s' % substage_colname params.append(value) elif substage_coltype[:3] == 'INT': q += ',%s=%%s' % substage_colname params.append(value) elif substage_coltype[:7] == 'VARCHAR': if value != None: q += ',%s=%%s' % substage_colname params.append(value.replace('&', '&')) elif substage_coltype[:6] == 'DOUBLE': q += ',%s=%%s' % substage_colname params.append(value) # Execute query. c.execute(q, params) # Commit database updates. cnx.commit() # Generate message. print 'Sample request %s submitted.' % request_name print '<br><br>' # Add hidden form data with some buttons. print '<form action="%s/request.py" method="post" target="_self">' % dbconfig.rel_url # Add hidden form data. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) for key in argdict: if key != 'submit': print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(argdict[key])) # Add buttons. print '<input type="submit" name="reload" value="Back">' # Done with form. print '<form>' # Generate document trailer. print '</body>' print '</html>' # Done. return
def override_form(cnx, id, qdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed() and dbutil.restricted_access( cnx, 'overrides', id): disabled = 'disabled' # Query override from database. c = cnx.cursor() q = 'SELECT stage_id,name,override_type,value FROM overrides WHERE id=%s' c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch override id %d' % id) row = rows[0] stage_id = row[0] name = row[1] override_type = row[2] value = row[3] # Query stage name and project id. q = 'SELECT id, name, project_id FROM stages WHERE id=%s' c.execute(q, (stage_id, )) stage_rows = c.fetchall() if len(stage_rows) == 0: raise IOError('Unable to fetch stage id %d' % stage_id) stage_row = stage_rows[0] stage_name = stage_row[1] project_id = stage_row[2] project_name = dbutil.get_project_name(cnx, project_id) # Generate form. print '<h2>Project %s</h2>' % project_name print '<h2>Stage %s</h2>' % stage_name print '<h2>Override %s</h2>' % name print '<form action="%s/dbhandler.py" method="post">' % dbconfig.rel_url # Add hidden input field to store table name. print '<input type="hidden" id="table" name="table" value="overrides">' # Add hidden input field to store save url (parent of this page). print '<input type="hidden" id="saveurl" name="saveurl" value="%s/edit_stage.py?id=%d&%s">' % \ (dbconfig.base_url, stage_id, dbargs.convert_args(qdict)) # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Add form fields in a table. print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<td>' print '<label for="id">ID:</label>' print '</td>' print '<td>' print '<input type="number" id="id" name="id" value="%d" readonly>' % id print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="stage_id">Stage ID:</label>' print '</td>' print '<td>' print '<input type="number" id="stage_id" name="stage_id" value="%d" readonly>' % stage_id print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="name">Name:</label>' print '</td>' print '<td>' print '<input type="text" id="name" name="name" value="%s">' % name print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="override_type">Type:</label>' print '</td>' print '<td>' print '<select id="override_type" name="override_type" size=0>' pulldown_list = pulldowns['override_type'] for override_value in pulldown_list: sel = '' if override_value == override_type: sel = 'selected' print '<option value="%s" %s>%s</option>' % (override_value, sel, override_value) print '</select>' print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="value">Value:</label>' print '</td>' print '<td>' print '<input type="text" id="value" name="value" value="%s">' % value print '</td>' print '</tr>' # Finish table. print '</table>' # Add "Save" and "Back" buttons. print '<input type="submit" name="submit" value="Save" %s>' % disabled print '<input type="submit" name="submit" value="Update" %s>' % disabled print '<input type="submit" name="submit" value="Back">' print '</form>'
def project_form(cnx, id, qdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed() and dbutil.restricted_access( cnx, 'projects', id): disabled = 'disabled' # Construct disable option that applies only to status options. option_disabled = '' if not dbconfig.restricted_access_allowed(): option_disabled = 'disabled' # Get project name. name = dbutil.get_project_name(cnx, id) # Get experiment. experiment = dbutil.get_project_experiment(cnx, id) # Generate form. print '<h2>Project %s</h2>' % name # Add button to insert another stage. print '<h2>Stages</h2>' print '<form action="%s/add_stage.py?id=%d&%s" method="post" target="_self">' % \ (dbconfig.rel_url, id, dbargs.convert_args(qdict)) print '<input type="submit" value="Add Stage" %s>' % disabled print '</form>' print '<br>' # Query stage ids belonging to this project. c = cnx.cursor() q = 'SELECT id, name FROM stages WHERE project_id=%s ORDER BY seqnum' c.execute(q, (id, )) rows = c.fetchall() if len(rows) > 0: # Add links to edit project stages. print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<th> Stage ID </th>' print '<th> Stage Name </th>' print '</tr>' for row in rows: print '<tr>' stage_id = row[0] stage_name = row[1] print '<td align="center">%d</td>' % stage_id print '<td> <a target="_self" href="%s/edit_stage.py?id=%d&%s">%s</a> </td>' % \ (dbconfig.base_url, stage_id, dbargs.convert_args(qdict), stage_name) # Add Edit button/column print '<td>' print '<form target="_self" action="%s/edit_stage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, stage_id, dbargs.convert_args(qdict)) print '<div title="Edit stage">' print '<input type="submit" value="✎">' print '</div>' print '</form>' print '</td>' # Add Clone button/column print '<td>' print '<form target="_self" action="%s/clone_stage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, stage_id, dbargs.convert_args(qdict)) print '<div title="Clone stage">' print '<input type="submit" value="⎘" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Delete button/column print '<td>' print '<form action="%s/delete_stage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, stage_id, dbargs.convert_args(qdict)) print '<div title="Delete stage">' print '<input type="submit" value="🗑" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Up button/column print '<td>' print '<form action="%s/up_stage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, stage_id, dbargs.convert_args(qdict)) print '<div title="Move up">' print '<input type="submit" value="▲" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Down button/column print '<td>' print '<form action="%s/down_stage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, stage_id, dbargs.convert_args(qdict)) print '<div title="Move down">' print '<input type="submit" value="▼" %s>' % disabled print '</div>' print '</form>' print '</td>' # Finish row. print '</tr>' # Finish table. print '</table>' print '<h2>Project Data</h2>' # Query full project from database. q = 'SELECT %s FROM projects WHERE id=%%s' % dbutil.columns('projects') c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch project id %d' % id) row = rows[0] print '<form action="%s/dbhandler.py" method="post">' % dbconfig.rel_url # Add hidden input field to store table name. print '<input type="hidden" id="table" name="table" value="projects">' # Add hidden input field to store save url (parent of this page). print '<input type="hidden" id="saveurl" name="saveurl" value="%s/query_projects.py?%s">' % \ (dbconfig.base_url, dbargs.convert_args(qdict)) # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Loop over fields of this project. # Put fields in a table. print '<table border=1 style="border-collapse:collapse">' cols = databaseDict['projects'] for n in range(len(cols)): coltup = cols[n] colname = coltup[0] coltype = coltup[2] colarray = coltup[3] coldesc = coltup[4] if colname != '': # Set readonly attribute readonly = '' if colname == 'id': readonly = 'readonly' elif disabled != '': readonly = 'readonly' print '<tr>' print '<td>' print '<label for="%s">%s: </label>' % (colname, coldesc) print '</td>' print '<td>' if colarray == 0: # Scalar column. if coltype[0:3] == 'INT': print '<input type="number" id="%s" name="%s" size=10 value="%d" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:6] == 'DOUBLE': print '<input type="text" id="%s" name="%s" size=10 value="%8.6f" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:7] == 'VARCHAR': if colname in pulldowns: print '<select id="%s" name="%s" size=0 %s>' % ( colname, colname, disabled) pulldown_list = pulldowns[colname] if type(pulldown_list) == type({}): if experiment in pulldown_list: pulldown_list = pulldowns[colname][experiment] else: pulldown_list = [''] for value in pulldown_list: sel = '' if value == row[n]: sel = 'selected' if value == '' or value == 'Requested': print '<option value="%s" %s>%s</option>' % ( value, sel, value) else: print '<option value="%s" %s %s>%s</option>' % ( value, sel, option_disabled, value) print '</select>' else: print '<input type="text" id="%s" name="%s" size=100 value="%s" %s>' % \ (colname, colname, row[n], readonly) else: # Array columns. # Display using multiline <textarea>. strs = dbutil.get_strings(cnx, row[n]) print '<textarea id="%s" name="%s" rows=%d cols=80 %s>' % \ (colname, colname, max(len(strs),1), readonly) print '\n'.join(strs) print '</textarea>' print '</td>' print '</tr>' # Finish table. print '</table>' # Add "Save" and "Back" buttons. print '<input type="submit" name="submit" value="Save" %s>' % disabled print '<input type="submit" name="submit" value="Update" %s>' % disabled print '<input type="submit" name="submit" value="Back">' print '</form>'
def substage_form(cnx, id, qdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed() and dbutil.restricted_access( cnx, 'substages', id): disabled = 'disabled' # Query substage from database. c = cnx.cursor() q = 'SELECT %s FROM substages WHERE id=%%s' % dbutil.columns('substages') c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch substage id %d' % id) row = rows[0] fclname = row[1] stage_id = row[2] # Query stage name and project id. q = 'SELECT id, name, project_id FROM stages WHERE id=%s' c.execute(q, (stage_id, )) stage_rows = c.fetchall() if len(stage_rows) == 0: raise IOError('Unable to fetch stage id %d' % stage_id) stage_row = stage_rows[0] stage_name = stage_row[1] project_id = stage_row[2] project_name = dbutil.get_project_name(cnx, project_id) # Generate form. print '<h2>Project %s</h2>' % project_name print '<h2>Stage %s</h2>' % stage_name print '<h2>FCL %s</h2>' % fclname print '<form action="%s/dbhandler.py" method="post">' % dbconfig.rel_url # Add hidden input field to store table name. print '<input type="hidden" id="table" name="table" value="substages">' # Add hidden input field to store save url (parent of this page). print '<input type="hidden" id="saveurl" name="saveurl" value="%s/edit_stage.py?id=%d&%s">' % \ (dbconfig.base_url, stage_id, dbargs.convert_args(qdict)) # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Loop over fields of this stage. # Put fields in a table. print '<table border=1 style="border-collapse:collapse">' cols = databaseDict['substages'] for n in range(len(cols)): coltup = cols[n] colname = coltup[0] coltype = coltup[2] colarray = coltup[3] coldesc = coltup[4] if colname != '': # Set readonly attribute readonly = '' if colname == 'id' or colname == 'stage_id': readonly = 'readonly' elif disabled != '': readonly = 'readonly' print '<tr>' print '<td>' print '<label for="%s">%s: </label>' % (colname, coldesc) print '</td>' print '<td>' if colarray == 0: # Scalar column. if coltype[0:3] == 'INT': print '<input type="number" id="%s" name="%s" size=10 value="%d" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:6] == 'DOUBLE': print '<input type="text" id="%s" name="%s" size=100 value="%8.6f" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:7] == 'VARCHAR': print '<input type="text" id="%s" name="%s" size=100 value="%s" %s>' % \ (colname, colname, row[n], readonly) else: # Array columns. # Display using multiline <textarea>. strs = dbutil.get_strings(cnx, row[n]) print '<textarea id="%s" name="%s" rows=%d cols=80 %s>' % \ (colname, colname, max(len(strs), 1), readonly) print '\n'.join(strs) print '</textarea>' print '</td>' print '</tr>' # Finish table. print '</table>' # Add "Save" and "Back" buttons. print '<input type="submit" name="submit" value="Save" %s>' % disabled print '<input type="submit" name="submit" value="Update" %s>' % disabled print '<input type="submit" name="submit" value="Back">' print '</form>'
def group_form(cnx, id, qdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed(): disabled = 'disabled' # Get group name. name = dbutil.get_group_name(cnx, id) # Generate form. print '<h2>Group %s</h2>' % name # Query full group from database. c = cnx.cursor() q = 'SELECT %s FROM groups WHERE id=%%s' % dbutil.columns('groups') c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch group id %d' % id) row = rows[0] print '<form action="%s/dbhandler.py" method="post">' % dbconfig.rel_url # Add hidden input field to store table name. print '<input type="hidden" id="table" name="table" value="groups">' # Add hidden input field to store save url (parent of this page). print '<input type="hidden" id="saveurl" name="saveurl" value="%s/query_groups.py?%s">' % \ (dbconfig.base_url, dbargs.convert_args(qdict)) # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Loop over fields of this group. # Put fields in a table. print '<table border=1 style="border-collapse:collapse">' cols = databaseDict['groups'] for n in range(len(cols)): coltup = cols[n] colname = coltup[0] coltype = coltup[2] colarray = coltup[3] coldesc = coltup[4] if colname != '': # Set readonly attribute readonly = '' if colname == 'id': readonly = 'readonly' elif disabled != '': readonly = 'readonly' print '<tr>' print '<td>' print '<label for="%s">%s: </label>' % (colname, coldesc) print '</td>' print '<td>' if colarray == 0: # Scalar column. if coltype[0:3] == 'INT': print '<input type="number" id="%s" name="%s" size=10 value="%d" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:6] == 'DOUBLE': print '<input type="text" id="%s" name="%s" size=10 value="%8.6f" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:7] == 'VARCHAR': if colname in pulldowns: print '<select id="%s" name="%s" size=0 %s>' % ( colname, colname, disabled) for value in pulldowns[colname]: sel = '' if value == row[n]: sel = 'selected' if value == '' or value == 'Requested': print '<option value="%s" %s>%s</option>' % ( value, sel, value) else: print '<option value="%s" %s %s>%s</option>' % ( value, sel, option_disabled, value) print '</select>' else: print '<input type="text" id="%s" name="%s" size=100 value="%s" %s>' % \ (colname, colname, row[n], readonly) else: # Array columns. # Display using multiline <textarea>. strs = dbutil.get_strings(cnx, row[n]) print '<textarea id="%s" name="%s" rows=%d cols=80 %s>' % \ (colname, colname, max(len(strs),1), readonly) print '\n'.join(strs) print '</textarea>' print '</td>' print '</tr>' # Finish table. print '</table>' # Projects section. print '<h3>Projects</h3>' # Query all projects. project_ids = [] q = 'SELECT id,name FROM projects ORDER BY name' c.execute(q, ()) rows = c.fetchall() for row in rows: project_id = row[0] project_ids.append(project_id) # Query all projects in this group. project_group_ids = set() q = 'SELECT project_id FROM group_project WHERE group_id=%s' c.execute(q, (id, )) rows = c.fetchall() for row in rows: project_id = row[0] project_group_ids.add(project_id) # Projects table. print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<th>Group Projects</th>' print '<th>Available Projects</th>' print '</tr>' # Generate project lists. print '<td>' # Generate selection list for projects in group. # Loop over project ids in name order. print '<select id="ingroup" name="remove" size=20 multiple>' for project_id in project_ids: if project_id in project_group_ids: project_name = dbutil.get_project_name(cnx, project_id) print '<option value="%d">%s</option>' % (project_id, project_name) print '</select>' print '</td>' print '<td>' # Generate selection list for projects not in group. # Loop over project ids in name order. print '<select id="available" name="add" size=20 multiple>' for project_id in project_ids: if not project_id in project_group_ids: project_name = dbutil.get_project_name(cnx, project_id) print '<option value="%d">%s</option>' % (project_id, project_name) print '</select>' print '</td>' # Finish datasets table. print '</table>' # Add "Save" and "Back" buttons. print '<input type="submit" name="submit" value="Save" %s>' % disabled print '<input type="submit" name="submit" value="Update" %s>' % disabled print '<input type="submit" name="submit" value="Back">' print '</form>'
def main(project_id, dataset_name, dataset_type, qdict): # Open database connection. cnx = dbconfig.connect(readonly=False, devel=qdict['dev']) c = cnx.cursor() if dataset_name == '': # If dataset name is empty, generate a dialog to query the dataset name. print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Add Dataset</title>' print '</head>' print '<body>' # Generate a form with file dialog and two buttons "Import" and "Cancel." print '<h2>Add %s dataset</h2>' % dataset_type print '<form action="%s/add_dataset.py" method="post">' % dbconfig.rel_url for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) print '<input type="hidden" name="id" value=%d>' % project_id print '<input type="hidden" name="type" value=\'%s\'>' % dataset_type print '<label for="dataset_name">Dataset Name: </label>' print '<input type="text" id="dataset_name" name="name">' print '<br>' print '<input type="submit" value="Add">' print '<input type="submit" value="Cancel" formaction="%s/edit_datasets.py">' % dbconfig.rel_url print '</form>' print '</body>' print '</html>' else: # Maybe insert dataset. dataset_id = dbutil.add_dataset(cnx, project_id, dataset_type, dataset_name) if dataset_id == 0: # This dataset name is already used. # Generate informative page. url = '%s/edit_datasets.py?id=%d&%s' % \ (dbconfig.base_url, project_id, dbargs.convert_args(qdict)) print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Add Dataset</title>' print '</head>' print '<body>' print 'Dataset with same name is already in database.' print '<br><br>' print '<a href=%s>Return to dataset list</a>.' % url print '</body>' print '</html>' return else: # Insert succeeded. # Redirect to dataset list. url = '%s/edit_datasets.py?id=%d&%s' % \ (dbconfig.base_url, project_id, dbargs.convert_args(qdict)) print 'Content-type: text/html' print 'Status: 303 See Other' print 'Location: %s' % url print print '<!DOCTYPE html>' print '<html>' print '<body>' print 'Dataset addition successful.' print '<br><br>' print 'If page does not automatically reload click this <a href=%s>link</a>' % url print '</body>' print '</html>' # Done. return
def stage_form(cnx, id, qdict): # Construct global disabled option for restricted controls. disabled = '' if not dbconfig.restricted_access_allowed() and dbutil.restricted_access( cnx, 'stages', id): disabled = 'disabled' # Query project name and id from database. c = cnx.cursor() q = 'SELECT id, name, project_id FROM stages WHERE id=%s' c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch stage id %d' % id) row = rows[0] name = row[1] project_id = row[2] project_name = dbutil.get_project_name(cnx, project_id) # Generate form. print '<h2>Project %s</h2>' % project_name print '<h2>Stage %s</h2>' % name # Substages section. print '<h2>Substages</h2>' # Add a button to add a new substage. print '<form action="%s/add_substage.py?id=%d&%s" method="post" target="_self">' % \ (dbconfig.rel_url, id, dbargs.convert_args(qdict)) print '<input type="submit" value="Add Substage" %s>' % disabled print '</form>' print '<br>' # Query substage ids belonging to this stage. q = 'SELECT id, fclname FROM substages WHERE stage_id=%s ORDER BY seqnum' c.execute(q, (id, )) rows = c.fetchall() if len(rows) > 0: # Add links to edit project stages. print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<th> Substage ID </th>' print '<th> FCL </th>' print '</tr>' for row in rows: print '<tr>' substage_id = row[0] fclname = row[1] print '<td align="center">%d</td>' % substage_id print '<td> <a target="_self" href="%s/edit_substage.py?id=%d&%s">%s</a> </td>' % \ (dbconfig.base_url, substage_id, dbargs.convert_args(qdict), fclname) # Add Edit button/column print '<td>' print '<form target="_self" action="%s/edit_substage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, substage_id, dbargs.convert_args(qdict)) print '<div title="Edit substage">' print '<input type="submit" value="✎">' print '</div>' print '</form>' print '</td>' # Add Clone button/column print '<td>' print '<form target="_self" action="%s/clone_substage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, substage_id, dbargs.convert_args(qdict)) print '<div title="Clone substage">' print '<input type="submit" value="⎘" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Delete button/column print '<td>' print '<form action="%s/delete_substage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, substage_id, dbargs.convert_args(qdict)) print '<div title="Delete substage">' print '<input type="submit" value="🗑" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Up button/column print '<td>' print '<form action="%s/up_substage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, substage_id, dbargs.convert_args(qdict)) print '<div title="Move up">' print '<input type="submit" value="▲" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Down button/column print '<td>' print '<form action="%s/down_substage.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, substage_id, dbargs.convert_args(qdict)) print '<div title="Move down">' print '<input type="submit" value="▼" %s>' % disabled print '</div>' print '</form>' print '</td>' # Finish row. print '</tr>' # Finish table. print '</table>' # Overrides section. print '<h2>Overrides</h2>' # Add a button to add a new override. print '<form action="%s/add_override.py?id=%d&%s" method="post" target="_self">' % \ (dbconfig.rel_url, id, dbargs.convert_args(qdict)) print '<table>' print '<tr>' print '<td>' print '<label for="name">Name:</label>' print '</td>' print '<td>' print '<input type="text" id="name" name="name" value="">' print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="override_type">Type:</label>' print '</td>' print '<td>' print '<select id="override_type" name="override_type" size=0>' pulldown_list = pulldowns['override_type'] sel = 'selected' for value in pulldown_list: print '<option value="%s" %s>%s</option>' % (value, sel, value) sel = '' print '</select>' print '</td>' print '</tr>' print '<tr>' print '<td>' print '<label for="value">Value:</label>' print '</td>' print '<td>' print '<input type="text" id="value" name="value" value="">' print '</td>' print '</tr>' print '</table>' print '<input type="submit" value="Add Override" %s>' % disabled print '</form>' print '<br>' # Query override ids belonging to this stage. q = 'SELECT id, name, override_type, value FROM overrides WHERE stage_id=%s ORDER BY override_type' c.execute(q, (id, )) rows = c.fetchall() if len(rows) > 0: # Add links to edit project stages. print '<table border=1 style="border-collapse:collapse">' print '<tr>' print '<th> ID </th>' print '<th> Name </th>' print '<th> Type </th>' print '<th> Value </th>' print '</tr>' for row in rows: print '<tr>' override_id = row[0] name = row[1] override_type = row[2] value = row[3] print '<td align="center">%d</td>' % override_id print '<td align="left"> %s </td>' % name print '<td align="left"> %s </td>' % override_type print '<td align="value" > %s </td>' % value # Add Edit button/column print '<td>' print '<form target="_self" action="%s/edit_override.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, override_id, dbargs.convert_args(qdict)) print '<div title="Edit override">' print '<input type="submit" value="✎">' print '</div>' print '</form>' print '</td>' # Add Clone button/column print '<td>' print '<form target="_self" action="%s/clone_override.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, override_id, dbargs.convert_args(qdict)) print '<div title="Clone override">' print '<input type="submit" value="⎘" %s>' % disabled print '</div>' print '</form>' print '</td>' # Add Delete button/column print '<td>' print '<form action="%s/delete_override.py?id=%d&%s" method="post">' % \ (dbconfig.rel_url, override_id, dbargs.convert_args(qdict)) print '<div title="Delete override">' print '<input type="submit" value="🗑" %s>' % disabled print '</div>' print '</form>' print '</td>' # Finish row. print '</tr>' # Finish table. print '</table>' print '<h2>Stage Data</h2>' # Query full stage from database. q = 'SELECT %s FROM stages WHERE id=%%s' % dbutil.columns('stages') c.execute(q, (id, )) rows = c.fetchall() if len(rows) == 0: raise IOError('Unable to fetch stage id %d' % id) row = rows[0] print '<form action="%s/dbhandler.py" method="post">' % dbconfig.rel_url # Add hidden input field to store table name. print '<input type="hidden" id="table" name="table" value="stages">' # Add hidden input field to store save url (parent of this page). print '<input type="hidden" id="saveurl" name="saveurl" value="%s/edit_project.py?id=%d&%s">' % \ (dbconfig.base_url, project_id, dbargs.convert_args(qdict)) # Add hidden qdict input fields. for key in qdict: print '<input type="hidden" name="%s" value="%s">' % ( dbutil.convert_str(key), dbutil.convert_str(qdict[key])) # Loop over fields of this stage. # Put fields in a table. print '<table border=1 style="border-collapse:collapse">' cols = databaseDict['stages'] for n in range(len(cols)): coltup = cols[n] colname = coltup[0] coltype = coltup[2] colarray = coltup[3] coldesc = coltup[4] if colname != '': # Set readonly attribute readonly = '' if colname == 'id' or colname == 'project_id': readonly = 'readonly' elif disabled != '': readonly = 'readonly' print '<tr>' print '<td>' print '<label for="%s">%s: </label>' % (colname, coldesc) print '</td>' print '<td>' if colarray == 0: # Scalar column. if coltype[0:3] == 'INT': print '<input type="number" id="%s" name="%s" size=10 value="%d" %s>' % \ (colname, colname, row[n], readonly) elif coltype[0:6] == 'DOUBLE': value = row[n] if value == None: value = 0. print '<input type="text" id="%s" name="%s" size=100 value="%8.6f" %s>' % \ (colname, colname, value, readonly) elif coltype[0:7] == 'VARCHAR': if colname in pulldowns: print '<select id="%s" name="%s" size=0 %s>' % ( colname, colname, disabled) pulldown_list = pulldowns[colname] if type(pulldown_list) == type({}): if experiment in pulldown_list: pulldown_list = pulldowns[colname][experiment] else: pulldown_list = [''] for value in pulldown_list: sel = '' if value == row[n]: sel = 'selected' print '<option value="%s" %s>%s</option>' % ( value, sel, value) print '</select>' else: print '<input type="text" id="%s" name="%s" size=100 value="%s" %s>' % \ (colname, colname, row[n], readonly) # Add datasets. #if (colname == 'defname' or colname == 'ana_defname') and row[n] != '': # dbutil.add_dataset(cnx, project_id, 'output', row[n]) #if colname == 'inputdef' and row[n] != '': # dbutil.add_dataset(cnx, project_id, 'input', row[n]) else: # Array columns. # Display using multiline <textarea>. strs = dbutil.get_strings(cnx, row[n]) print '<textarea id="%s" name="%s" rows=%d cols=80 %s>' % \ (colname, colname, max(len(strs), 1), readonly) print '\n'.join(strs) print '</textarea>' print '</td>' print '</tr>' # Finish table. print '</table>' # Add "Save" and "Back" buttons. print '<input type="submit" name="submit" value="Save" %s>' % disabled print '<input type="submit" name="submit" value="Update" %s>' % disabled print '<input type="submit" name="submit" value="Back">' print '</form>'
def main(xmldata, qdict): # Open database connection. cnx = dbconfig.connect(readonly = False, devel = qdict['dev']) if xmldata == '': # If xml data is empty, generate a dialog to browse for local xml name. print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Import Project</title>' print '</head>' print '<body>' # Generate a form with file dialog and two buttons "Import" and "Cancel." print '<form action="%s/import_project.py" method="post" enctype="multipart/form-data">' % dbconfig.rel_url for key in qdict: print '<input type="hidden" name="%s" value="%s">' % (dbutil.convert_str(key), dbutil.convert_str(qdict[key])) print '<label for="xmldata">Choose input xml file: </label>' print '<input type="file" id="xmldata" name="data" accept=".xml">' print '<br>' print '<input type="submit" value="Import">' print '<input type="submit" value="Cancel" formaction="%s/query_projects.py?%s">' % \ (dbconfig.rel_url, dbargs.convert_args(qdict)) print '</body>' print '</html>' else: # Got uploaded xml data. # Check any project are not already in database. names = [] try: names = dbutil.xml_project_names(xmldata) except: names = [] if len(names) == 0: # XML error. url = '%s/query_projects.py?%s' % \ (dbconfig.base_url, dbargs.convert_args(qdict)) print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Import Project</title>' print '</head>' print '<body>' print 'Initial XML parsing error.' print '<br><br>' print '<a href=%s>Return to project list</a>.' % url print '</body>' print '</html>' return # See if names already exist in database. ok = False for name in names: id = dbutil.get_project_id(cnx, name) if id == 0: ok = True break if not ok: # All project names are already in database. # Generate informative page. url = '%s/query_projects.py?%s' % \ (dbconfig.base_url, dbargs.convert_args(qdict)) print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Import Project</title>' print '</head>' print '<body>' print 'Project with same name is already in database.' print '<br><br>' print '<a href=%s>Return to project list</a>.' % url print '</body>' print '</html>' return # Insert project in database. ids = [] try: ids = dbutil.import_project(cnx, xmldata) except: #print 'Content-type: text/html' #print #ids = dbutil.import_project(cnx, xmldata) ids = [] if len(ids) > 0: # Import successful. # Redirect to project editor. project_id = ids[0] url = '%s/edit_project.py?id=%d&%s' % \ (dbconfig.base_url, project_id, dbargs.convert_args(qdict)) print 'Content-type: text/html' print 'Status: 303 See Other' print 'Location: %s' % url print print '<!DOCTYPE html>' print '<html>' print '<body>' print 'Import project successful.' print '<br><br>' print 'If page does not automatically reload click this <a href=%s>link</a>' % url print '</body>' print '</html>' else: # Import failed. url = '%s/query_projects.py?%s' % \ (dbconfig.base_url, dbargs.convert_args(qdict)) print 'Content-type: text/html' print print '<!DOCTYPE html>' print '<html>' print '<head>' print '<title>Import Project</title>' print '</head>' print '<body>' print 'XML parsing error.' print '<br><br>' print '<a href=%s>Return to project list</a>.' % url print '</body>' print '</html>' # Done. return