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


Python Messages.primaryKeyViolation方法代码示例

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


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

示例1: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self):
        model = request.environ["sqlalchemy.model"]
        db = request.environ["sqlalchemy.session"]

        try:
            name = request.params['name']
        except:
            return { "failure": Messages.invalidArguments() }

        if name == "":
            return { "failure": Messages.invalidArguments() }

        try:
            user = db.query(model.AuthenticatedUser).filter_by(uid = h.authenticated_user().uid).one()
            balance = model.Balance(name = name,)
            user_balance = model.UserBalance(user_uid=h.authenticated_user().uid, writable=True)
            balance.users.append(user_balance)
            user.balances.append(user_balance)
            db.save(balance)

            # ensure we set writable to true (needed only with sqlite3)
            #ub = db.query(model.UserBalance).filter_by(user_uid=session[BaseController.AUTHENTICATED_USER], balance_uid=balance.uid).one()
            #ub.writable = True
            #db.save(ub)

            db.commit()
        except IntegrityError, e:
            return { "failure": Messages.primaryKeyViolation() }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:30,代码来源:balances.py

示例2: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self, balance_uid):
        model = request.environ['sqlalchemy.model']
        db = request.environ['sqlalchemy.session']

        if not Operations(db, model).can_modify_balance(h.authenticated_user().uid, balance_uid):
            return { "failure": Messages.permissionDenied() }

        try:
            with localcontext() as ctx:
                ctx.prec = 2
            	try:
                	amount = h.parse_decimal(request.params['amount'])
            	except NumberFormatError:
                	return { "failure": Messages.invalidCurrencyFormat() }
            expense_date = parser.parse(request.params['occurred_on']) 
            income_category_uid = None
            expense_category_uid = None

            if (int(request.params['is_income']) >= 0):
                    income_category_uid = int(request.params['income_category_uid'])
                    is_income = True
            else:
                    expense_category_uid = int(request.params['expense_category_uid'])
                    is_income = False
        except:
            return { "failure": Messages.invalidArguments() }

        tags = request.params.get('tags', '')
    
        try:
            description = request.params['description']
        except:
            description = ""

        try:
            bc = model.BalanceChange(
                amount = amount, 
                description = description, 
                balance_uid = balance_uid, 
                user_uid = h.authenticated_user().uid, 
                expense_category_uid = expense_category_uid,
                occurred_on = expense_date,
                is_income = is_income,
                income_category_uid = income_category_uid
            )
            ops = Operations(db, model)
            ops.change_tags_from_string(bc, tags)
            ops.save_balance_change(bc)
        except IntegrityError, e:
            return { "failure": Messages.primaryKeyViolation() }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:52,代码来源:balance_changes.py

示例3: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self):
        model = request.environ["sqlalchemy.model"]
        db = request.environ["sqlalchemy.session"]

        name = request.params.get('name')
        if not name:
            return { "failure": Messages.invalidArguments() }

        try:
            ec = model.IncomeCategory(name = name,)
            db.save(ec)
            db.commit()
        except IntegrityError, e:
            return { "failure": Messages.primaryKeyViolation() }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:16,代码来源:income_categories.py

示例4: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self):
        db = self.get_sa_session()
        model = self.get_sa_model()

        try:
            name = request.params['name']
        except:
            return { "failure": Messages.invalidArguments() }

        if name == "":
            return { "failure": Messages.invalidArguments() }

        try:
            ec = model.ChangeCategory(name = name,)
            db.save(ec)
            db.commit()
        except IntegrityError, e:
            return { "failure": Messages.primaryKeyViolation() }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:20,代码来源:change_categories.py

示例5: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self):
        db = request.environ['sqlalchemy.session']
        model = request.environ['sqlalchemy.model']

        try:
            name = request.params['name']
        except:
            return { "failure": Messages.invalidArguments() }

        if name == "":
            return { "failure": Messages.invalidArguments() }

        try:
            ec = model.ExpenseCategory(name = name,)
            db.save(ec)
            db.commit()
        except IntegrityError, e:
            return { "failure": Messages.primaryKeyViolation() }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:20,代码来源:expense_categories.py

示例6: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import primaryKeyViolation [as 别名]
    def add(self):
        model = request.environ["sqlalchemy.model"]
        db = request.environ["sqlalchemy.session"]

        name = request.params.get("name")
        if not name:
            return {"failure": Messages.invalidArguments()}

        try:
            user = db.query(model.AuthenticatedUser).filter_by(uid=h.authenticated_user().uid).one()
            balance = model.Balance(name=name)
            user_balance = model.UserBalance(user_uid=h.authenticated_user().uid, writable=True)
            balance.users.append(user_balance)
            user.balances.append(user_balance)
            db.save(balance)
            db.commit()
        except IntegrityError, e:
            return {"failure": Messages.primaryKeyViolation()}
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:20,代码来源:balances.py


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