def _compute_ratio(self, customer_id, province_id, city_id): qty_ratio = '' weight_ratio = '' vol_ratio = '' q1 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, CustomerDiquRatio.customer_id == customer_id, CustomerDiquRatio.province_id == province_id, CustomerDiquRatio.city_id == city_id, )) if q1.count() == 1: t = q1.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q2 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, CustomerDiquRatio.customer_id == customer_id, CustomerDiquRatio.province_id == province_id, CustomerDiquRatio.city_id == None, )) if q2.count() == 1: t = q2.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q3 = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id)) if q3.count() == 1: t = q3.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q4 = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id)) if q4.count() == 1: t = q4.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # try: # t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, # CustomerDiquRatio.customer_id == customer_id, # CustomerDiquRatio.province_id == province_id, # CustomerDiquRatio.city_id == city_id, # )).one() # qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # except: # try: # t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, # CustomerDiquRatio.customer_id == customer_id, # CustomerDiquRatio.province_id == province_id, # CustomerDiquRatio.city_id == None, # )).one() # qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # except: # try: # c = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id)).one() # qty_ratio, weight_ratio, vol_ratio = c.qty_ratio, c.weight_ratio, c.vol_ratio # except: # try: # p = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id)).one() # qty_ratio, weight_ratio, vol_ratio = p.qty_ratio, p.weight_ratio, p.vol_ratio # except: pass return {'qty_ratio' : qty_ratio, 'weight_ratio' : weight_ratio, 'vol_ratio' : vol_ratio}
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 review(self): id = _g('id') or None if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(self.default()) try: header = DBSession.query(OrderHeader).get(id) logs = [] logs.extend(header.get_logs()) try: deliver_detail = DBSession.query(DeliverDetail).filter(and_(DeliverDetail.active == 0, DeliverDetail.order_header_id == header.id)).one() deliver_heaer = deliver_detail.header # for f in deliver_heaer.get_logs() : _info(f.remark) logs.extend(deliver_heaer.get_logs()) except: pass logs = sorted(logs, cmp = lambda x, y: cmp(x.transfer_date, y.transfer_date)) return { 'header' : header , 'transit_logs' : logs, } except: _error(traceback.print_exc()) flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(self.default())
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'))
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 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, }, } )
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 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)
def profit(self): if _g('SEARCH_SUBMIT'): # come from search values = {'page' : 1} for f in [ 'no', 'create_time_from', 'create_time_to', 'destination_province_id', 'destination_city_id', 'ref_no', 'deliver_no', 'supplier_id', 'payment_id', 'is_discount_return' ] : 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('fin_profit_values', {}) if _g('page') : values['page'] = int(_g('page')) elif 'page' not in values : values['page'] = 1 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['fin_profit_values'] = values conditions = [OrderHeader.active == 0, DeliverHeader.active == 0 , DeliverDetail.active == 0, DeliverHeader.id == DeliverDetail.header_id, OrderHeader.id == DeliverDetail.order_header_id, ] if values.get('create_time_from', None): conditions.append(OrderHeader.order_time > values['create_time_from']) if values.get('create_time_to', None): conditions.append(OrderHeader.order_time < '%s 23:59' % values['create_time_to']) if values.get('ref_no', None): conditions.append(OrderHeader.ref_no.op('like')('%%%s%%' % values['ref_no'])) if values.get('deliver_no', None): conditions.append(DeliverHeader.no.op('like')('%%%s%%' % values['deliver_no'])) if values.get('destination_province_id', None): conditions.append(OrderHeader.destination_province_id == values['destination_province_id']) dp = DBSession.query(Province).get(values['destination_province_id']) destination_cites = dp.children() else: destination_cites = [] if values.get('destination_city_id', None): conditions.append(OrderHeader.destination_city_id == values['destination_city_id']) if values.get('supplier_id', None): conditions.append(DeliverHeader.supplier_id == values['supplier_id']) if values.get('payment_id', None): conditions.append(OrderHeader.payment_id == values['payment_id']) if values.get('is_discount_return', None): conditions.append(OrderHeader.is_discount_return == values['is_discount_return']) # for the sort function field = values.get('field', 'create_time') if values.get('direction', 'desc') == 'desc': result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions)) else: result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions)) def url_for_page(**params): return url_for('bpFin.view', action = "profit", 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 { 'values' : values , 'records' : records, 'destination_cites' : destination_cites, }
def view_items(self): id = _g('id') w = DBSession.query(InventoryLocation).get(id) ids = w.full_path_ids.split("|") result = DBSession.query(InventoryItem, InventoryLocation).filter(and_( InventoryItem.active == 0, InventoryItem.location_id.in_(ids), InventoryLocation.active == 0, InventoryItem.location_id == InventoryLocation, )).order_by(InventoryItem.create_time).all() return {'result' : result , 'location' : w}
def list_doctors(): id = request.values.get("id", None) if not id: dps = DBSession.query(DoctorProfile).filter(DoctorProfile.active == 0) # dps = connection.DoctorProfile.find({'active':0}) data = [dp.populate() for dp in dps] else: c = DBSession.query(Clinic).get(id) # c = connection.Clinic.one({'active':0, 'id':int(id)}) # data = [connection.DoctorProfile.one({'id':i}).populate() for i in c.doctors] data = [i.populate() for i in c.doctors] return {"doctors": data}
def in_note(self): if _g('SEARCH_SUBMIT'): # come from search values = {'page' : 1} for f in ['no', 'create_time_from', 'create_time_to', 'customer_id', 'location_id' ] : 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('inventory_in_note_values', {}) if _g('page') : values['page'] = int(_g('page')) elif 'page' not in values : values['page'] = 1 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_in_note_values'] = values conditions = [InventoryInNote.active == 0] if values.get('create_time_from', None): conditions.append(InventoryInNote.create_time > values['create_time_from']) if values.get('create_time_to', None): conditions.append(InventoryInNote.create_time < '%s 23:59' % values['create_time_to']) if values.get('no', None): conditions.append(InventoryInNote.no.op('like')('%%%s%%' % values['no'])) if values.get('customer_id', None): conditions.append(InventoryInNote.customer_id == values['customer_id']) if values.get('location_id', None): conditions.extend([ InventoryNoteDetail.active == 0, InventoryNoteDetail.type == 'IN', InventoryNoteDetail.header_id == InventoryInNote.id, InventoryNoteDetail.location_id == values['location_id'], ]) # for the sort function field = values.get('field', 'create_time') if values.get('direction', 'desc') == 'desc': result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(desc(getattr(InventoryInNote, field))) else: result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(getattr(InventoryInNote, field)) def url_for_page(**params): return url_for('.view', action = "in_note", page = params['page']) records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page) root_locations = DBSession.query(InventoryLocation).filter(and_(InventoryLocation.active == 0, InventoryLocation.parent_id == None)).order_by(InventoryLocation.name) return { 'values' : values , 'records' : records, 'locations' : root_locations, }
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))
def isHoliday(clz, d): if isinstance(d, (str, unicode)): try: year, month, day = d[:10].split('-') DBSession.query(clz).filter(and_(clz.year == year, clz.month == month, clz.day == day)).one() return True except: pass elif isinstance(d, (datetime.datetime, datetime.date)): try: DBSession.query(clz).filter(and_(clz.year == d.year, clz.month == d.month, clz.day == d.day)).one() return True except: pass return False
def _compute_day(self, province_id, city_id): estimate_day = '' if city_id: c = DBSession.query(City).get(city_id) if c.shixiao: estimate_day = (dt.now() + timedelta(days = c.shixiao)).strftime(SYSTEM_DATE_FORMAT) else: p = DBSession.query(Province).get(province_id) if p.shixiao: estimate_day = (dt.now() + timedelta(days = p.shixiao)).strftime(SYSTEM_DATE_FORMAT) elif province_id: p = DBSession.query(Province).get(province_id) if p.shixiao: estimate_day = (dt.now() + timedelta(days = p.shixiao)).strftime(SYSTEM_DATE_FORMAT) return {'day' : estimate_day}
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, }
def view(self): id = _g('id') if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for('.view')) obj = DBSession.query(Customer).get(id) return {'obj' : obj}
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))
def saveProfile(self): uid = session['user_profile']['id'] user = DBSession.query(User).get(uid) user.mobile = _g('mobile') DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view'))
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 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 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 getUserProfile(self): user = DBSession.query(User).get(self.user_id) info = user.populate() info['profile_id'] = self.id info['desc'] = self.desc info['worktime_setting'] = self.worktime_setting return info
def out_note_review(self): id = _g('id') if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(self.default()) obj = DBSession.query(InventoryOutNote).get(id) return {'obj' : obj}
def getComment(): fields = ["lang", "doctorID"] if _check_params(fields) != 0: return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING}) comments = ( DBSession.query(DoctorComment, User) .filter( and_( DoctorComment.active == 0, User.active == 0, DoctorComment.create_by_id == User.id, DoctorComment.doctor_id == _g("doctorID"), ) ) .order_by(desc(DoctorComment.create_time)) ) return jsonify( { "result": 1, "data": [ {"userID": comment.create_by_id, "name": unicode(user), "comment": comment.content} for (comment, user) in comments ], } )
def getByID(id, obj, attr): from sys2do.model import DBSession from sys2do import model as dbModel v = getattr(DBSession.query(getattr(dbModel, obj)).get(id), attr) # v = getattr(getattr(, obj).one({"id" : id}), attr) return v() if callable(v) else v
def add(self): ratios = {} for r in DBSession.query(Ratio).filter(Ratio.active == 0): ratios[r.type] = r.value return { 'ratios' : ratios, }
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 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})
def m_events_list(): try: page = _g("page", 1) except: page = 1 es = DBSession.query(Events).filter(Events.active == 0).order_by(desc(Events.date)) paginate_events = Page(es, page = page, items_per_page = ITEM_PER_PAGE, url = lambda page:"%s?page=%d" % (url_for("m_events_list"), page)) return {"paginate_events" : paginate_events}