本文整理匯總了Python中tribal.model.DBSession.query方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.query方法的具體用法?Python DBSession.query怎麽用?Python DBSession.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tribal.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fun
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def fun():
if active==None:
data = DBSession.query(obj).order_by(getattr(obj, order_by_field))
else:
data = DBSession.query(obj).filter(obj.active == active).order_by(getattr(obj, order_by_field))
if to:
#data = data.filter(obj.type == to).filter(obj.vendor_id == request.identity["user"].user_id)
data = data.filter(obj.type == to)
return [("", ""), ] + [(str(row.id), str(getattr(row, query_field))) for row in data.all()]
示例2: find_by_ids
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def find_by_ids(cls, ids, separator=',', order_func='id asc'):
if type(ids) == str or type(ids) == unicode:
results = []
id_list = filter(lambda x: x, ids.split(separator))
result_dict = {}
for result in DBSession.query(cls).filter(cls.id.in_(id_list)).order_by(order_func).all():
result_dict[result.id] = result
for id in ids.split(separator):
results.append(result_dict[int(id)] if id else None)
return results
elif type(ids) == list or type(ids) == tuple:
return DBSession.query(cls).filter(cls.id.in_(ids)).order_by(order_func).all()
示例3: update
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def update( self, **kw ):
old_object = self.serialize()
old_object_status = self.status
for key, dbobj in [( "project_own", Region ), ( "team", Team ), ( "customer", Customer ), ( "request_team", Team ),
( "item_category", PSItemCategory )]:
if key in kw :
val = DBSession.query( dbobj ).get( kw[key] ) if kw[key] else None
setattr( self, key, val )
for key in ["contact_person", "reference_code", "item_description", "item_code", "project_owner", "request_contact_number", "project"]:
if key in kw :
val = kw[key].strip() if kw[key] else None
setattr( self, key, val )
if "cc_to" in kw:
self.cc_to = ( kw["cc_to"] or '' ).replace( "\n", '' )
self.child_form = kw.get( "form_ids" )
# add the update log
if old_object_status != PS_DRAFT:
self.revision += 1
# if update from draft and save to status: new
if old_object_status == PS_DRAFT and not kw['is_draft']:
self.status = PS_NEW_REQUEST
new_object = self.serialize( False )
check_log = PSMainForm.compareObject( old_object, new_object )
log_str = []
for ( key, old_val, new_val ) in check_log['update']:
log_str.append( "Change [%s] from '%s' to '%s' " % ( key, old_val, new_val ) )
for ( key, new_val ) in check_log['new']:
log_str.append( "New [%s] '%s' " % ( key, new_val ) )
if log_str and old_object_status != PS_DRAFT: DBSession.add( PSDevelopmentLog( system_no = str( self ), main_form_id = self.id, sub_form_id = None, sub_form_type = None, action_type = 'UPDATE', remark = " .\n".join( log_str ) ) )
示例4: getUserTeams
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getUserTeams(user):
teams = set()
for g in user.groups:
if "SAMPLE_DEVELOPMENT" not in map(lambda p:p.permission_name,g.permissions):continue
profiles = DBSession.query(SampleGroupProfile).filter(and_(SampleGroupProfile.active==0,SampleGroupProfile.group_id==g.group_id))
for p in profiles : teams.add(p.team)
return list(teams)
示例5: jobs
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def jobs( self ):
try:
return DBSession.query( PSJob ).filter( and_( PSJob.active == 0, PSJob.sub_form_type == self.__class__.__name__,
PSJob.sub_form_id == self.id, PSJob.status == PS_JOB_COMPLETE ) ).all()
except Exception, e:
log.exception( str( e ) )
return []
示例6: get_attachments
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def get_attachments(self, key='attachment', wrapper=True):
try:
if not wrapper: return [id for id in getattr(self, key).split("|") if id]
m = lambda id: DBSession.query(UploadObject).get(id)
return map(m, [id for id in getattr(self, key).split("|") if id])
except:
return []
示例7: find_by
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def find_by(cls, **kw):
data = DBSession.query(cls).filter(cls.active == 0).order_by(desc(cls.create_time))
number = kw.get("number")
name = kw.get("product_desc")
bill_to_id = kw.get("bill_to_id")
ship_to_id = kw.get("ship_to_id")
create_data_start = kw.get("create_time_start")
create_time_end = kw.get("create_time_end")
if number:
data = data.filter(cls.number.ilike('%%%s%%' % number))
if bill_to_id:
data = data.filter(cls.bill_to_id == bill_to_id)
if ship_to_id:
data = data.filter(cls.ship_to_id == ship_to_id)
if create_data_start:
data = data.filter(cls.create_time >= dt.strptime(create_data_start + "00:00:00", "%Y-%m-%d%H:%M:%S"))
if create_time_end:
data = data.filter(cls.create_time <= dt.strptime(create_time_end + "00:00:00", "%Y-%m-%d%H:%M:%S"))
if name:
rs = []
labels = CabelasLabel.find_labels_by_name(name)
labels = [i[0] for i in labels]
da = data.all()
for a in da:
label = a.label
if label:
label_ids = label.split(",")
for b in label_ids:
if int(b) in labels:
rs.append(a)
else:
rs = data.all()
return list(set(rs))
示例8: create
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def create( cls, **kw ):
requiredFields = ["project_own", "contact_person", "team", "project", "project_own"]
is_draft = kw['is_draft']
if not is_draft:
for f in requiredFields:
if not kw.get( f, False ) :
raise Exception( 'Please Fill in the required field(s) before you submit the request!' )
hParam = {
'child_form': kw.get( "form_ids", '' ),
"contact_person" : kw.get( "contact_person", None ),
"reference_code" : kw.get( "reference_code", None ),
"item_description" : kw.get( "item_description", None ),
"item_code" : kw.get( "item_code", None ),
"request_contact_number" : kw.get( "request_contact_number", None ),
"team" : DBSession.query( Team ).get( kw["team"] ) if kw.get( "team", None ) else None,
"customer" : DBSession.query( Customer ).get( kw["customer"] ) if kw.get( "customer", False ) else None,
"item_category" : DBSession.query( PSItemCategory ).get( kw["item_category"] ) if kw.get( "item_category", False ) else None,
"project" : kw.get( "project", None ),
"project_own" : DBSession.query( Region ).get( kw["project_own"] ) if kw.get( "project_own", False ) else None,
"request_team" : DBSession.query( Team ).get( kw["request_team"] ) if kw.get( "request_team", None ) else None,
"project_owner" : kw.get( "project_owner", None ),
"rpt" : kw.get( "rpt", None ) or None,
"cc_to" : kw.get( "cc_to", None ) or None,
"status": PS_DRAFT if is_draft else PS_NEW_REQUEST,
"status_back": PS_DRAFT if is_draft else PS_NEW_REQUEST,
}
if hParam['cc_to'] : hParam['cc_to'] = hParam['cc_to'].strip().replace( "\n", '' )
hParam["request_type"] = "New"
def _getSystemNo():
s = Sequence( 'rp_main_form_seq' )
s.create( DBSession.bind, checkfirst = True ) # if the seq is existed ,don't create again
c = DBSession.execute( s )
prefix = 'OTHER'
for g in request.identity["user"].groups:
for profile in g.prepress_profiles:
if profile.region_id :
prefix = profile.region.code
break
# return "RP%s%.6d" % ( prefix, c )
return "RP%s%s" % ( prefix, c )
hParam["system_no"] = _getSystemNo()
h = PSMainForm( **hParam )
DBSession.add( h )
return h
示例9: download
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def download( self, **kw ):
try:
obj = DBSession.query( UploadObject ).get( kw["id"] )
return serveFile( obj.file_path, obj.file_name )
except:
traceback.print_exc()
flash( "No such file!" )
redirect( "/index" )
示例10: getManagerByTeam
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getManagerByTeam(tid,idOnly=True):
try:
users = []
for p in DBSession.query(SampleGroupProfile).filter(and_(SampleGroupProfile.active==0,SampleGroupProfile.team_id==tid)):
if p.manager_group_id : users.extend(p.manager_group.users)
return [u.user_id for u in users] if idOnly else users
except:
traceback.print_exc()
return []
示例11: getAllSampleUsers
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getAllSampleUsers():
try:
users = set()
p = DBSession.query(Permission).filter(Permission.permission_name=="SAMPLE_DEVELOPMENT").one()
for g in p.groups :
for u in g.users: users.add(u)
return sorted(list(users),key=lambda o:o.user_name)
except:
traceback.print_exc()
return []
示例12: getFormTypeMapping
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getFormTypeMapping(self):
if self._formTypeMapping is None:
self._formTypeMapping = {}
for m in DBSession.query(FormTypeMapping).filter(FormTypeMapping.active==0):
self._formTypeMapping[m.name] = {
"name" : m.name,
"label" : m.label,
"category" : m.category,
"report_header" : m.report_header,
}
return self._formTypeMapping
示例13: getChildrenForm
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getChildrenForm( self ):
k = lambda n: globals()[n]
m = lambda d: DBSession.query( d ).filter( and_( d.active == 0, d.main_id == self.id ) ).order_by( d.id ).all()
result = []
try:
for c in self.getChildren(): result.extend( m( k( c ) ) )
return sorted( result, cmp = lambda x, y : cmp( x.create_time, y.create_time ) )
except Exception, e:
log.exception( str( e ) )
return result
示例14: copyAttachments
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def copyAttachments( cls, ids ):
if isinstance( ids, str ) or isinstance( ids, unicode ):
ids = [ids]
objs = [DBSession.query( UploadObject ).get( int( id ) ) for id in ids if id]
attachments = []
for obj in objs:
if obj:
attachment = UploadObject( **{'file_name': obj.file_name, 'file_path': obj._file_path} )
DBSession.add( attachment )
DBSession.flush()
attachments.append( attachment.id )
return attachments
示例15: getAttachment
# 需要導入模塊: from tribal.model import DBSession [as 別名]
# 或者: from tribal.model.DBSession import query [as 別名]
def getAttachment( self, wrapper = False, attach_type = "attachment" ):
'''獲取sub_form附件
Args:
attach_type: 附件類型,attachment或complete_attachment
'''
try:
attachment = getattr( self, attach_type )
if not wrapper: return [id for id in attachment.split( "|" ) if id]
m = lambda id: DBSession.query( UploadObject ).get( id )
return map( m, [id for id in attachment.split( "|" ) if id] )
except:
return []