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


Python Messages.elementNotFound方法代码示例

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


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

示例1: delete

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
    def delete(self):
        result = {}
        for id in request.params.getall('id'):
            try:
                item = self.dbFacade().balances.changeDao.find_by_uid(id, options=[eagerload('balance'), eagerload('transfer')])
                if item is None:
                    result[id] = {
                        "deleted" : False,
                        "message": Messages.elementNotFound(key=id)
                    }
                    continue

                if not item.balance or not item.balance.can_modify_balance(h.authenticated_user().uid) \
                    or (item.transfer and not item.transfer.balance) \
                    or (item.transfer and not item.transfer.balance.can_modify_balance(h.authenticated_user().uid)):
                    result[id] = {
                        "deleted" : False,
                        "message": Messages.permissionDenied()
                    }
                    continue
                
                if item.transfer:
                    self.dbFacade().db.delete(item.transfer)
                self.dbFacade().db.delete(item)
                self.dbFacade().db.commit()
                result[id] = { "deleted" : True }
            except Exception, e:
                result[id] = {
                    "deleted" : False,
                    "message" : Messages.failedToDelete(exception=e),
                }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:33,代码来源:balance_changes.py

示例2: delete

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

        result = {}
        for id in request.params.getall('id'):
            try:
                item = db.query(model.ChangeCategory).filter_by(uid=id).one()
            except InvalidRequestError:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            if (db.query(model.BalanceChange).filter_by(change_category_uid=item.uid).count() > 0):
                result[item.uid] = { 
                    "deleted" : False,
                    "message" : Messages.changeCategoryInUse(id=item.uid)
                }
            else:
                try:
                    db.delete(item)
                    db.commit()
                    result[item.uid] = {
                        "deleted" : True,
                    }
                except Exception, e:
                    result[item.uid] = {
                        "deleted" : False,
                        "message" : Messages.failedToDelete(exception=e),
                    }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:34,代码来源:change_categories.py

示例3: delete

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

        result = {}
        for id in request.params.getall('id'):
            try:
                item = db.query(model.BalanceChange).filter_by(uid=id).filter_by(balance_uid=balance_uid).one()
            except InvalidRequestError:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            else:
                try:
                    Operations(db, model).delete_balance_change(item)
                    result[item.uid] = {
                        "deleted" : True,
                    }
                except Exception, e:
                    result[item.uid] = {
                        "deleted" : False,
                        "message" : Messages.failedToDelete(exception=e),
                    }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:31,代码来源:balance_changes.py

示例4: delete

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
    def delete(self):
        dbFacade = self.dbFacade()

        result = {}
        for id in request.params.getall('id'):
            try:
                item = dbFacade.balances.balanceDao.find_by_uid(id)
                if not item or not item.can_modify_balance(h.authenticated_user().uid):
                    result[id] = {
                        "deleted": False,
                        "message": Messages.permissionDenied()
                    }
                    continue
            except InvalidRequestError:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            try:
                dbFacade.db.delete(item)
                dbFacade.db.commit()
                result[item.uid] = {
                    "deleted" : True,
                }
            except Exception, e:
                result[item.uid] = {
                    "deleted" : False,
                    "message" : Messages.failedToDelete(exception=e)
                }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:33,代码来源:balances.py

示例5: delete

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

        result = {}
        for id in request.params.getall('id'):
            try:
                item = db.query(model.IncomeCategory).filter_by(uid=id).one()
            except InvalidRequestError:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            if (db.query(model.BalanceChange).filter_by(income_category_uid=item.uid).count() > 0):
                result[item.uid] = { 
                    "deleted" : False,
                    "message" : Messages.incomeCategoryIsInUse(id=item.uid)
                }
            else:
                try:
                    db.delete(item)
                    db.commit()
                    result[item.uid] = {
                        "deleted" : True,
                    }
                except Exception, e:
                    result[item.uid] = {
                        "deleted" : False,
                        "message" : Messages.failedToDelete(exception=e)
                    }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:34,代码来源:income_categories.py

示例6: delete

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

        result = {}
        for id in request.params.getall('id'):
            try:
                if not Operations(db, model).can_modify_balance(h.authenticated_user().uid, id):
                    result[id] = {
                        "deleted": False,
                        "message": Messages.permissionDenied()
                    }
                    continue
                item = db.query(model.Balance).filter_by(uid=id).one()
            except InvalidRequestError:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            try:
                db.delete(item)
                db.commit()
                result[item.uid] = {
                    "deleted" : True,
                }
            except Exception, e:
                result[item.uid] = {
                    "deleted" : False,
                    "message" : Messages.failedToDelete(exception=e)
                }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:34,代码来源:balances.py

