def _do_get_provider_count_and_objs(self, name=None, **kw): userid = request.identity['repoze.who.userid'] lcompound = DBSession.query(LCompound) dsc = True order = 'id' if kw: for k, v in kw.iteritems(): if str(k) == 'desc' and str(v) != '1': dsc = None elif str(k) == 'order_by': order = v # else: # scompound = scompound.filter(str(k)==str(v)) if dsc: lcompound = lcompound.order_by(desc(order)) else: lcompound = lcompound.order_by((order)) lcompound = lcompound.all() return len(lcompound), lcompound
def _do_get_provider_count_and_objs(self, name=None, **kw): userid = request.identity['repoze.who.userid'] scompound = () dsc = True order = 'id' if kw: try: smiles = kw['smi'] method = kw['method'] except Exception: smiles = None method = None pass try: ogranicz_tekst = kw['ogranicz_tekst'] except Exception: ogranicz_tekst = None pass if smiles: if checksmi(smiles): from razi.functions import functions from razi.expression import TxtMoleculeElement if method == 'similarity': query_bfp = functions.morgan_b(TxtMoleculeElement(smiles), 2) constraint = SCompound.morgan.dice_similar(query_bfp) dice_sml = SCompound.morgan.dice_similarity(query_bfp).label('dice') # scompound = DBSession.query(SCompound, dice_sml).filter(constraint).filter(SCompound.owner.contains(userid)) scompound = DBSession.query(SCompound).filter(constraint).filter(SCompound.owner.contains(userid)) elif method == 'substructure': constraint = SCompound.structure.contains(smiles) scompound = DBSession.query(SCompound).filter(constraint).filter(SCompound.owner.contains(userid)) elif method == 'identity': scompound = DBSession.query(SCompound).filter(SCompound.structure.equals(smiles)).filter(SCompound.owner.contains(userid)) # if ogranicz_tekst: # scompound = scompound.filter(SCompound.__getattribute__(SCompound, kw['ogranicz']).like(ogranicz_tekst)) else: flash('SMILES error', 'warning') scompound = () else: scompound = DBSession.query(SCompound).filter(SCompound.owner.contains(userid)) if ogranicz_tekst: if kw['ogranicz'] == 'p_id': try: p_id = int(ogranicz_tekst) scompound = scompound.filter_by(p_id = p_id ) except Exception as msg: flash('P_id should be a number: %s' % msg, 'error') else: scompound = scompound.filter(SCompound.__getattribute__(SCompound, kw['ogranicz']).like(ogranicz_tekst)) try: tagi = kw['tags'] except Exception: tagi = None pass if isinstance(tagi, basestring): tagi_id = [int(tagi)] else: tagi_id = [int(id) for id in tagi] if tagi_id: import sqlalchemy scompound = scompound.filter(SCompound.tags.any(Tags.tags_id.in_(tagi_id))) # scompound = scompound.filter(SCompound.tags.contain(tagi_id)) # scompound = scompound.join(SCompound.tags).filter_by(not_(tags_id = tagi_id[0])) if int(kw['status']) > 0: scompound = scompound.filter(SCompound.status_id == int(kw['status'])) for k, v in kw.iteritems(): if str(k) == 'desc' and str(v) != '1': dsc = None elif str(k) == 'order_by': order = v if scompound: if dsc: scompound = scompound.order_by(desc(order)) else: scompound = scompound.order_by((order)) scompound = scompound.all() # scompound = scompound.all() return len(scompound), scompound