本文整理汇总了Python中sys2do.util.common._g函数的典型用法代码示例。如果您正苦于以下问题:Python _g函数的具体用法?Python _g怎么用?Python _g使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_g函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register():
fields = ["email", "password", "repassword"]
if _check_params(fields) != 0:
return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING})
email = _g("email")
password = _g("password")
repassword = _g("repassword")
if not email:
return jsonify({"result": 0, "msg": MSG_EMAIL_BLANK_ERROR})
if not password:
return jsonify({"result": 0, "msg": MSG_PASSWORD_BLANK_ERROR})
if password != repassword:
return jsonify({"result": 0, "msg": MSG_PASSWORD_NOT_MATCH})
try:
DBSession.query(User).filter(and_(User.active == 0, func.upper(User.email) == email.upper())).one()
return jsonify({"result": 0, "msg": MSG_EMAIL_EXIST})
except:
traceback.print_exc()
pass
display_name = _g("display_name") or email
try:
u = User(email=email, password=password, display_name=display_name)
DBSession.add(u)
DBSession.commit()
return jsonify({"result": 1, "msg": MSG_SAVE_SUCCESS, "id": u.id, "point": u.point})
except:
traceback.print_exc()
return jsonify({"result": 0, "msg": MSG_SERVER_ERROR})
示例2: m_events_update
def m_events_update():
id = _g("id")
if not id :
flash("No id supplied !", MESSAGE_ERROR)
return redirect(url_for("m_events_list"))
action_type = _g("action_type")
if not action_type in ["m", "c", "p"]:
flash("No such action !", MESSAGE_ERROR)
return redirect(url_for("m_events_list"))
e = DBSession.query(Events).get(id)
# e = connection.Events.one({"id" : int(id)})
if action_type == "m":
return render_template("m_events_update.html", event = e)
elif action_type == "c": #cancel
e.status = 2
DBSession.add(Message(subject = u"Cancel Booking Event", user_id = e.user_id,
content = u"%s cancel the booking request." % session['user_profile']['name']))
DBSession.commit()
return jsonify({"success" : True, "message" : "Update successfully !"})
elif action_type == "p": #confirmed
e.status = 1
DBSession.add(Message(subject = u"Confirm Booking Event", user_id = e.user_id,
content = u"%s confirm the booking request." % session['user_profile']['name']))
DBSession.commit()
return jsonify({"success" : True, "message" : "Update successfully !"})
示例3: save_new
def save_new(self):
params = {
"name" : _g('name'),
"address" : _g('address'),
"manager" : _g('manager'),
"remark" : _g('remark'),
"parent_id" : _g('parent_id'),
}
try:
obj = InventoryLocation(**params)
DBSession.add(obj)
DBSession.flush()
if params['parent_id']:
parent = DBSession.query(InventoryLocation).get(obj.parent_id)
obj.full_path = "%s%s" % (parent.full_path or '', params['name'])
obj.full_path_ids = "%s|%s" % (parent.full_path_ids, obj.id)
else:
obj.full_path = params['name']
obj.full_path_ids = obj.id
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
except:
DBSession.rollback()
_error(traceback.print_exc())
return redirect(self.default())
示例4: getDoctorList
def getDoctorList():
fields = ["lang", "locationIndex"]
if _check_params(fields) != 0:
return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING})
ds = []
lang = _g("lang")
locationIndex = _g("locationIndex")
for c in DBSession.query(Clinic).filter(and_(Clinic.active == 0, Clinic.area_id == locationIndex)):
latitude = longtitude = None
if c.coordinate:
latitude, longtitude = c.coordinate.split(",")
for d in c.doctors:
ds.append(
{
"doctorID": d.id,
"clinicID": c.id,
"name": {"zh_HK": c.name_tc, "zh_CN": c.name_sc}.get(lang, c.name),
"latitude": latitude,
"longtitude": longtitude,
"address": {"zh_HK": c.address_tc, "zh_CN": c.address_sc}.get(lang, c.address),
}
)
return jsonify({"result": 1, "data": ds})
示例5: item_detail
def item_detail(self):
if _g('SEARCH_SUBMIT'): # come from search
values = {'page' : 1}
for f in ['create_time_from', 'create_time_to', 'id'] :
values[f] = _g(f)
else: # come from paginate or return
values = session.get('inventory_item_detail_values', {})
if _g('page') : values['page'] = int(_g('page'))
elif 'page' not in values : values['page'] = 1
values['id'] = _g('id')
if not values.get('create_time_from', None) and not values.get('create_time_to', None):
values['create_time_to'] = dt.now().strftime("%Y-%m-%d")
values['create_time_from'] = (dt.now() - timedelta(days = 30)).strftime("%Y-%m-%d")
session['inventory_item_detail_values'] = values
conditions = [InventoryNoteDetail.active == 0, InventoryNoteDetail.item_id == values.get('id', None)]
result = DBSession.query(InventoryNoteDetail).filter(and_(*conditions)).order_by(InventoryNoteDetail.create_time)
def url_for_page(**params): return url_for('.view', action = "item_detail", id = values.get('id', None), page = params['page'])
records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page)
return {
"records" : records,
"values" : values,
}
示例6: permission
def permission(self):
method = _g('m', 'LIST')
if method not in ['LIST', 'NEW', 'UPDATE', 'DELETE', 'SAVE_NEW', 'SAVE_UPDATE']:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR);
return redirect(url_for('.view', action = 'index'))
if method == 'LIST':
page = _g('page') or 1
objs = DBSession.query(Permission).filter(Permission.active == 0).order_by(Permission.name).all()
def url_for_page(**params): return url_for('bpAdmin.view', action = 'permission', m = 'LIST', page = params['page'])
records = paginate.Page(objs, page, show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page)
return render_template('admin/permission_index.html', records = records)
elif method == 'NEW':
groups = Group.all()
return render_template('admin/permission_new.html', groups = groups)
elif method == 'UPDATE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
gids = map(lambda v:v.id, obj.groups)
all_groups = Group.all()
return render_template('admin/permission_update.html', v = obj.populate(), gids = gids, all_groups = all_groups)
elif method == 'DELETE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj.active = 1
obj.groups = []
DBSession.commit()
flash(MSG_DELETE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
elif method == 'SAVE_NEW':
obj = Permission.saveAsNew(request.values)
obj.groups = DBSession.query(Group).filter(Group.id.in_(_gl("gids"))).all()
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
elif method == 'SAVE_UPDATE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj.saveAsUpdate(request.values)
obj.groups = DBSession.query(Group).filter(Group.id.in_(_gl('gids'))).all()
obj.commit()
flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
示例7: save_update
def save_update(self):
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view'))
obj = DBSession.query(Customer).get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view'))
try:
fields = ['no', 'name', 'display_name', 'province_id', 'city_id',
'address', 'contact_person', 'mobile', 'phone', 'email', 'note_id', 'remark']
old_info = obj.serialize(fields) # to used for the history log
for f in fields:
setattr(obj, f, _g(f))
#handle the file upload
old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_"))
old_attachment_ids.extend(multiupload())
obj.attachment = old_attachment_ids
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
# return redirect(url_for('.view',id=obj.id))
new_info = obj.serialize(fields)
change_result = obj.compare(old_info, new_info)
obj.insert_system_logs(change_result)
except:
_error(traceback.print_exc())
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view', action = "view", id = obj.id))
示例8: save_register
def save_register():
cid = _g('customer_id' , None)
user_params = {
"name" : _g('name'),
"password" : _g('password'),
"email" : _g('email'),
"first_name" : _g('first_name'),
"last_name" : _g('last_name'),
"phone" : _g('phone'),
"mobile" : _g('mobile'),
}
if cid and cid != 'OTHER':
c = DBSession.query(Customer).get(cid)
user_params['customer_profile_id'] = c.profile.id
else:
cname = _g('name').strip()
cp = CustomerProfile(name = "PROFILE_%s" % cname.strip().upper().replace(' ', '_'))
DBSession.add(cp)
DBSession.flush()
c = Customer(
name = cname,
address = _g('address'),
profile = cp
)
user_params['customer_profile_id'] = cp.id
DBSession.add(c)
DBSession.add(User(**user_params))
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('bpAuth.login'))
示例9: getDoctorDetail
def getDoctorDetail():
fields = ["lang", "doctorID", "clinicID"]
if _check_params(fields) != 0:
return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING})
lang = _g("lang")
dp = DBSession.query(DoctorProfile).get(_g("doctorID"))
base_info = dp.getUserProfile()
c = DBSession.query(Clinic).get(_g("clinicID"))
latitude = longtitude = None
if c.coordinate:
latitude, longtitude = c.coordinate.split(",")
return jsonify(
{
"result": 1,
"data": {
"doctorID": dp.id,
"name": {"zh_HK": base_info["display_name_tc"], "zh_CN": base_info["display_name_sc"]}.get(
lang, base_info["display_name"]
),
"desc": dp.desc,
"tel": c.tel,
"address": {"zh_HK": c.address_tc, "zh_CN": c.address_sc}.get(lang, c.address),
"image": base_info["image_url"],
"mapLocationX": longtitude,
"mapLocationY": latitude,
"rating": dp.rating,
},
}
)
示例10: ajax_save
def ajax_save(self):
id = _g("id")
type = _g('form_type')
if type not in ['sendout', 'transit', 'exception', 'arrived']:
return jsonify({'code' :-1, 'msg' : unicode(MSG_NO_SUCH_ACTION)})
header = DeliverHeader.get(id)
if type == 'sendout':
header.status = SEND_OUT[0]
DBSession.add(TransferLog(
refer_id = header.id,
transfer_date = _g('send_out_time'),
type = 1,
remark = _g('send_out_remark')
))
header.sendout_time = _g('send_out_time')
DBSession.add(SystemLog(
type = header.__class__.__name__,
ref_id = header.id,
remark = u'%s 确认该记录状态为已发货。' % session['user_profile']['name']
))
DBSession.commit()
self._sms(header, u'已发货。')
return jsonify({'code' : 0 , 'msg' : unicode(MSG_SAVE_SUCC)})
if type == 'transit':
DBSession.add(TransferLog(
refer_id = header.id,
transfer_date = _g('transit_time'),
type = 1,
remark = _g('transit_remark')
))
DBSession.commit()
return jsonify({'code' : 0 , 'msg' : unicode(MSG_SAVE_SUCC)})
if type == 'arrived' :
header.status = GOODS_ARRIVED[0]
DBSession.add(TransferLog(
refer_id = header.id,
transfer_date = _g('arrived_time'),
type = 1,
remark = _g('arrived_remark')
))
DBSession.add(SystemLog(
type = header.__class__.__name__,
ref_id = header.id,
remark = u'%s 确认记录状态为货物已到达目的站。' % session['user_profile']['name']
))
for d in header.details:
order_header = d.order_header
order_header.actual_time = _g('arrived_time')
DBSession.commit()
self._sms(header, u'已到达。')
return jsonify({'code' : 0 , 'msg' : unicode(MSG_SAVE_SUCC)})
示例11: ajax_change_flag
def ajax_change_flag(self):
try:
ids = _g('order_ids', '').split("|")
flag = _g('flag')
type = _g('type')
for r in DBSession.query(OrderHeader).filter(OrderHeader.id.in_(ids)).order_by(OrderHeader.create_time):
if type == 'APPROVE':
r.approve = flag
if flag == '1': # approve
remark = u'%s 审核通过该订单。' % session['user_profile']['name']
else: # disapprove
remark = u'%s 审核不通过该订单。' % session['user_profile']['name']
elif type == 'PAID':
r.paid = flag
if flag == '1':
remark = u'%s 确认该订单为客户已付款。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为客户未付款。' % session['user_profile']['name']
elif type == 'SUPLLIER_PAID':
r.supplier_paid = flag
if flag == '1':
remark = u'%s 确认该订单为已付款予承运商。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为未付款予承运商。' % session['user_profile']['name']
elif type == 'ORDER_RETURN':
r.is_return_note = flag
if flag == '1':
remark = u'%s 确认该订单为客户已返回单。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为客户未返回单。' % session['user_profile']['name']
elif type == 'EXCEPTION':
r.is_exception = flag
if flag == '1':
remark = u'%s 标记该订单为异常。' % session['user_profile']['name']
else:
remark = u'%s 取消该订单的异常标记。' % session['user_profile']['name']
elif type == 'LESS_QTY':
r.is_less_qty = flag
if flag == '1':
remark = u'%s 标记该订单为少货。' % session['user_profile']['name']
else:
remark = u'%s 取消该订单的少货标记。' % session['user_profile']['name']
DBSession.add(SystemLog(
type = r.__class__.__name__,
ref_id = r.id,
remark = remark
))
DBSession.commit()
return jsonify({'code' : 0 , 'msg' : MSG_UPDATE_SUCC})
except:
_error(traceback.print_exc())
DBSession.rollback()
return jsonify({'code' : 1, 'msg' : MSG_SERVER_ERROR})
示例12: barcode
def barcode(self):
method = _g('m', 'LIST')
if method not in ['LIST', 'NEW', 'PRINT', 'SAVE_NEW']:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR);
return redirect(url_for('.view', action = 'index'))
DBObj = Barcode
index_page = 'admin/barcode_index.html'
new_page = 'admin/barcode_new.html'
print_page = 'admin/barcode_print.html'
action = 'barcode'
if method == 'LIST':
if _g('SEARCH_SUBMIT'): # come from search
values = {'page' : 1}
for f in ['value', 'ref_no', 'status', 'create_time_from', 'create_time_to'] :
values[f] = _g(f)
values['field'] = _g('field', None) or 'create_time'
values['direction'] = _g('direction', None) or 'desc'
else: #come from paginate or return
values = session.get('master_barcode_values', {})
if _g('page') : values['page'] = int(_g('page'))
elif 'page' not in values : values['page'] = 1
session['master_barcode_values'] = values
conditions = [DBObj.active == 0]
if values.get('value', None): conditions.append(DBObj.value.op('like')('%%%s%%' % values['value']))
if values.get('ref_no', None): conditions.append(DBObj.ref_no.op('like')('%%%s%%' % values['ref_no']))
if values.get('status', None): conditions.append(DBObj.status == values['status'])
if values.get('create_time_from', None): conditions.append(DBObj.create_time > values['create_time_from'])
if values.get('create_time_to', None): conditions.append(DBObj.create_time < '%s 23:59' % values['create_time_to'])
field = values.get('field', 'create_time')
if values.get('direction', 'desc') == 'desc':
result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(desc(getattr(DBObj, field)))
else:
result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(getattr(DBObj, field))
def url_for_page(**params): return url_for('bpAdmin.view', action = action, m = 'LIST', page = params['page'])
records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = 100, url = url_for_page)
return render_template(index_page, records = records, action = action, values = values)
elif method == 'NEW':
return render_template(new_page, action = action)
elif method == 'PRINT':
ids = _gl('ids')
records = DBSession.query(DBObj).filter(DBObj.id.in_(ids)).order_by(desc(DBObj.create_time))
return render_template(print_page, records = records)
elif method == 'SAVE_NEW':
qty = _g('qty')
records = [DBObj.getOrCreate(None, None, status = 1) for i in range(int(qty))]
DBSession.commit()
if _g('type') == 'CREATE':
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = action))
else:
return render_template(print_page, records = records)
示例13: compute_by_diqu
def compute_by_diqu(self):
province_id = _g('province_id')
city_id = _g('city_id')
customer_id = _g('customer_id')
# count the ratio
ratio_result = self._compute_ratio(customer_id, province_id, city_id)
# count the day
day_result = self._compute_day(province_id, city_id)
ratio_result.update(day_result)
ratio_result.update({'code' : 0})
return jsonify(ratio_result)
示例14: out_note_save_update
def out_note_save_update(self):
id = _g('id')
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for(".view", action = "out_note"))
obj = DBSession.query(InventoryOutNote).get(id)
for f in ['customer_id', 'so', 'po', 'dn', 'ref', 'remark' ] : setattr(obj, f, _g(f))
total_qty = total_weight = total_area = 0
details_mapping = {}
for d in obj.details : details_mapping['%s' % d.id] = d
for qk, qv in _gp("qty_"):
id = qk.split("_")[1]
if id not in details_mapping : continue
d = details_mapping[id]
qty = self._p(_g('qty_%s' % id), int, 0)
weight = self._p(_g('weight_%s' % id), float, 0)
area = self._p(_g('area_%s' % id), float, 0)
total_qty += qty
total_area += area
total_weight += weight
if obj.status != 2:
# update the locaion-item relation
t = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.location_id == d.location_id,
InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one()
if obj.status == 1: # if the record is approved,update the real qty/weight/area
t.qty -= qty - d.qty
t.weight -= weight - d.weight
t.area -= area - d.area
t.exp_qty -= qty - d.qty
t.exp_weight -= weight - d.weight
t.exp_area -= area - d.area
d.qty = qty
d.weight = weight
d.area = area
obj.qty = total_qty
obj.area = total_area
obj.weight = total_weight
DBSession.commit()
flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
return redirect(url_for(".view", action = "out_note_review", id = obj.id))
示例15: save_profile
def save_profile():
id = session['user_profile']["id"]
u = connection.User.one({"id" : id})
u.first_name = _g("first_name")
u.last_name = _g("last_name")
u.phone = _g("phone")
u.birthday = _g("birthday")
try:
f = upload("image_url")
u.image_url = f.id
except:
app.logger.error(traceback.format_exc())
u.save()
flash("Update the profile successfully!", MESSAGE_INFO)
return redirect(url_for("index"))