#!/usr/local/bin/python3.3 import cgi import cgitb import pymysql import datetime from functions import get_cookies, phead, ptail cgitb.enable() """ The following issues need to be addressed: -remove study """ cookie = get_cookies() if cookie: print(cookie) fname = cookie["fname"].value lname = cookie["lname"].value name = " ".join((fname, lname)) admin = cookie["admin"].value uid = cookie["uid"].value uname = cookie["uname"].value form = cgi.FieldStorage() newst = form.getvalue("stname") plid = form.getvalue("plname") prid2 = form.getvalue("prname") des1 = form.getvalue("description1") des2 = form.getvalue("description2") des3 = form.getvalue("description3") study_to_delete = form.getvalue("study_to_delete") prid = form.getvalue('prid') qprname = "select prname from Project where prid = '%s'" % prid data = [] #data should be in the order: user, passwd, host, db with open('./dbinfo.txt') as f: for line in f: line = line.strip('\n') data.append(line) info = [] for item in data: item = item.split(':') info.append(item) user=info[0][1] passwd=info[1][1] host=info[2][1] db=info[3][1] if newst == None: newst = "" if plid == None: plid = "" if des1 == None: des1 = "" if des2 == None: des2 = "" if des3 == None: des3 = "" def addStudy(stname, plid, prid, des1, des2, des3, uname, date): connection = pymysql.connect(host=host, user=user, db=db, passwd=passwd) cursor = connection.cursor() query1 = """INSERT INTO Study (sname, plid, description1, description2, description3, creator, date) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s") ;""" % (stname, plid, des1, des2, des3, uname, date) cursor.execute(query1) connection.commit() qgetsid = """select sid from Study where sname = "%s" """ % stname getsid = runQuery(qgetsid, user, passwd) sid = getsid[0][0] query2 = """insert into ProjectStudy (prid, sid) values ("%s", "%s")""" % (prid, sid) cursor.execute(query2) connection.commit() cursor.close() connection.close() def delStudy(plid): connection = pymysql.connect(host=host, user=user, db=db, passwd=passwd) cursor = connection.cursor() query = """delete from Study where sid = ("%s");""" %(plid) cursor.execute(query) connection.commit() cursor.close() connection.close() def runQuery(query, user, passwd): connection = pymysql.connect(host=host,db=db,user=user,passwd=passwd) cursor = connection.cursor() cursor.execute(query) res = cursor.fetchall() cursor.close() connection.close() return res if len(newst) != 0 and len(plid) != 0 and prid2 != None: addStudy(newst, plid, prid2, des1, des2, des3, uname, str(datetime.date.today())) print("Location: showstudy.py") elif study_to_delete != None: delStudy(study_to_delete) print("Content-type: text/html\n") phead(name, admin) print("""
All studies:
') q1 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, count(*) from Study s join Platform using(plid) join StudyExperiment using(sid) group by sid order by s.date desc, sname asc; """ # get sid, sname, plname, description1,2,3, creator, date, exp#. Admin = 1 q2 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, 0 from Study s join Platform using(plid) left join StudyExperiment using(sid) where eid is NULL order by date desc, sname asc; """ # admin = 1 exp = 0 elif admin == "1" and prid: prname = runQuery(qprname, user, passwd)[0][0] print('All studies in project %s:
' % prname) q1 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, count(*) from Study s join Platform using(plid) join StudyExperiment using(sid) join ProjectStudy using(sid) where prid = "%s" group by sid order by s.date desc, sname asc; """ % prid q2 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, 0 from Study s join Platform using(plid) join ProjectStudy using(sid) left join StudyExperiment using(sid) where eid is NULL and prid = "%s" order by date desc, sname asc; """ % prid elif admin == "0" and prid == None: print('All studies:
') q1 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, count(*) from Study s join Platform using(plid) join StudyExperiment using(sid) group by sid order by s.date desc, sname asc; """ #% uname q2 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, 0 from Study s join Platform using(plid) left join StudyExperiment using(sid) where eid is NULL order by date desc, sname asc; """ #% uname else: prname = runQuery(qprname, user, passwd)[0][0] print('All studies in project %s:
' % prname) q1 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, count(*) from Study s join Platform using(plid) join StudyExperiment using(sid) join ProjectStudy using(sid) where prid="%s" group by sid order by s.date desc, sname asc; """ % ( prid) #removed uname, for creator q2 = """ select sid, sname, plname, s.description1, s.description2, s.description3, s.creator, s.date, 0 from Study s join Platform using(plid) join ProjectStudy using(sid) left join StudyExperiment using(sid) where prid="%s" and eid is NULL order by s.date desc, sname asc; """ % ( prid) # removed uname, for creator res1 = runQuery(q1, user, passwd) res2 = runQuery(q2, user, passwd) if len(res1) > 0 or len(res2) > 0: print("""ID | Study | Platform | Description1 | Description2 | Description3 | Creator | Create date | # experiments | |
---|---|---|---|---|---|---|---|---|---|
""") for j in range(len(row)): if j == 0 or j == 1: print(""" | %s | """ % (str(row[0]),str(row[j]))) else: print("%s | " % str(row[j])) print("
Add a new study:
Delete a Study:
Note: This CANNOT be undone and it will remove everything within the study.