示例7: category

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
    def category(self):
        dbFacade = self.dbFacade()
        result = {}
            
        category = dbFacade.balances.categoryDao.find_by_name(request.params.get('category'))
        if category is None:
            return { "failure": Messages.invalidArguments() }

        for id in request.params.getall('id'):
            try:
                item = dbFacade.balances.changeDao.find_by_uid(id, options=[eagerload('balance')])
                if item is None:
                    result[id] = {
                        "deleted" : False,
                        "message": Messages.elementNotFound(key=id)
                    }
                    continue

                if not item.balance or not item.balance.can_modify_balance(h.authenticated_user().uid):
                    result[id] = {
                        "deleted" : False,
                        "message": Messages.permissionDenied()
                    }
                    continue

                item.category = category.name
                
                dbFacade.db.commit()
                result[id] = { "modified" : True }
            except Exception, e:
                result[id] = {
                    "deleted" : False,
                    "message" : Messages.failedToDelete(exception=e),
                }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:36,代码来源:balance_changes.py

示例8: delete

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
 def delete(self):
     result = {}        
     try:
         category_name = request.params.get('name')
         category_tc = self.dbFacade().balances.categoryDao.find_by_name(category_name, h.authenticated_user().uid)
         if category_tc is None:
             return { "failure" : Messages.elementNotFound(key=category_name) }
         parent = self.dbFacade().balances.categoryDao.find_by_key(category_tc.parent, h.authenticated_user().uid)                     
         self.dbFacade().db.delete(category_tc)
         self._change_changes_category(category_name, parent.name)
         self.dbFacade().db.commit()
     except Exception, e:
         return { "failure" : Messages.failedToDelete(exception=e) }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:15,代码来源:balance_categories.py

示例9: delete

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
    def delete(self):
        dbFacade = self.dbFacade()
        result = {}
        for id in request.params.getall('id'):
            item = dbFacade.stocks.changeDao.find_by_uid(id)
            if item is None:
                result[id] = {
                    "deleted" : False,
                    "message": Messages.elementNotFound(key=id)
                }
                continue

            try:
                dbFacade.db.delete(item)
                dbFacade.db.commit()
                result[item.uid] = {
                    "deleted" : True,
                }
            except Exception, e:
                result[item.uid] = {
                    "deleted" : False,
                    "message" : Messages.failedToDelete(exception=e)
                }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:25,代码来源:stocks.py

示例10: edit

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
 def edit(self):        
     category_tc = self.dbFacade().balances.categoryDao.find_by_name(request.params.get('old_name'), h.authenticated_user().uid)       
     if category_tc is None:
         return { "failure" : Messages.elementNotFound(key=request.params.get('old_name')) }
     return self._edit_category(category_tc, False)
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:7,代码来源:balance_categories.py

示例11: test_category_manage

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import elementNotFound [as 别名]
    def test_category_manage(self):

        existing_balance_url = url_for(controller='rest/balance_changes', action='list')
        response = self.app.get(existing_balance_url)
        self.assertEquals(200, response.status)

        signin_form = response.forms.get('login_form')
        self.failUnless(signin_form)
        signin_form.set('username', '[email protected]')
        signin_form.set('password', '[email protected]')
        response = signin_form.submit()
        self.assertEquals(200, response.status)

        category_name = 'Test1'        
        
        self.failIf(self.__in_categories(category_name)) 
        
        """ Add new category - Test1 """
        existing_balance_url = url_for(controller='rest/balance_categories', action='add', name=category_name, parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)        
        status = result.get('id')
        self.failIf(status is None)


        """ Add category again - Test1 should be failure"""
        existing_balance_url = url_for(controller='rest/balance_categories', action='add', name=category_name, parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        status = result.get('failure')
        self.assertEquals(status, Messages.categoryAlreadyExists(name=category_name))
        self.assertEquals(self.__in_categories(category_name), True)

        """ Edit category name """
        category_name_edit = 'Test2'
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='edit', name=category_name_edit, 
                                       old_name = category_name,
                                       parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('id')
        self.failIf(status is None)

        """ Edit category name again - should be error"""
        category_name_edit = 'Test2'
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='edit', name=category_name_edit, 
                                       old_name = category_name, 
                                       parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, Messages.elementNotFound(key=category_name))

        """ Delete category Test 2 """        
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='delete', name=category_name_edit, 
                                       )
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, None)
        self.failIf(self.__in_categories(category_name_edit))

        """ Delete category Test 1 - Fail """        
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='delete', name=category_name, 
                                       )
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, Messages.elementNotFound(key=category_name))
        self.failIf(self.__in_categories(category_name))
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:98,代码来源:test_rest_balance_categories.py


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