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


Python Messages.permissionDenied方法代码示例

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


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

示例1: delete

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

示例2: delete

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

示例3: category

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

示例4: list_tags

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

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

        query = request.params.get("query", None)
        if query:
            tags = balance.get_tags_starting_with(query)
        else:
            tags = balance.tags.order_by(dbFacade.model.BalanceTag.tag).all()

        total = len(tags)
        try:
            page_nr = int(request.params["page_nr"])
        except:
            page_nr = 1

        try:
            items_per_page = int(request.params["items_per_page"])
        except:
            items_per_page = 15

        subset = Page(tags, item_count=total, current_page=page_nr, items_per_page=items_per_page)
        return {
            "totalItems": total,
            "itemsFound": len(subset),
            "items": [{"uid": item.uid, "tag": item.tag} for item in subset],
        }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:32,代码来源:balances.py

示例5: delete

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

示例6: delete

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

示例7: _by_day

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

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

        conditions = [model.BalanceChange.c.balance_uid == balance_uid, model.BalanceChange.c.is_income == is_income]

        (start_date, end_date) = self._get_dates()
        if start_date:
            conditions.append(model.BalanceChange.c.occurred_on >= start_date)

        if end_date:
            conditions.append(model.BalanceChange.c.occurred_on <= end_date)

        dates = db.execute(select([func.sum(model.BalanceChange.c.amount).label('summary'), model.BalanceChange.c.occurred_on.label('date')],
            and_(*conditions),
            from_obj=[model.balance_changes_table], order_by=['date'], group_by=['date'])).fetchall()

        return { 
            "totalItems" : len(dates),
            "itemsFound": len(dates),
            "items" : [{ 
                "date" : item.date, 
                "summary": item.summary} for item in dates ]
        }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:30,代码来源:balance_changes.py

示例8: _list_by_category

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

        try:
            user_uid = h.authenticated_user().uid
        except:
            return { "failure": Messages.pemissionDenied() }
        if not Operations(db, model).can_see_balance(user_uid, balance_uid):
            return { "failure": Messages.permissionDenied() }

        now = date.today()
       
        select_expenses = select(
            [model.ExpenseCategory.c.uid.label('uid'), model.ExpenseCategory.c.name.label('name'), func.sum(model.BalanceChange.c.amount).label('summary')], 
            and_(model.BalanceChange.is_income==False,
                model.ExpenseCategory.uid==model.BalanceChange.expense_category_uid,
                model.BalanceChange.balance_uid==balance_uid,
                model.BalanceChange.occurred_on >= date(now.year, now.month, 1)), 
            from_obj=[model.expense_categories_table, model.balance_changes_table],
            group_by=[model.ExpenseCategory.c.uid, model.ExpenseCategory.c.name])

        select_incomes = select(
            [model.IncomeCategory.c.uid.label('uid'), model.IncomeCategory.c.name.label('name'), func.sum(model.BalanceChange.c.amount).label('summary')], 
            and_(model.BalanceChange.is_income==True,
                model.IncomeCategory.uid==model.BalanceChange.income_category_uid,
                model.BalanceChange.balance_uid==balance_uid,
                model.BalanceChange.occurred_on >= date(now.year, now.month, 1)), 
            from_obj=[model.income_categories_table, model.balance_changes_table],
            group_by=[model.IncomeCategory.c.uid, model.IncomeCategory.c.name])

        if expenses and incomes:
            query = union(select_expenses, select_incomes)
        else:
            query = expenses and select_expenses or select_incomes

        balance_changes = db.execute(query.order_by('name')).fetchall()
        total = len(balance_changes)
        try:
            page_nr = request.params['page_nr']
        except:
            page_nr = 1

        try:
            items_per_page = int(request.params['items_per_page'])
        except:
            items_per_page = 15
        
        subset = Page(balance_changes, item_count=total, current_page=page_nr, items_per_page=items_per_page)
        return { 
            "totalItems" : total,
            "itemsFound" : len(subset),
            "items" : [{ 
                "uid" : item.uid,
                "name" : item.name,
                "summary" : h.format_decimal(Decimal(item.summary))} for item in subset ]
        }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:59,代码来源:balance_changes.py

