本文整理汇总了Python中biorepo.model.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类biorepo.model.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_project_owner
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def change_project_owner(self, p_id, new_owner_id, mail, key):
'''
Allow to change the owner of one given project (include its sample(s) and measurement(s))
'''
try:
p_target = DBSession.query(Projects).filter(Projects.id == p_id).first()
#just one lab by project, so the first is the good one
project_lab = p_target.labs[0]
new_owner = DBSession.query(User).filter(User.id == new_owner_id).first()
if project_lab in new_owner.labs:
list_samples = p_target.samples
for s in list_samples:
list_meas = s.measurements
for m in list_meas:
m.user_id = new_owner.id
DBSession.add(m)
DBSession.flush()
p_target.user_id = new_owner.id
DBSession.add(p_target)
DBSession.flush()
print "Update done."
else:
raise Exception("The new owner is not a member of this lab project. Impossible to continue the operation.")
except:
print_traceback()
示例2: change_bis_sample
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def change_bis_sample(self, sending_s, reception_s):
'''
Allow to move all the measurements of one sample to an other one
and delete the sending sample after the operation.
Usefull for the "_bis" samples in spreadsheet.
@param principal : sending_s (sample id sending the measurements), reception_s (sample id receptioning the measurements)
'''
try:
# samples queries
from_sample = DBSession.query(Samples).filter(Samples.id == int(sending_s)).first()
to_sample = DBSession.query(Samples).filter(Samples.id == int(reception_s)).first()
# get the measurements lists
from_att = from_sample.attributs
to_att = to_sample.attributs
# lab checking
if from_att[0].lab_id != to_att[0].lab_id:
raise Exception("Samples from different labs. Impossible to move these measurements.")
# get list of measurements objects
meas_to_move = from_sample.measurements
meas_in_place = to_sample.measurements
# move the measurements
for m in meas_to_move:
if m not in meas_in_place:
(to_sample.measurements).append(m)
DBSession.delete(from_sample)
DBSession.add(to_sample)
DBSession.flush()
print "---> Sample " + sending_s + " was deleted and its measurements are now into the sample " + reception_s
except:
print_traceback()
示例3: multi_meas_delete
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def multi_meas_delete(self, p_id, s_id, mail, key):
'''
deleted ALL the measurements for a given sample
/!\ IRREVERSIBLE /!\
'''
try:
project = DBSession.query(Projects).filter(Projects.id == p_id).first()
sample = DBSession.query(Samples).filter(Samples.id == s_id).first()
user = DBSession.query(User).filter(User._email == mail).first()
#checking
print "--- Check your inputs... ---"
if project is None:
print "Project " + str(p_id) + " not found."
if sample is None:
print "Sample " + str(s_id) + " not found."
if user is None:
print "Your mail " + mail + " is not recorded in BioRepo."
if project.id == sample.project_id and user.id == project.user_id:
print "--- Begin the purge... ---"
list_meas = sample.measurements
print "Today, " + str(len(list_meas)) + " will die..."
print "--------------------------"
for m in list_meas:
list_fus = m.fus
for f in list_fus:
#delete the file on the server only if it is not used by anyone else anymore
if len(f.measurements) == 1 and not (f.path).startswith(HTS_path_data()) and not (f.path).startswith(HTS_path_archive()):
path_fu = f.path + "/" + f.sha1
mail = user._email
mail_tmp = mail.split('@')
path_mail = "AT".join(mail_tmp)
path_symlink = f.path + "/" + path_mail + "/" + f.sha1
DBSession.delete(f)
path_symlink = f.path + "/" + path_mail + "/" + f.sha1
try:
os.remove(path_symlink)
except:
print "---- path_symlink deleted yet ----"
pass
os.remove(path_fu)
elif (f.path).startswith(HTS_path_data()) or (f.path).startswith(HTS_path_archive()):
DBSession.delete(f)
#TODO send back something to hts to notify that it's not into biorepo anymore
print str(m.name) + "(" + str(m.id) + ") ... Sorry ... PAN."
DBSession.delete(m)
DBSession.flush()
print "--- They are all died T_T ---"
else:
print "It's not your project/sample. The FBI was notified. Run."
except:
print_traceback()
print "Something went wrong...Please, don't cry."
示例4: delete
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def delete(self, *args, **kw):
user = handler.user.get_user_in_session(request)
project = DBSession.query(Projects).filter(Projects.id == args[0]).first()
admin = isAdmin(user)
if project.user_id == user.id or admin:
try:
flash("Your project " + str(project.project_name) + " has been deleted with success")
except:
flash("Your project " + (project.project_name) + " has been deleted with success")
DBSession.delete(project)
DBSession.flush()
raise redirect('/projects')
else:
flash("It is not your project -> you are not allowed to delete it", 'error')
raise redirect('/projects')
示例5: post
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def post(self, *args, **kw):
user = handler.user.get_user_in_session(request)
user_lab = session.get("current_lab", None)
if user_lab:
lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
p = Projects()
if kw['project_name'] == '':
flash("Bad Project : Your project must have a name", "error")
raise redirect("./new")
p.project_name = kw['project_name']
p.user_id = user.id
p.description = kw.get('description', None)
(p.labs).append(lab)
DBSession.add(p)
DBSession.flush()
flash("Project created !")
raise redirect('/projects')
示例6: create_ext_lab
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def create_ext_lab(self, mail, key, lab_name):
#utilisation (only for admins) :
#wget --post-data "[email protected]&key=xxxxxxxxxxx&lab_name=bbcf" http://yourdomain.com/biorepo/create_ext_lab
lab_test = DBSession.query(Labs).filter(Labs.name == lab_name).first()
if lab_test is None:
try:
lab = Labs()
lab.name = lab_name
lab.path_raw = path_raw(lab_name)
lab.path_processed = path_processed(lab_name)
lab.path_tmp = path_tmp(lab_name)
DBSession.add(lab)
DBSession.flush()
print "Exterior lab created :", lab_name
except:
print_traceback()
print "Exterior lab NOT created --> ERROR"
else:
print "This lab : ", str(lab_name), " is in the db yet. --> ERROR"
示例7: create_gone_user
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def create_gone_user(self, mail, key, lab_id, firstname, name, user_mail):
#utilisation (only for admins) :
#wget --post-data "key=xxxxxxxxxxxxxxxxxxxxx&[email protected]&lab_id=lab_id&firstname=jean-michel&name=michel&[email protected]" \
# http://yourdomain.com/biorepo/create_gone_user
try:
user = User()
user.firstname = firstname.capitalize()
user.name = name.capitalize()
lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
user.labs.append(lab)
user._email = user_mail
group = DBSession.query(Group).filter(Group.id == 1).first()
user.groups.append(group)
DBSession.add(user)
DBSession.flush()
print "Gone/Exterior user created :", user
except:
print_traceback()
print "Gone/Exterior user NOT created --> ERROR"
示例8: create
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def create(self, *args, **kw):
user = handler.user.get_user_in_session(request)
project = Projects()
name = kw.get('project_name', None)
if name is None:
return {'ERROR': "You have to give a name to your project"}
project.project_name = name
lab_id = kw['lab']
if lab_id is None:
return {'ERROR': "We need to know the user's lab"}
lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
(project.labs).append(lab)
#test if user is an admin
admin = isAdmin(user)
if admin:
project.user_id = kw.get('user_id', user.id)
else:
project.user_id = user.id
project.description = kw.get('description', None)
get_samples = kw.get('samples', None)
l = []
if get_samples is None:
project.samples = l
else:
for x in get_samples.split(','):
sam = DBSession.query(Samples).join(Projects).join(User).filter(Samples.id == x).first()
l.append(sam)
project.samples = l
#checking print
print project, " building project with wget"
DBSession.add(project)
DBSession.flush()
return {"user_id": user.id, "user_name": user.name, "project_id": project.id, "project_name": project.project_name,
"description": project.description}
示例9: delete
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def delete(self, *args, **kw):
user = handler.user.get_user_in_session(request)
sample = DBSession.query(Samples).filter(Samples.id == args[0]).first()
admin = isAdmin(user)
if sample.get_userid == user.id or admin:
try:
flash("Your sample " + str(sample.name) + " has been deleted with success")
except:
flash("Your sample " + (sample.name) + " has been deleted with success")
DBSession.delete(sample)
DBSession.flush()
raise redirect("/samples")
#TO CHECK : check if sample get already an user as owner
elif sample.get_userid == None or admin:
DBSession.delete(sample)
DBSession.flush()
flash("Your sample has been deleted")
raise redirect("/samples")
else:
flash("It is not your sample -> you are not allowed to delete it", 'error')
raise redirect('/samples')
示例10: add_lab_4_user
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def add_lab_4_user(self, mail, key, user_mail, lab2add):
'''
Allow to bypass Shibboleth. You can add here a registered lab for a registered user.
Warning : Don't use it for someone who is not from EPFL.
'''
#utilisation (only for admins) :
#wget --post-data "[email protected]&key=xxxxxxxxxxx&[email protected]&lab2add=bbcf" http://yourdomain.com/biorepo/add_lab_4_user
user = DBSession.query(User).filter(User._email == user_mail).first()
if user is None:
print "User not found."
lab = DBSession.query(Labs).filter(Labs.name == lab2add).first()
if lab is None:
print "Lab not found."
registred = False
if lab is not None and lab in user.labs:
print "This lab is already registered for this user."
registred = True
if user is not None and lab is not None and not registred:
(user.labs).append(lab)
DBSession.flush()
else:
print "Error, lab was not added to the user"
示例11: manage_fu_from_HTS
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def manage_fu_from_HTS(existing_fu, meas, filename, sha1, url_path, hts_path):
#fixing bug str "true", str "false" for meas.type
if isinstance(meas.type, basestring):
bool_type = str2bool(meas.type)
meas.type = bool_type
if existing_fu:
print "-------- EXISTING FILE FROM HTS--------"
meas.fus.append(existing_fu)
DBSession.add(meas)
DBSession.flush()
return existing_fu
###########################################################################################
else:
#new files_up building
fu = Files_up()
fu.path = hts_path
#save the filename and the extension to the database
fu.filename = filename
if '.' in filename:
extension = filename.split('.')[-1]
fu.extension = extension
else:
fu.extension = "not specified"
fu.sha1 = sha1
fu.url_path = url_path
#add to the crossing table (measurement <-> file uploaded)
meas.fus.append(fu)
#adding new measurement and new files_up to the db
DBSession.add(meas)
DBSession.add(fu)
DBSession.flush()
return fu
示例12: check_value_addition
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def check_value_addition(self, list_type_att, dict_att_values_type, dict_att_values_db, lab_id):
'''
Checking for value(s) addition
@param principal
@return an updated db
'''
for key_type in list_type_att:
for i in dict_att_values_type[key_type]:
#get the attribut and its value(s)
i_att = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.key == key_type)).first()
#warning : i_att_value is a list !
i_att_value = DBSession.query(Attributs_values).filter(and_(Attributs_values.attribut_id == i_att.id,
Attributs_values.value == i)).all()
try:
flag = False
if i not in dict_att_values_db[key_type] and i != "None":
for existant in i_att_value:
if existant.value == i and existant.deprecated == True:
existant.deprecated = False
DBSession.flush()
flag = True
if existant.value is None:
existant.deprecated = True
DBSession.flush()
if flag == False:
new_value = Attributs_values()
new_value.attribut_id = i_att.id
new_value.value = i
new_value.deprecated = False
DBSession.add(new_value)
DBSession.flush()
except Exception as e:
import sys, traceback
a, b, c = sys.exc_info()
traceback.print_exception(a, b, c)
print "--- error login.py check_value_addition() ---"
print "i --->", i
print "key_type --->", key_type
print "list_type_att --->", list_type_att
print "dict_att_values_type[key_type] -->", dict_att_values_type[key_type]
print "i_att --> ", i_att
print "i_att_value", i_att_value
示例13: auth
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def auth(self, came_from='/', **kw):
'''
Fetch user back from tequila.
Validate the key from tequila.
Log user.
'''
if not kw.has_key('key'):
raise redirect(came_from)
# take parameters
key = kw.get('key')
environ = request.environ
authentication_plugins = environ['repoze.who.plugins']
identifier = authentication_plugins['ticket']
secret = identifier.secret
cookiename = identifier.cookie_name
remote_addr = environ['REMOTE_ADDR']
# get user
principal = tequila.validate_key(key, 'tequila.epfl.ch')
if principal is None:
raise redirect('./login')
#in case of user gets several labs
try:
if session["first_passage"] == False:
#second passage
tmp_user = session["tmp_user"]
tmp_lab = session['tmp_lab']
except:
#first passage
session["first_passage"] = True
session["principal_tequila"] = principal
session.save()
tmp_user, tmp_lab = self.build_user(principal)
try:
mail = tmp_user.email
except:
flash("Sorry, you've been disconnected. You can try to relog yourself now", 'error')
raise redirect('/login/out')
# log or create him
user = DBSession.query(User).filter(User.email == tmp_user.email).first()
if user is None:
user_group = DBSession.query(Group).filter(Group.name == gl.group_users).first()
user_group.users.append(tmp_user)
DBSession.add(tmp_user)
DBSession.flush()
user = DBSession.query(User).filter(User.email == mail).first()
flash(u'Your account has been created %s' % (user.firstname + ' ' + user.name, ))
DBSession.flush()
print "######################"
print "key user :", user.key
elif user.name == gl.tmp_user_name:
user.name = tmp_user.name
user._set_date(datetime.datetime.now())
user_group = DBSession.query(Group).filter(Group.name == gl.group_users).first()
user_group.users.append(tmp_user)
flash(u'Your account has been created %s' % (user.firstname + ' ' + user.name, ))
DBSession.add(user)
DBSession.flush()
print "######################"
print "key user :", user.key
else:
flash('Welcome back')
print "######################"
print "key user :", user.key
#create his/her lab
lab = DBSession.query(Labs).filter(Labs.name == tmp_lab.name).first()
if lab is None:
tmp_lab.users.append(user)
DBSession.add(tmp_lab)
DBSession.flush()
lab = DBSession.query(Labs).filter(Labs.name == tmp_lab.name).first()
print "lab created : ", lab
else:
if lab not in user.labs:
lab.users.append(user)
DBSession.flush()
print "lab existing : ", lab
#create attributs / check existing attributs
attributs = DBSession.query(Attributs).filter(Attributs.lab_id == lab.id).all()
if len(attributs) == 0:
attributs = None
lab_id = lab.id
#parsing "unit".ini
config = ConfigParser.RawConfigParser()
config.read(path_conf_unit(lab.name))
list_sample_att = (config.get('samples_attributs:main', 'keys')).split(',')
list_sample_hiding = (config.get('samples_hiding:main', 'keys')).split(',')
if len(list_sample_hiding) == 1 and list_sample_hiding[0] == '':
list_sample_hiding = ''
list_measurement_att = (config.get('meas_attributs:main', 'keys')).split(',')
list_meas_hiding = (config.get('meas_hiding:main', 'keys')).split(',')
if len(list_meas_hiding) == 1 and list_meas_hiding[0] == '':
list_meas_hiding = ''
list_searchable = (config.get('searchable_attributs:main', 'keys')).split(',')
#.........这里部分代码省略.........
示例14: post_edit
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def post_edit(self, *args, **kw):
id_sample = kw['IDselected']
sample = DBSession.query(Samples).filter(Samples.id == id_sample).first()
try:
project_id = kw.get("project")
if project_id is None or project_id == "":
flash("Edition rejected : Your sample must be in a project", 'error')
raise redirect("./")
sample.project_id = project_id
except:
flash("Your sample must be in a project", 'error')
raise redirect("./")
if kw['name'] == '' or kw['name'] is None:
flash("Bad Sample : you have to give a name to your sample", "error")
raise redirect("./edit/" + id_sample)
sample.name = kw.get("name", None)
sample.protocole = kw.get("protocole", None)
sample.type = kw.get("type", None)
meas_ids = kw.get("measurements", None)
if meas_ids is not None:
if not isinstance(meas_ids, (list, tuple)):
meas_ids = [int(meas_ids)]
else:
#from unicode to integer for comparison
list_tmp = []
for i in meas_ids:
i = int(i)
list_tmp.append(i)
meas_ids = list_tmp
else:
meas_ids = []
list_meas = []
for m in meas_ids:
measurement = DBSession.query(Measurements).filter(Measurements.id == m).first()
list_meas.append(measurement)
sample.measurements = list_meas
#DYNAMICITY
list_static = ['project', 'name', 'type', 'protocole', 'IDselected', 'measurements']
list_attributs = []
list_a_values = sample.a_values
for a in sample.attributs:
if a.deprecated == False:
list_attributs.append(a)
for x in kw:
if x not in list_static:
for a in list_attributs:
if x == a.key:
val_kw = kw[x]
object_2_delete = None
#search if the field was edited
for v in list_a_values:
v_value = v.value
if a.widget == "checkbox" or a.widget == "hiding_checkbox":
val_kw = check_boolean(kw[x])
v_value = check_boolean(v.value)
if v.attribut_id == a.id and v_value != val_kw and a.widget != "multipleselectfield" and a.widget != "hiding_multipleselectfield":
object_2_delete = v
if a.widget == "textfield" or a.widget == "hiding_textfield" or a.widget == "textarea" or a.widget == "hiding_textarea":
if object_2_delete:
object_2_delete.value = kw[x]
elif a.widget == "checkbox" or a.widget == "hiding_checkbox":
if len(a.values) < 3:
for old_v in a.values:
if old_v.value is not None and old_v.value != '':
list_a_values.remove(old_v)
av = Attributs_values()
av.attribut_id = a.id
av.value = True
av.deprecated = False
DBSession.add(av)
list_a_values.append(av)
DBSession.flush()
elif len(a.values) == 3:
if object_2_delete:
list_a_values.remove(object_2_delete)
v = object_2_delete.value
for val in a.values:
val_to_avoid = [None, ""]
if v not in val_to_avoid:
val_to_avoid.append(v)
if val.value not in val_to_avoid:
list_a_values.append(val)
DBSession.flush()
else:
print "----- BOOLEAN ERROR -----"
print str(a.id), " attributs id"
print "boolean with more than 2 values"
raise
elif a.widget == "singleselectfield" or a.widget == "hiding_singleselectfield":
#edition : delete the connexion to the older a_value, make the connexion between the new a_value and the sample
if object_2_delete:
list_a_values.remove(object_2_delete)
list_possible = a.values
for p in list_possible:
#.........这里部分代码省略.........
示例15: post
# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import flush [as 别名]
def post(self, *args, **kw):
user_lab = session.get("current_lab", None)
lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
lab_id = lab.id
s = Samples()
list_static = ['project', 'name', 'type', 'protocole']
list_dynamic = []
#new sample object
if 'project' not in kw:
flash("You have to choose a project to attach to your new sample, retry please", "error")
raise redirect('./')
s.project_id = kw['project']
#TODO : make a correct validator for NewSample
if kw['name'] == '':
flash("Bad Sample : you have to give a name to your sample", "error")
raise redirect('./new')
s.name = kw['name']
s.type = kw.get('type', None)
s.protocole = kw.get('protocole', None)
DBSession.add(s)
DBSession.flush()
#link the new sample to the attributs object
for x in kw:
#exclude the static fields belonging to Samples()
if x not in list_static:
list_dynamic.append(x)
#get the attribut
a = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.key == x, Attributs.deprecated == False, Attributs.owner == "sample")).first()
if a is not None:
#get its value(s)
(s.attributs).append(a)
#if values of the attribute are fixed
if a.fixed_value == True and kw[x] is not None and kw[x] != '' and a.widget != "checkbox" and a.widget != "hiding_checkbox":
value = kw[x]
list_value = DBSession.query(Attributs_values).filter(Attributs_values.attribut_id == a.id).all()
for v in list_value:
#if the keyword value is in the value list, the attributs_values object is saved in the cross table
if v.value == value and v not in s.a_values:
(s.a_values).append(v)
DBSession.flush()
#if values of the attribute are free
elif a.fixed_value == False and a.widget != "checkbox" and a.widget != "hiding_checkbox":
av = Attributs_values()
av.attribut_id = a.id
av.value = kw.get(x, None)
av.deprecated = False
DBSession.add(av)
DBSession.flush()
(s.a_values).append(av)
DBSession.flush()
#special case for checkbox because of the "on" and None value of TW2 for True and False...(here it's True)
elif a.widget == "checkbox" or a.widget == "hiding_checkbox":
found = False
for v in a.values:
if check_boolean(v.value) and v.value is not None:
(s.a_values).append(v)
found = True
if not found:
av = Attributs_values()
av.attribut_id = a.id
av.value = True
av.deprecated = False
DBSession.add(av)
DBSession.flush()
(s.a_values).append(av)
DBSession.flush()
#special case for checkbox because of the "on" and None value of TW2 for True and False...(here it's False)
dynamic_booleans = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.deprecated == False, Attributs.owner == "sample", or_(Attributs.widget == "checkbox", Attributs.widget == "hiding_checkbox"))).all()
if len(dynamic_booleans) > 0:
for d in dynamic_booleans:
if d.key not in list_dynamic:
if d.widget == "checkbox" or d.widget == "hiding_checkbox":
found = False
for v in d.values:
if not check_boolean(v.value) and v.value is not None:
(s.attributs).append(d)
(s.a_values).append(v)
found = True
#to avoid IntegrityError in the db
break
if not found:
av = Attributs_values()
av.attribut_id = d.id
av.value = False
av.deprecated = False
DBSession.add(av)
DBSession.flush()
(s.attributs).append(d)
(s.a_values).append(av)
DBSession.flush()
flash("Sample created !")
raise redirect('/samples')