当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.add方法代码示例

本文整理汇总了Python中sys2do.model.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys2do.model.DBSession的用法示例。


在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
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})
开发者ID:LamCiuLoeng,项目名称:V3,代码行数:33,代码来源:api.py

示例2: m_events_update

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
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 !"})
开发者ID:LamCiuLoeng,项目名称:V3,代码行数:29,代码来源:manage.py

示例3: out_note_delete

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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"))
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:35,代码来源:inventory.py

示例4: saveNewApp

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
 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'))
开发者ID:LamCiuLoeng,项目名称:appwebsite,代码行数:35,代码来源:consoles.py

示例5: save_new

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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())
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:30,代码来源:warehouse.py

示例6: saveAsNew

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
 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
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:9,代码来源:auth.py

示例7: save_new

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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'))
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:29,代码来源:customer.py

示例8: upload

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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)
开发者ID:LamCiuLoeng,项目名称:BookStore,代码行数:27,代码来源:base.py

示例9: saveNewArticle

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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))
开发者ID:LamCiuLoeng,项目名称:appwebsite,代码行数:32,代码来源:consoles.py

示例10: save_events

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
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 !"})
开发者ID:LamCiuLoeng,项目名称:V3,代码行数:29,代码来源:action.py

示例11: ajax_save

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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)})
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:61,代码来源:deliver.py

示例12: saveAsNew

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:11,代码来源:master.py

示例13: save_new

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
 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
开发者ID:LamCiuLoeng,项目名称:BookStore,代码行数:12,代码来源:auth.py

示例14: ajax_change_flag

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
    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})
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:57,代码来源:fin.py

示例15: delete

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import add [as 别名]
 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'))
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:13,代码来源:order.py


注:本文中的sys2do.model.DBSession.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。