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})
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 !"})
def out_note_delete(self): id = _g("id") if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for(".view", action = "out_note")) try: note = DBSession.query(InventoryOutNote).get(id) note.active = 1 for d in note.details: location_item = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.active == 0, InventoryLocationItem.location_id == d.location_id, InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one() if note.status == 1 : # the record is not approved location_item.qty += d.qty location_item.area += d.area location_item.weight += d.weight location_item.exp_qty += d.qty location_item.exp_area += d.area location_item.exp_weight += d.weight DBSession.add(SystemLog( type = InventoryOutNote.__class__.__name__, ref_id = note.id, remark = u"%s 删除该记录。" % (session['user_profile']['name']) )) DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for(".view", action = "out_note"))
def saveNewApp(self): appName, appDesc = _gs('appName', 'appDesc') if not appName: flash(MSG_NO_APP_NAME, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createApp')) try: DBSession.query(AppObject).filter(and_(AppObject.active == 0, AppObject.name == appName)).one() except: try: app = AppObject(name = appName, desc = appDesc) DBSession.add(app) DBSession.flush() url = createApp(session['user_profile']['id'], APP_FOLDER, APP_PACKAGE, 'app%s' % app.id, app.name) if not url : raise Exception('App generation error!') url = '%s%s' % (WEBSITE_ROOT, url) imgFile = createQR(url) if not imgFile : raise Exception('QR code generation error!') DBSession.add(imgFile) app.appfile = imgFile DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) self._updateAppInSession() return redirect(url_for('.view')) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view')) else: flash(MSG_APP_NAME_DUPLICATED, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createApp'))
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())
def saveAsNew(clz, v): params = {} for f in clz._get_fields(): params[f] = v.get(f, None) or None obj = clz(**params) DBSession.add(obj) return obj
def save_new(self): try: obj = Customer( no = _g('no'), name = _g('name'), display_name = _g('display_name'), province_id = _g('province_id'), city_id = _g('city_id'), address = _g('address'), contact_person = _g('contact_person'), mobile = _g('mobile'), phone = _g('phone'), email = _g('email'), remark = _g('remark'), note_id = _g('note_id'), # payment_id = _g('payment_id'), ) DBSession.add(obj) obj.attachment = multiupload() DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'view', id = obj.id)) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view'))
def upload(self, file_name): try: f = self.request.files[file_name][0] original_fname = f['filename'] extension = os.path.splitext(original_fname)[1].lower() fname = Date2Text(dateTimeFormat = "%Y%m%d%H%M%S", defaultNow = True) + ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6)) final_filename = fname + extension d = os.path.join(self.application.settings.get("static_path"), self.application.settings.get("upload_relative_path")) if not os.path.exists(d): os.makedirs(d) full_path = os.path.join(d, final_filename) output_file = open(full_path, 'wb') output_file.write(f['body']) output_file.close() DBSession.add(Attachment(name = final_filename, path = full_path, original_name = original_fname, url = self.static_url("/".join([self.application.settings.get("upload_relative_path"), final_filename])))) DBSession.commit() return (0, original_fname, final_filename, full_path) except: DBSession.rollback() logging.error(traceback.print_exc()) return (1, None, None, None)
def saveAsNew(clz, v): params = {} for f in ['name', 'password', 'email', 'image_url', 'phone', 'mobile', ]: params[f] = v.get(f, None) or None one = clz(**params) DBSession.add(one) return one
def saveNewArticle(self): appid, title, sub_title, validate_date, desc, content = _gs('appid', 'title', 'sub_title', 'validate_date', 'desc', 'content') if not appid : flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING) return redirect(url_for('.view')) if not title: flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createArticle', appid = appid)) try: article = AppArticle( app_id = appid, title = title, sub_title = sub_title, desc = desc, content = content, validate_date = validate_date, ) DBSession.add(article) DBSession.flush() article.seq = article.id DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for(".view", action = "listArticle", appid = appid)) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) traceback.print_exc() return redirect(url_for(".view", action = "listArticle", appid = appid))
def save_events(): uid = request.values.get("uid", None) did = request.values.get("did", None) d = request.values.get("d", None) t = request.values.get("t", None) if not uid or not did or not d or not t: return jsonify({"success": False, "message": "The required info is not supplied !"}) format_date = lambda v: "-".join([v[:4], v[4:6], v[-2:]]) try: e = Events(user_id=uid, doctor_id=did, date=d, time=t, remark=request.values.get("remark", None)) DBSession.add(e) doctor = DBSession.query(DoctorProfile).get(did).getUserProfile() m = Message( subject=u"Booking request submit", user_id=session["user_profile"]["id"], content=u"%s make a booking with doctor %s at %s , %s." % (session["user_profile"]["name"], doctor["name"], t, format_date(d)), ) DBSession.add(m) DBSession.commit() return jsonify({"success": True, "message": "Save your request successfully !", "event_time": e.time}) except: DBSession.rollback() app.logger.error(traceback.format_exc()) return jsonify({"success": False, "message": "Error occur when submiting the request !"})
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)})
def saveAsNew(clz, v): params = { 'name' : v.get('name', None) or None, 'desc' : v.get('desc', None) or None, } one = clz(**params) DBSession.add(one) return one
def saveAsNew(clz, v): params = {} for f in ['name', 'code', 'province_id', 'city_id', 'begin_no', 'end_no', 'apply_time', 'apply_person_id', 'operator_id', 'remark']: params[f] = v.get(f, None) or None obj = clz(**params) DBSession.add(obj) return obj
def saveAsNew(clz, v): params = { "name" : v.get("name", None) or None, "desc" : v.get("desc", None) or None, "display_name" : v.get("display_name", None) or None } group = clz(**params) DBSession.add(group) return group
def save_new(clz, handler): params = { "user_name" : handler.get_argument("user_name", None), "email_address" : handler.get_argument("email_address", None), "display_name" : handler.get_argument("display_name", None), "password" : handler.get_argument("password", None), } record = clz(**params) DBSession.add(record) return record
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})
def delete(self): header = getOr404(OrderHeader, _g('id'), redirect_url = self.default()) header.active = 1 DBSession.add(SystemLog( type = header.__class__.__name__, ref_id = header.id, remark = u"%s 删除该记录。" % session['user_profile']['name'], )) DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'index'))
def insert_system_logs(self, comare_result): try: _remark = [u"[%s]'%s' 修改为 '%s'" % (name, ov, nv) for (name, ov, nv) in comare_result['update']] DBSession.add(SystemLog( type = self.__class__.__name__, ref_id = self.id, remark = u"%s 修改该记录。%s" % (session['user_profile']['name'], ";".join(_remark)) )) DBSession.commit() except: DBSession.rollback() _error(traceback.print_exc())
def getOrCreate(clz, value, ref_no, status = 0): if value: # get the existing try: b = DBSession.query(clz).filter(clz.value == value).one() return b except: pass #create b = clz(value = value, ref_no = ref_no, status = status) DBSession.add(b) DBSession.flush() b.value = '%s%06d' % (dt.now().strftime('%y%m%d'), (b.id % 1000000)) b.img = generate_barcode_file(b.value) return b
def init(): try: print "create tables" metadata.drop_all(engine, checkfirst = True) metadata.create_all(engine) DBSession.add(User(email = '*****@*****.**', password = '******')) DBSession.add(User(email = '*****@*****.**', password = '******')) DBSession.commit() print "finish init!" except: traceback.print_exc() DBSession.rollback()
def vendor_input_save(self): if not session.get('supplier_profile', None) or not session['supplier_profile'].get('id', None): flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR) return redirect(url_for('bpRoot.view', action = "index")) header = DeliverHeader.get(_g('id')) if not header : flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('.view', action = 'vendor_select')) elif header.supplier_id != session['supplier_profile']['id']: flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR) return redirect(url_for('bpRoot.view', action = "index")) if _g('type') == "IN_TRAVEL" : new_status = IN_TRAVEL[0] remark = u'货物在途。备注 :%s' % _g('remark') elif _g('type') == "GOODS_ARRIVED" : new_status = GOODS_ARRIVED[0] remark = u'货物到达。备注 :%s' % _g('remark') elif _g('type') == "GOODS_SIGNED" : new_status = GOODS_SIGNED[0] remark = u'货物签收。备注 :%s' % _g('remark') else: flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR) return redirect(url_for('.view', action = 'vendor_select')) try: header.update_status(new_status) for d in header.details: d.order_detail.update_status(new_status) # log = DeliverLog(deliver_header_id = header.id, remark = _g('remark')) # DBSession.add(log) DBSession.add(TransferLog( refer_id = header.id, transfer_date = dt.now().strftime(SYSTEM_DATETIME_FORMAT), type = 1, remark = remark )) DBSession.commit() except: DBSession.rollback() _error(traceback.print_exc()) flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view', action = 'vendor_select')) else: flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'vendor_select'))
def out_note_save_new(self): params = {} for f in ["customer_id", "so", "po", "dn", "ref", "remark", ]: params[f] = _g(f) try: header = InventoryOutNote(**params) DBSession.add(header) DBSession.flush() total_qty = total_area = total_weight = 0 for k, id in _gp("item_"): tmp_qty = int(_g('qty_%s' % id) or 0) tmp_area = float(_g('area_%s' % id) or 0) tmp_weight = float(_g('weight_%s' % id) or 0) total_qty += tmp_qty total_area += tmp_area total_weight += tmp_weight tmp_location_item = DBSession.query(InventoryLocationItem).get(id) tmp_location_item.exp_qty -= tmp_qty tmp_location_item.exp_area -= tmp_area tmp_location_item.exp_weight -= tmp_weight DBSession.add(InventoryNoteDetail( header_id = header.id, type = 'OUT', item_id = tmp_location_item.item_id, desc = tmp_location_item.item.desc, qty = tmp_qty, weight = tmp_weight, area = tmp_area, remark = _g('remark_%s' % id), location_id = tmp_location_item.location_id, )) header.qty = total_qty header.weight = total_weight header.area = total_area header.no = getOutNo(header.id) DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = "out_note_review", id = header.id)) except: DBSession.rollback() _error(traceback.print_exc()) flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for(".view", action = "index"))
def addComment(): fields = ["lang", "doctorID", "userID", "comment"] if _check_params(fields) != 0: return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING}) doctorID = _g("doctorID") userID = _g("userID") comment = _g("comment") if not doctorID or not userID or not comment: return jsonify({"result": 0, "msg": MSG_PARAMS_EMPTY}) try: DBSession.add(DoctorComment(doctor_id=doctorID, content=comment, create_by_id=doctorID)) DBSession.commit() return jsonify({"result": 1, "msg": MSG_SAVE_SUCCESS}) except: DBSession.rollback() return jsonify({"result": 0, "msg": MSG_SERVER_ERROR})
def delete(self): header = getOr404(DeliverHeader, _g('id'), redirect_url = self.default()) header.active = 1 for d in header.details: d.active = 1 d.order_header.deliver_header_no = None d.order_header.deliver_header_ref = None d.order_header.status = ORDER_NEW[0] DBSession.add(SystemLog( type = header.__class__.__name__, ref_id = header.id, remark = u'%s 删除送货该送货单。' % session['user_profile']['name'] )) DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'index'))
def upload(name): f = request.files.get(name, None) if not f : raise makeException(MSG_NO_FILE_UPLOADED) dir_path = os.path.join(UPLOAD_FOLDER_PREFIX, UPLOAD_FOLDER) if not os.path.exists(dir_path) : os.makedirs(dir_path) (pre, ext) = os.path.splitext(f.filename) converted_name = "%s%s" % (dt.now().strftime("%Y%m%d%H%M%S"), ext) path = os.path.join(dir_path, converted_name) f.save(path) db_file_name = os.path.basename(f.filename) db_file_path = os.path.join(UPLOAD_FOLDER, converted_name) u = UploadFile(create_by_id = session['user_profile']['id'], name = db_file_name, path = db_file_path, url = "/".join([UPLOAD_FOLDER_URL, converted_name])) DBSession.add(u) DBSession.flush() return u
def init(): try: print "create tables" metadata.drop_all(engine, checkfirst = True) metadata.create_all(engine) print "insert default value" DBSession.add(User(name = 'demo', password = '******')) for code in range(9121, 9140): DBSession.add(NFCData(authcode = unicode(code), company = 'RoyalDragonVodka', serial = code - 9000, )) f = open('country.txt', 'r') cs = f.readlines() f.close() for c in cs: n, c, iso = c.split('|') DBSession.add(MLocation(name = n, iso_code = iso, code = c)) DBSession.commit() print "finish init!" except: traceback.print_exc() DBSession.rollback()
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'))
def ajax_change_flag(self): try: id = _g('id') flag = _g('flag') type = _g('type') remark = None header = DBSession.query(DeliverHeader).get(id) if type == 'SUPLLIER_PAID': header.supplier_paid = flag if flag == '1': remark = u'%s 确认该记录为已付款予承运商。' % session['user_profile']['name'] else: remark = u'%s 确认该记录为未付款予承运商。' % session['user_profile']['name'] for d in header.details: d.supplier_paid = flag d.order_header.supplier_paid = flag DBSession.add(SystemLog( type = d.order_header.__class__.__name__, ref_id = d.order_header_id, remark = remark )) DBSession.add(SystemLog( type = header.__class__.__name__, ref_id = header.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})
def upload(name): f = request.files.get(name, None) if not f : raise makeException("No file upload!") if _allowedFile(f.filename): if not os.path.exists(UPLOAD_FOLDER) : os.makedirs(UPLOAD_FOLDER) converted_name = "%s.%s" % (dt.now().strftime("%Y%m%d%H%M%S"), f.filename.rsplit('.', 1)[1].lower()) path = os.path.join(UPLOAD_FOLDER, converted_name) f.save(path) u = UploadFile(create_by_id = session['user_profile']['id'], name = secure_filename(f.filename), path = path, url = "/".join([UPLOAD_FOLDER_URL, converted_name])) DBSession.add(u) DBSession.flush() return u # u = connection.UploadFile() # u.id = u.getID() # u.uid = session['user_profile']['id'] # u.name = unicode(secure_filename(f.filename)) # u.path = path # u.url = "/".join([UPLOAD_FOLDER_URL, converted_name]) # u.save() # return u else: raise makeException("Invalid file to upload!")