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


Python Messages.invalidCurrencyFormat方法代码示例

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


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

示例1: add

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import invalidCurrencyFormat [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

示例2: add

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

        balance = db.query(model.Balance).filter_by(uid = balance_uid).first()
        if not balance or not balance.can_modify_balance(h.authenticated_user().uid):
            return { "failure": Messages.permissionDenied() }

        try:
            with localcontext() as ctx:
                ctx.prec = 2
                try:
                    amount = h.parse_decimal(request.params['amount'])
                except:
                    log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1)
                    return { "failure": Messages.invalidCurrencyFormat() }
            expense_date = h.parse_date(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:
            log.error("Failed to parse arguments %s" % str(request.params), exc_info=1)
            return { "failure": Messages.invalidArguments() }

        tags = request.params.get('tags', '')
        description = request.params.get('description', '')

        bc = model.BalanceChange(
            amount = amount, 
            description = description,
            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
        )

        balance.changes.append(bc)
        db.flush()
        ops = Operations(db, model)
        ops.change_tags_from_string(bc, tags)
        ops.save_balance_change(bc)

        return { "id" : bc.uid }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:52,代码来源:balance_changes.py

示例3: add

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

        balance = dbFacade.balances.balanceDao.find_by_uid(balance_uid)
        if not balance or not balance.can_modify_balance(h.authenticated_user().uid):
            return { "failure": Messages.permissionDenied() }

        try:
            with localcontext() as ctx:
                ctx.prec = 2
                try:
                    amount = h.parse_decimal(request.params['amount'])
                except:
                    log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1)
                    return { "failure": Messages.invalidCurrencyFormat() }
            expense_date = h.parse_date(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:
            log.error("Failed to parse arguments %s" % str(request.params), exc_info=1)
            return { "failure": Messages.invalidArguments() }

        tags = request.params.get('tags', '')
        description = request.params.get('description', '')

        bc = dbFacade.model.BalanceChange(
            amount = amount, 
            description = description,
            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
        )
        
        bc.tags = dbFacade.balances.find_or_create_tags(balance, 
            dbFacade.balances.elements_from_string(tags))

        dbFacade.balances.add_balance_change(balance, bc)
        dbFacade.db.commit()
        return { "id" : bc.uid }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:50,代码来源:balance_changes.py

示例4: _edit_stock

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import invalidCurrencyFormat [as 别名]
    def _edit_stock(self, stock):
        try:
            stock.ticker = request.params['ticker'][0:50].upper()
        except:
            return { "failure": Messages.invalidArguments() }

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

        try:
            stock.buy = asbool(request.params['buy'])
        except:
            return { "failure": Messages.invalidArguments() }
        
        try: 
            with localcontext() as ctx: 
                ctx.prec = 2 
                stock.price = h.parse_decimal(request.params['price']) 
        except: 
            log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1) 
            return { "failure": Messages.invalidCurrencyFormat() }

        try:
            stock.occurred_on = h.parse_date(request.params['occurred_on'])
        except:
            return { "failure": Messages.invalidDate() }

        if stock.user is None:
            stock.user = h.authenticated_user()

        self.dbFacade().stocks.changeDao.save(stock)
        self.dbFacade().db.commit()

        return { "id" : stock.uid }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:38,代码来源:stocks.py

示例5: _edit_change

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import invalidCurrencyFormat [as 别名]
    def _edit_change(self, to_bc):
        dbFacade = self.dbFacade()
    
        if to_bc.uid is not None:
            if not to_bc.balance or not to_bc.balance.can_modify_balance(h.authenticated_user().uid):
                return { "failure": Messages.permissionDenied() }

            # If it's a transfer check if user can modify the other balance
            if to_bc.transfer:
                old_from_balance = dbFacade.balances.balanceDao.find_by_uid(to_bc.transfer.balance_uid)
                if not old_from_balance or not old_from_balance.can_modify_balance(h.authenticated_user().uid):
                    return { "failure": Messages.permissionDenied() }

        to_balance_uid = request.params.get('to_balance_uid')
        to_balance = dbFacade.balances.balanceDao.find_by_uid(to_balance_uid)
        if not to_balance or not to_balance.can_modify_balance(h.authenticated_user().uid):
            return { "failure": Messages.permissionDenied() }

        try:
             with localcontext() as ctx:
                ctx.prec = 2
                to_bc.amount = h.parse_decimal(request.params['amount'])
        except:
            log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1)
            return { "failure": Messages.invalidCurrencyFormat() }
    
        try:
            to_bc.occurred_on = h.parse_date(request.params['occurred_on']) 
        except:
            return { "failure": Messages.invalidDate() }
            
        try:
            to_bc.change_category_uid = int(request.params['change_category_uid'])
        except:
            log.error("Failed to parse arguments %s" % str(request.params), exc_info=1)
            return { "failure": Messages.invalidArguments() }

        to_bc.balance = to_balance
        to_bc.tags = [dbFacade.model.ChangeTag(tag=tag) for tag in dbFacade.balances.elements_from_string(request.params.get('tags', ''))]
        to_bc.description = request.params.get('description', '')
        to_bc.user_uid = h.authenticated_user().uid

        from_balance_uid = request.params.get('from_balance_uid')
        if from_balance_uid is not None:
            if from_balance_uid == to_balance_uid:
                return { "failure": Messages.pleaseSelectDifferentAccounts() }

            from_balance = dbFacade.balances.balanceDao.find_by_uid(from_balance_uid)
            if not from_balance or not from_balance.can_modify_balance(h.authenticated_user().uid):
                return { "failure": Messages.permissionDenied() }

            from_bc = to_bc.transfer and to_bc.transfer or dbFacade.model.BalanceChange()
            to_bc.amount = abs(to_bc.amount)
            from_bc.amount = -to_bc.amount
            from_bc.occurred_on = to_bc.occurred_on
            from_bc.change_category_uid = to_bc.change_category_uid
            from_bc.balance = from_balance
            from_bc.tags = [dbFacade.model.ChangeTag(tag=tag) for tag in dbFacade.balances.elements_from_string(request.params.get('tags', ''))] 
            from_bc.description = to_bc.description
            from_bc.user_uid = h.authenticated_user().uid

            from_bc.transfer = to_bc
            to_bc.transfer = from_bc
        elif to_bc.transfer is not None:
            from_bc = to_bc.transfer
            from_bc.transfer = None
            to_bc.transfer = None
            dbFacade.db.flush()
            dbFacade.db.delete(from_bc)
            
        dbFacade.balances.changeDao.save(to_bc)
        dbFacade.db.commit()
        return { "id" : to_bc.uid }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:75,代码来源:balance_changes.py


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