示例9: list

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import permissionDenied [as 别名]
    def list(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_see_balance(h.authenticated_user().uid):
            return { "failure": Messages.permissionDenied() }

        qr = balance.changes \
            .options(eagerload('expense_category'), eagerload('income_category'), eagerload('tags')) \
            .order_by(model.BalanceChange.occurred_on)

        (start_date, end_date) = self._get_dates()

        if start_date:
            qr = qr.filter(model.BalanceChange.occurred_on >= start_date)

        if end_date:
            qr = qr.filter(model.BalanceChange.occurred_on <= end_date)

        balance_changes = qr.all()

        total = len(balance_changes)
        try:
            page_nr = int(request.params['page_nr'])
        except:
            page_nr = 1

        try:
            items_per_page = int(request.params['items_per_page'])
        except:
            items_per_page = 15
        
        subset = Page(balance_changes, item_count=total, current_page=page_nr, items_per_page=items_per_page)
        return {
            "summary" : {
                "total" : self._total(balance_uid),
                "date_range" : {
                    "expenses" : self._expenses_for_date_range(balance_uid, start_date, end_date),
                    "incomes" : self._incomes_for_date_range(balance_uid, start_date, end_date),
                },
            },
            "changes": { 
            "totalItems" : total,
            "itemsFound" : len(subset),
            "items" : [{ 
                "uid" : item.uid, 
                "category_uid" : item.is_income and item.income_category_uid or item.expense_category_uid, 
                "category" : (item.is_income and item.income_category or item.expense_category).name, 
                "amount" : Decimal(item.amount), 
                "description" : item.description, 
                "occurred_on": str(item.occurred_on), 
                "is_income": item.is_income,
                "tags_as_string": item.tags_as_string()} for item in subset ]
            }
        }
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:58,代码来源:balance_changes.py

示例10: edit

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

        uid = int(request.params['uid'])
        bc = balance.changes.filter_by(uid=uid).first()
        if not bc:
            abort(404)

        try:
             with localcontext() as ctx:
                ctx.prec = 2
                bc.amount = h.parse_decimal(request.params['amount'])
        except:
            log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1)
            pass

        try:
            if int(request.params['is_income']) >= 0:
                bc.income_category_uid = int(request.params['income_category_uid'])
                bc.expense_category_uid = None
                bc.is_income = True
            else:
                bc.expense_category_uid = int(request.params['expense_category_uid'])
                bc.income_category_uid = None
                bc.is_income = False
        except:
            pass

        try:
            bc.description = request.params['description']
        except:
            pass

        try:
            bc.occurred_on = h.parse_date(request.params['occurred_on'])
        except:
            log.error("Invalid date: %s" % request.params.get('occurred_on'), exc_info=1)
            pass

        ops = Operations(db, model)
        try:
            ops.change_tags_from_string(bc, request.params['tags'])
        except:
            pass

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

示例11: add

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

示例12: add

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

示例13: edit

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

        uid = int(request.params['uid'])
        bc = balance.changes.filter_by(uid=uid).first()
        if not bc:
            abort(404)

        try:
             with localcontext() as ctx:
                ctx.prec = 2
                bc.amount = h.parse_decimal(request.params['amount'])
        except:
            log.error("Invalid number: %s" % request.params.get('amount'), exc_info=1)
            pass

        try:
            if int(request.params['is_income']) >= 0:
                bc.income_category_uid = int(request.params['income_category_uid'])
                bc.expense_category_uid = None
                bc.is_income = True
            else:
                bc.expense_category_uid = int(request.params['expense_category_uid'])
                bc.income_category_uid = None
                bc.is_income = False
        except:
            pass

        try:
            bc.description = request.params['description']
        except:
            pass

        try:
            bc.occurred_on = h.parse_date(request.params['occurred_on'])
        except:
            log.error("Invalid date: %s" % request.params.get('occurred_on'), exc_info=1)
            pass

        bc.tags = dbFacade.balances.find_or_create_tags(balance, 
            dbFacade.balances.elements_from_string(request.params.get('tags', '')))

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

示例14: add

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

示例15: edit

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

        uid = int(request.params["uid"])
        if not Operations(db, model).can_modify_balance(h.authenticated_user().uid, uid):
            return {"failure": Messages.permissionDenied()}

        balance = db.query(model.Balance).filter_by(uid=uid).one()
        try:
            balance.name = request.params["name"]
        except:
            pass
        db.commit()

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


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