本文整理汇总了Python中pygdv.model.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygdv.model.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validation
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def validation(*args, **kw):
for arg in args_list:
if arg not in kw:
raise Exception('Missing args for the validation %s' % kw)
user = DBSession.query(User).filter(User.email == str(kw['mail'])).first()
if user.key != str(kw['key']):
raise Exception('User not valid %s' % kw)
project = DBSession.query(Project).filter(Project.id == int(kw['pid'])).first()
if project.key != str(kw['pkey']):
raise Exception('Project not valid %s' % kw)
job = Job()
job.user_id = user.id
job.project_id = project.id
job.status = 'PENDING'
job.ext_task_id = kw['task_id']
job.bioscript_url = handler.job.task_url(kw['task_id'])
if 'plugin_info' in kw:
info = json.loads(kw['plugin_info'])
job.name = info['title']
job.description = info['description']
else:
job.name = 'Job %s from bioscript' % kw['task_id']
job.description = 'Description available at %s' % handler.job.task_url(kw['task_id'])
DBSession.add(job)
DBSession.flush()
return {}
示例2: edit
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def edit(project, name, user_id, sequence_id=None, tracks=None, isPublic=False, circles=None):
'''
Like create but edit an existing project.
'''
project.name=name
if sequence_id is not None:
project.sequence_id = sequence_id
project.user_id = user_id
project.is_public = isPublic
DBSession.add(project)
DBSession.flush()
project.tracks = []
if tracks is not None:
for track_id in tracks :
t = DBSession.query(Track).filter(Track.id == track_id).first()
project.tracks.append(t)
if circles is not None: # adding circle with the read permission by default
project._circle_right = []
for circle in circles : _add_read_right(project, circle.id)
DBSession.add(project)
DBSession.flush()
return project
示例3: add_read_right
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def add_read_right(project, circle_id):
'''
Add the ``read`` right to the project & circle specified. Flush the database
'''
_add_read_right(project, circle_id)
DBSession.add(project)
DBSession.flush()
示例4: e
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def e(project=None, project_id=None, name=None, track_ids=None, circle_ids=None):
if project is None:
project = DBSession.query(Project).filter(Project.id == project_id).first()
if name is not None:
project.name = name
if track_ids is not None:
project.tracks = []
for tid in track_ids:
t = DBSession.query(Track).filter(Track.id == tid).first()
project.tracks.append(t)
if circle_ids is not None:
if not isinstance(circle_ids, list):
circle_ids = [circle_ids]
circle_ids = [int(i) for i in circle_ids]
to_del = []
for shared in project._circle_right:
if shared.circle.id not in circle_ids:
to_del.append(shared)
for d in to_del:
DBSession.delete(d)
project._circle_right.remove(d)
DBSession.flush()
shared_ids = [c.id for c in project.shared_circles]
read_right = DBSession.query(Right).filter(Right.id == constants.rights['read']['id']).first()
for new_id in circle_ids:
if new_id not in shared_ids:
add_right(project=project, circle_id=new_id, right=read_right)
DBSession.flush()
DBSession.add(project)
DBSession.flush()
return project
示例5: change_rights
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def change_rights(project_id, circle_id, rights=None):
'''
Modify the right associated to a project to a group.
If any right is added, automatically add read right.
@param project_id : the project id
@param circle_id : the circle id
@param rights : the right to update
'''
project = DBSession.query(Project).filter(Project.id == project_id).first()
rc_assocs = get_circle_right_assocs(circle_id, project_id)
for rc in rc_assocs:
if rc.circle.id == int(circle_id) :
project._circle_right.remove(rc)
DBSession.delete(rc)
DBSession.flush()
if rights is not None:
_add_read_right(project, circle_id)
for right_name in rights:
if right_name != constants.right_read :
right = DBSession.query(Right).filter(Right.name == right_name).first()
cr_assoc = _get_circle_right_assoc(right, circle_id, project_id)
project._circle_right.append(cr_assoc)
DBSession.add(project)
DBSession.flush()
示例6: add_read_right_to_circles_ids
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def add_read_right_to_circles_ids(project, ids):
'''
Add the ``read`` right to the project & circles specified. Flush the database
'''
for id in ids:
_add_read_right(project, id)
DBSession.add(project)
DBSession.flush()
示例7: add_tracks
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def add_tracks(project, track_ids):
'''
Add a list of track to the project specified.
'''
for track_id in track_ids:
track_ = DBSession.query(Track).filter(Track.id == track_id).first()
project.tracks.append(track_)
DBSession.add(project)
DBSession.flush()
示例8: create_tmp_user
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def create_tmp_user(mail):
user = User()
user.name = constants.tmp_user_name
user.email = mail
user.firstname = ''
user_group = DBSession.query(Group).filter(Group.id == constants.group_users_id).first()
user_group.users.append(user)
DBSession.add(user)
DBSession.flush()
return user
示例9: index
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def index(self, *args, **kw):
seq_form = form.NewSequenceForm(action=url('/sequences')).req()
species = genrep.get_species()
m = {}
sp_to_add = []
for sp in species:
assemblies = genrep.get_assemblies_not_created_from_species_id(sp.id)
if len(assemblies) > 0:
m[sp.id] = [(ass.id, ass.name) for ass in assemblies]
sp_to_add.append(sp)
sp_opts = [(sp.id, sp.species) for sp in sp_to_add]
seq_form.child.children[1].options = sp_opts
value = {'smapping' : json.dumps(m)}
seq_form.value = value
grid = datagrid.sequences_grid
if request.method == 'GET':
sequences = DBSession.query(Sequence).all()
seq_grid = [util.to_datagrid(grid, sequences, "Sequences", len(sequences)>0)]
return dict(page="sequences", widget=seq_form, grid=seq_grid)
else :
species_id = kw['species']
assembly_id = kw['assembly']
# look if the species already exist in GDV, else create it
species = DBSession.query(Species).filter(Species.id == species_id).first()
if not species:
species = handler.genrep.get_species_by_id(species_id)
current_sp = Species()
current_sp.id = species.id
current_sp.name = species.species
DBSession.add(current_sp)
DBSession.flush()
current_sp = DBSession.query(Species).filter(Species.id == species_id).first()
flash( '''Species created: %s'''%( current_sp ))
# look if the assembly not already created, else create it
if not DBSession.query(Sequence).filter(Sequence.id == assembly_id).first():
assembly = handler.genrep.get_assembly_by_id(assembly_id)
seq = Sequence()
seq.id = assembly_id
seq.name = assembly.name
seq.species_id = species_id
DBSession.add(seq)
DBSession.flush()
seq = DBSession.query(Sequence).filter(Sequence.id == assembly_id).first()
handler.sequence.add_new_sequence(seq)
flash( '''Sequence created: %s'''%( seq ))
DBSession.flush()
sequences = DBSession.query(Sequence).all()
seq_grid = [util.to_datagrid(grid, sequences, "Sequences", len(sequences)>0)]
return dict(page="sequences", widget=seq_form, grid=seq_grid)
示例10: callback
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def callback(self, *args, **kw):
print kw
job = DBSession.query(Job).filter(Job.ext_task_id == kw['task_id']).first()
project = DBSession.query(Project).filter(Project.id == int(kw['pid'])).first()
if project is None or project.key != str(kw['pkey']):
raise Exception('Project not valid')
if job.project_id != project.id:
raise Exception('Job not valid')
status = str(kw['status'])
job.status = status
if status.lower() in ['error', 'failed']:
job.traceback = kw['error']
elif status == 'SUCCESS':
results = json.loads(kw['results'])
for result in results:
bres = Bresults()
bres.job_id = job.id
bres.output_type = str(result.get('type', 'not defined'))
bres.is_file = result.get('is_file', False)
path = str(result.get('path', ''))
bres.path = path
bres.data = str(result.get('value', ''))
is_track = result.get('type', '') == 'track'
if is_track:
out = os.path.join(filemanager.temporary_directory(), os.path.split(path)[-1])
fileinfo = filemanager.FileInfo(inputtype='fsys', inpath=path, outpath=out, admin=False)
sequence = project.sequence
user = DBSession.query(User).filter(User.key == str(kw['key'])).first()
if user.email != str(kw['mail']):
raise Exception("Wrong user")
user_info = {'id': user.id, 'name': user.name, 'email': user.email}
sequence_info = {'id': sequence.id, 'name': sequence.name}
t = Track()
t.name = fileinfo.trackname
t.sequence_id = sequence.id
t.user_id = user.id
DBSession.add(t)
DBSession.flush()
async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id, project.id)
t.task_id = async.task_id
bres.track_id = t.id
bres.is_track = is_track
DBSession.add(bres)
DBSession.flush()
return {}
示例11: _get_circle_right_assoc
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def _get_circle_right_assoc(right, circle_id, project_id):
'''
Get the ``RightCircleAssociation`` corresponding
to the right and circle_id and project_id given
'''
cr_assoc = DBSession.query(RightCircleAssociation).filter(
and_(RightCircleAssociation.right_id == right.id,
RightCircleAssociation.circle_id == circle_id,
RightCircleAssociation.project_id == project_id
)).first()
if cr_assoc is None:
cr_assoc = RightCircleAssociation()
cr_assoc.circle_id = circle_id
cr_assoc.right = right
cr_assoc.project_id = project_id
DBSession.add(cr_assoc)
return cr_assoc
示例12: save
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def save(self, project_id, color, description, locations):
user = handler.user.get_user_in_session(request)
if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id):
flash('You must have %s permission to delete the project.' % constants.right_upload, 'error')
return {'save': 'failed'}
#print "save %s, color %s, desc %s loc %s" % (project_id, color, description, locations)
''' For the moment, there is only one selection per project'''
sel = DBSession.query(Selection).filter(Selection.project_id == project_id).first()
if sel is None:
sel = Selection()
sel.project_id = project_id
sel.description = description
sel.color = color
DBSession.add(sel)
DBSession.flush()
locations_ids = []
# add locations
for loc in json.loads(locations):
obj = None
if 'id' in loc:
obj = DBSession.query(Location).join(Selection.locations).filter(
and_(Selection.id == sel.id, Location.id == loc.get('id'))).first()
if obj is None:
obj = Location()
obj.chromosome = loc.get('chr')
obj.start = loc.get('start')
obj.end = loc.get('end')
obj.description = loc.get('desc', 'No description')
obj.selection = sel
DBSession.add(obj)
DBSession.flush()
locations_ids.append(obj.id)
# remove not saved ones
loc_to_remove = DBSession.query(Location).filter(not_(Location.id.in_(locations_ids))).all()
for l in loc_to_remove:
DBSession.delete(l)
DBSession.flush()
return {"saved": "ok"}
示例13: add_new_sequence
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def add_new_sequence(sequence):
'''
Method called when a new sequence is created on GDV.
It should import fast from JBrowse
'''
print 'add new sequence'
file_url = Assembly(sequence).get_sqlite_url()
print file_url
out = os.path.join(filemanager.temporary_directory(), 'Genes.sql')
fileinfo = filemanager.FileInfo(inputtype='url',
inpath=file_url, trackname='Genes', extension='sql', outpath=out, admin=True)
print fileinfo
user = DBSession.query(User).filter(User.key == constants.admin_user_key()).first()
user_info = {'id': user.id, 'name': user.name, 'email': user.email}
sequence_info = {'id': sequence.id, 'name': sequence.name}
# track
t = Track()
t.name = fileinfo.trackname
t.sequence_id = sequence.id
t.user_id = user.id
DBSession.add(t)
DBSession.flush()
# send task
async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id)
t.task_id = async.task_id
DBSession.add(t)
sequence.default_tracks.append(t)
DBSession.add(sequence)
DBSession.flush()
示例14: auth
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def auth(self, came_from='/', **kw):
'''
Fetch user back from tequila.
Validate the key from tequila.
Log user.
'''
if not 'key' in kw:
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')
tmp_user = self.build_user(principal)
mail = tmp_user.email
# 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.id == constants.group_users_id).first()
user_group.users.append(tmp_user)
DBSession.add(tmp_user)
DBSession.flush()
#transaction.commit()
user = DBSession.query(User).filter(User.email == mail).first()
flash('Your account has been created')
DBSession.flush()
self.build_circles_with_user(tmp_user, principal)
DBSession.flush()
#transaction.commit()
elif user.name == constants.tmp_user_name:
user.name = tmp_user.name
user.firstname = tmp_user.firstname
user._set_date(datetime.datetime.now())
#user_group = DBSession.query(Group).filter(Group.id == constants.group_users_id).first()
#user_group.users.append(tmp_user)
flash('Your account has been created')
DBSession.flush()
self.build_circles_with_user(tmp_user, principal, user)
DBSession.flush()
#transaction.commit()
else:
flash('Welcome back', 'notice')
self.check_circles_with_user(user, principal)
# look if an user is admin or not
admins = tg.config.get('admin.mails')
group_admins = DBSession.query(Group).filter(Group.id == constants.group_admins_id).first()
if user.email in admins:
user not in group_admins.users and group_admins.users.append(user)
else:
user in group_admins.users and group_admins.users.remove(user)
DBSession.flush()
# create the authentication ticket
user = DBSession.query(User).filter(User.email == mail).first()
userdata = "%s|%s" % (user.id, user in group_admins.users)
ticket = auth_tkt.AuthTicket(
secret, user.email, remote_addr, tokens=token,
user_data=userdata, time=None, cookie_name=cookiename,
secure=True)
val = ticket.cookie_value()
# set it in the cookies
response.set_cookie(
cookiename,
value=val,
max_age=None,
path='/',
domain=None,
secure=False,
httponly=False,
comment=None,
expires=None,
overwrite=False)
transaction.commit()
raise redirect(came_from)
示例15: prepare_view
# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import add [as 别名]
def prepare_view(project_id, *args, **kw):
from pygdv import handler
# Get the project
project = DBSession.query(Project).filter(Project.id == project_id).first()
tracks = project.success_tracks
# prepare track that are not yet initialised
for t in tracks:
handler.track.init(t)
DBSession.flush()
seq = project.sequence
default_tracks = [d for d in seq.default_tracks if d.status == constants.SUCCESS]
all_tracks = tracks + default_tracks
# Track names must be different
trackNames = []
for t in all_tracks:
while t.name in trackNames:
ind = 0
while(t.name[-(ind + 1)].isdigit()):
ind += 1
cpt = t.name[-ind:]
try:
cpt = int(cpt)
except ValueError:
cpt = 0
cpt += 1
tmp_name = t.name
if ind > 0:
tmp_name = t.name[:-ind]
t.name = tmp_name + str(cpt)
t.accessed
DBSession.add(t)
DBSession.flush()
trackNames.append(t.name)
# prepare javascript parameters
refSeqs = 'refSeqs = %s' % json.dumps(jb.ref_seqs(project.sequence_id))
trackInfo = 'trackInfo = %s' % json.dumps(jb.track_info(all_tracks, assembly_id=project.sequence_id))
parameters = 'var b = new Browser(%s)' % jb.browser_parameters(
constants.data_root(), constants.style_root(), constants.image_root(), ','.join([track.name for track in all_tracks]))
style_control = '''function getFeatureStyle(type, div){
div.style.backgroundColor='#3333D7';div.className='basic';
switch(type){
%s
}};
''' % jb.features_style(all_tracks)
selections = 'init_locations = %s' % handler.selection.selections(project_id)
# prepare _gdv_info
info = {}
prefix = tg.config.get('prefix')
if prefix:
info['prefix'] = prefix
info['proxy'] = tg.config.get('main.proxy')
info['sequence_id'] = project.sequence_id
info['admin'] = kw.get('admin', True)
info['plug_url'] = url('/plugins')
info['project_key'] = project.key
info['project_id'] = project.id
info['bioscript'] = bioscript_parameters('oplist')
if 'mode' in kw:
info['mode'] = kw.get('mode')
info = json.dumps(info)
control = 'b.showTracks();initGDV(b, %s, %s);' % (project.id, info)
# add location if it's in url
if 'loc' in kw:
control += 'b.navigateTo("%s");' % kw.get('loc')
# prepare jobs list
jobs = 'init_jobs = {}'
op = '{}'
if 'plugin.service.url' in tg.config:
try:
op = handler.job.operation_list()
except urllib2.URLError:
pass
return dict(species_name=project.species.name,
nr_assembly_id=project.sequence_id,
project_id=project.id,
is_admin=True,
ref_seqs=refSeqs,
track_info=trackInfo,
parameters=parameters,
style_control=style_control,
control=control,
selections=selections,
jobs=jobs,
page='view',
oplist=op)