本文整理汇总了Python中tribal.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: update
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 ) ) )
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:32,代码来源:prepress.py
示例2: upload
def upload( self, **kw ):
try:
print "*-" * 30
print type( kw["attachment"] )
print "*-" * 30
file_path = kw["attachment"].filename
( pre, ext ) = os.path.splitext( file_path )
path_prefix = os.path.join( config.download_dir, "sys" )
if not os.path.exists( path_prefix ) : os.makedirs( path_prefix )
file_name = "%s%.4d%s" % ( dt.now().strftime( "%Y%m%d%H%M%S" ), random.randint( 1, 1000 ), ext )
print file_name
print "*-" * 30
full_path = os.path.join( path_prefix, file_name )
f = open( full_path, "wb" )
f.write( kw["attachment"].file.read() )
f.close()
db_file_name = kw.get( "attachment_name", None ) or file_name
if db_file_name.find( "." ) < 0 : db_file_name = db_file_name + ext
obj = UploadObject( file_name = db_file_name, file_path = os.path.join( "sys", file_name ) )
DBSession.add( obj )
DBSession.flush()
return obj.id
except:
traceback.print_exc()
return None
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:33,代码来源:root.py
示例3: add_attachments
def add_attachments(self, attachments=[], key='attachment'):
ids = []
for att in attachments:
upObj = UploadObject(**{'_file_path':att, 'file_name': att.split('\\')[-1].split('/')[-1]})
DBSession.add(upObj)
DBSession.flush()
ids.append(upObj.id)
setattr(self, key, '|'.join(map(str, ids)))
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:8,代码来源:sysutil.py
示例4: fun
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()]
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:9,代码来源:cabelas.py
示例5: create
def create(cls, **kw):
params = cls.upload_attachments('logo', 'proof', **kw)
params = cls._resetKw(**params)
if params.has_key('logo'):
params['logo'] = '|'.join(map(str, params['logo'].split(',')))
elif params.has_key('proof'):
params['proof'] = '|'.join(map(str, params['proof'].split(',')))
obj = cls(**params)
DBSession.add(obj)
return obj
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:10,代码来源:cabelas.py
示例6: saveNew
def saveNew(self, **kw):
params = {"issuedBy":request.identity["user"], "lastModifyBy":request.identity["user"], "lastModifyTime":dt.now()}
for f in self.formFields:
if f in kw : params[f] = kw[f]
params = self.beforeSaveNew(kw, params)
obj = self.dbObj(**params)
obj = self.afterSaveNew(obj,kw)
DBSession.add(obj)
flash("Save the new master successfully!")
redirect("/%s/index" % self.url)
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:10,代码来源:basicMaster.py
示例7: _init_local_from_erp
def _init_local_from_erp():
#insert newset so dtl and hdr
newest_date = MglobalSchedulerErp.get_last_date()
qi_start_date = newest_date.qi_date.strftime('%Y-%m-%d 00:00:00') if newest_date else '2013-01-24 00:00:00'
qi_end_date = dt.now().strftime('%Y-%m-%d 00:00:00')
so_list = MglobalErpSO.find_from_erp_by_date(qi_start_date, qi_end_date)
print 'add new so list size: %s' % len(so_list)
for record in so_list:
sod = MglobalErpSOD.merge(**{
'so_no':unicode(record[0]) if record[0] else None,
'cust_po_no':unicode(record[1]) if record[1] else None,
'customer_code':unicode(record[2]) if record[2] else None,
'customer_name':unicode(record[3]) if record[3] else None,
'line_no':unicode(record[4]) if record[4] else None,
'item_code':unicode(record[5]) if record[5] else None,
'order_qty':int(record[6]) if record[6] else None,
'create_date':record[7]
})
DBSession.add(MglobalSchedulerErp(**{'ci_date': dt.now(), 'qi_date': dt.now()}))
client_id_list = MglobalMasterItem.find_client_id_list()
mp_no_list = MglobalCustPo.find_cust_po_no(client_id_list)
MglobalErpSO.update_in_mp_order(mp_no_list)
#synchronize the uncomplete so hdr
so_undone_list = MglobalErpSO.find_undone_mp_so()
#so_undone_list = MglobalErpSO.find_undone_so()
print 'undone so size: %s' % len(so_undone_list)
so_undone_no_list = []
so_undone_map = {}
for i in so_undone_list:
so_undone_no_list.append(i.so_no)
so_undone_map[i.so_no] = i
soh_so_list = MglobalErpSO.find_so_from_erp_by_so(so_undone_no_list)
print 'search so size: %s' % len(soh_so_list)
for i in soh_so_list:
if so_undone_map[i[0]].so_qty != i[1]:
soh = so_undone_map[i[0]]
soh.has_update_so = True
soh.so_qty = i[1]
soh_si_list = MglobalErpSO.find_si_from_erp_by_so(so_undone_no_list)
print 'search si size: %s' % len(soh_si_list)
for i in soh_si_list:
if so_undone_map[i[0]].so_invoice_qty != i[1]:
soh = so_undone_map[i[0]]
soh.has_update_si = True
soh.so_invoice_qty = i[1]
soh.cp_so_si = so_undone_map[i[0]].so_invoice_qty >= so_undone_map[i[0]].so_qty
soh_dn_list = MglobalErpSO.find_dn_from_erp_by_so(so_undone_no_list)
print 'search dn size: %s' % len(soh_dn_list)
for i in soh_dn_list:
if so_undone_map[i[0]].so_dn_qty != i[1]:
soh = so_undone_map[i[0]]
soh.has_update_dn = True
soh.so_dn_qty = i[1]
soh.cp_so_dn = so_undone_map[i[0]].so_dn_qty >= so_undone_map[i[0]].so_qty
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:55,代码来源:mglobalpack.py
示例8: find_by_ids
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()
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:12,代码来源:sysutil.py
示例9: copyAttachments
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
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:12,代码来源:prepress.py
示例10: get_mglobal_upload_data
def get_mglobal_upload_data():
results = []
_init_local_from_erp()
_process_local_so()
_proess_blank_awb()
#prepare the upload data to MglobalPack for cron
upload_list = MglobalErpDND.find_updated_dn()
upload_map = {}
for dnd in upload_list:
so_hdr = dnd.local_so
so_dtls = so_hdr.local_sods
dn_client = dnd.local_client
key = '%s-%s' % (so_hdr.cust_po_no, dn_client.client_id)
upload_dn = upload_map.get(key, None)
dnd_awb = dnd.get_awb()
if dnd_awb:
if not upload_dn:
upload_dn = {'MGOrderNumber': so_hdr.cust_po_no, 'MGClientNumber': dn_client.client_id, 'OptionalNote': '', 'Items': {}}
if so_hdr.has_done:
upload_dn.update({'MODE': 'C', 'InvoiceDate': dnd.dn_date.strftime('%Y-%m-%d %H:%M:%S'), 'InvoiceNumber': dnd.so_no,
'TrackingNumber': dnd_awb[1],
'TransportCompany': dnd_awb[0]})
else:
upload_dn.update({'MODE': 'P'})
upload_map[key] = upload_dn
if not upload_dn['Items'].has_key(dnd.local_item.mg_item_code):
upload_dn['Items'][dnd.local_item.mg_item_code] = {}
if not upload_dn['Items'][dnd.local_item.mg_item_code].has_key(dnd.dn_no):
upload_dn['Items'][dnd.local_item.mg_item_code][dnd.dn_no] = {
'ItemCode': dnd.local_item.mg_item_code,
'PartialDeliveryDocument': dnd.dn_no,
'PartialDeliveryDate': dnd.dn_date.strftime('%Y-%m-%d %H:%M:%S'),
'InvoicedQty': dnd.dn_qty
}
else:
item = upload_dn['Items'][dnd.local_item.mg_item_code][dnd.dn_no]
item['InvoicedQty'] += dnd.dn_qty
DBSession.add(MglobalSchedulerMg(**{'ci_date': dt.now(), 'qi_date': dt.now()}))
for k, v in upload_map.iteritems():
dn_items = []
mg_cust_po = MglobalCustPo.get_by_cust_po_no(v['MGOrderNumber'], v['MGClientNumber'])
if mg_cust_po:
for i in mg_cust_po.detail:
if v['Items'].has_key(i.item_no):
dn_items.extend(v['Items'][i.item_no].values())
v['Items'] = dn_items
results.append(v)
transaction.commit()
return results
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:50,代码来源:mglobalpack.py
示例11: get_attachments
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 []
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:7,代码来源:sysutil.py
示例12: jobs
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 []
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:7,代码来源:prepress.py
示例13: getUserTeams
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)
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:7,代码来源:sample_helper.py
示例14: find_by
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))
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:33,代码来源:cabelas.py
示例15: download
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" )
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:8,代码来源:root.py
示例16: getManagerByTeam
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 []
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:10,代码来源:sample_helper.py
示例17: getAllSampleUsers
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 []
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:10,代码来源:sample_helper.py
示例18: getChildrenForm
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
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:11,代码来源:prepress.py
示例19: getFormTypeMapping
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
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:11,代码来源:sample_helper.py
示例20: init_master_data
def init_master_data(cls):
for i in DBSession.query(cls).filter(cls.local_client_id==None).all():
sql = "SELECT DISTINCT tih.ITEM_CODE,tih.PROGRAM,tih.BRAND FROM t_item_hdr tih WHERE tih.ITEM_CODE='%s' and tih.COMPANY_CODE IN ('RPACEU','RPACPACKEU')" % i.erp_item_code
records = searchOracle(sql, {})
if records:
record = records[0]
if not i.erp_program or not i.erp_brand:
i.erp_program = record[1]
i.erp_brand = record[2]
local_client = MglobalMasterClient.get_client(record[1], record[2])
if local_client:
i.local_client_id = local_client.id
开发者ID:LamCiuLoeng,项目名称:internal,代码行数:12,代码来源:mglobalpack.py
注:本文中的tribal.model.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论