def update_cartline(id): # TODO when not enough stock, response ajax error line = CartLine.get_by_id(id) response = { "variantId": line.variant_id, "subtotal": 0, "total": 0, "cart": { "numItems": 0, "numLines": 0 }, } if request.form["quantity"] == "0": line.delete() else: line.quantity = int(request.form["quantity"]) line.save() cart = Cart.query.filter(Cart.user_id == current_user.id).first() response["cart"]["numItems"] = cart.update_quantity() response["cart"]["numLines"] = len(cart) response["subtotal"] = format_currency(line.subtotal, os.environ['BABEL_CURRENCY'], os.environ['BABEL_DEFAULT_LOCALE']) response["total"] = format_currency(cart.total, os.environ['BABEL_CURRENCY'], os.environ['BABEL_DEFAULT_LOCALE']) return jsonify(response)
def create_notification(self): if self.value >= 0: text = ("Insättning!\n{money}: {message}".format( money=flask_babel.format_currency(self.value / 100, 'SEK'), message=self.text)) elif self.value < 0: text = ("Uttag!\n{money}: {message}".format( money=flask_babel.format_currency(self.value / 100, 'SEK'), message=self.text)) notification = Notification(text=text, user_id=self.user_id, type='admintransaction', reference=str(self.id)) db.session.add(notification) db.session.commit()
def currencyformat_nc(number, currency, *args, **kwargs): """ Same as flask_babel.Babel.currencyformat, but without the "no currency ¤" sign when there is no currency. """ return format_currency( number, currency if currency != CurrencyConverter.no_currency else "", *args, **kwargs).strip()
def test_basics(self): app = flask.Flask(__name__) babel.Babel(app) n = 1099 with app.test_request_context(): assert babel.format_number(n) == u'1,099' assert babel.format_decimal(Decimal('1010.99')) == u'1,010.99' assert babel.format_currency(n, 'USD') == '$1,099.00' assert babel.format_percent(0.19) == '19%' assert babel.format_scientific(10000) == u'1E4'
def test_basics(self): app = flask.Flask(__name__) b = babel.Babel(app) n = 1099 with app.test_request_context(): assert babel.format_number(n) == u'1,099' assert babel.format_decimal(Decimal('1010.99')) == u'1,010.99' assert babel.format_currency(n, 'USD') == '$1,099.00' assert babel.format_percent(0.19) == '19%' assert babel.format_scientific(10000) == u'1E4'
def currency(context, number, currency=None, *args, **kwargs): if currency is None: currency = context.get("g").project.default_currency """ Same as flask_babel.Babel.currencyformat, but without the "no currency ¤" sign when there is no currency. """ return format_currency( number, currency if currency != CurrencyConverter.no_currency else "", *args, **kwargs).strip()
def hello(name=None): paragraph = None now = arrow.now() time = format_datetime(now, 'EEEE, d. MMMM yyyy H:mm') money = format_currency(1000000, 'CNY') if name != 'Nobody': paragraph = 'Hello %(name)s,\n Now is %(time)s,\nYour house provident fund is %(money)s' paragraph = gettext( 'Hello %(name)s,\n Now is %(time)s,\nYour house provident fund is %(money)s', name=name, time=time, money=money) return render_template('hello.html', paragraph=paragraph)
def costs(product_id): if request.method == 'POST': product_cost = tabapp.utils.current_product_cost(product_id) if product_cost: product_cost.end_date = date.today() product_cost = ProductCost() product_cost.product_id = product_id product_cost.value = request.form.get('product_cost') product_cost.start_date = date.today() db.session.add(product_cost) db.session.commit() return jsonify(result=True) product = Product.query.get(product_id) if not product: return abort(404) costs = [] for product_cost in product.costs: costs.append({ 'date': format_date(product_cost.start_date), 'value': format_currency(product_cost.value, 'EUR'), }) return jsonify(costs=costs)
def format_curr(amount): if not amount: amount = 0 return format_currency(amount, 'EUR')
def currency_filter(value): return format_currency(value, 'EUR')
def formatted_value(self): return flask_babel.format_currency(self.value / 100, 'SEK')
def formatted_balance(self): return flask_babel.format_currency(self.balance / 100, 'SEK')
def to_currency(value): return format_currency(value, 'BRL')
def index(): d = date(1984, 8, 12) t = time(22, 16) current_locale = str(get_locale()) if current_locale in ['es', 'de', 'mt', 'se_SE']: current_currency = 'EUR' elif current_locale == 'en_GB': current_currency = 'GBP' elif current_locale in ['en_AU']: current_currency = 'AUD' else: current_currency = 'USD' translate_current = gettext('Current') us_num = numbers.format_decimal(1.2345, locale='en_US') us_cur = numbers.format_currency(1.2345, locale='en_US', currency='USD') us_date = dates.format_date(d, locale='en_US') us_time = dates.format_time(t, locale='en_US') se_num = numbers.format_decimal(1.2345, locale='se_SE') se_cur = numbers.format_currency(1.2345, locale='se_SE', currency='EUR') se_date = dates.format_date(d, locale='se_SE') se_time = dates.format_time(t, locale='se_SE') mt_num = numbers.format_decimal(1.2345, locale='mt_MT') mt_cur = numbers.format_currency(1.2345, locale='mt_MT', currency='EUR') mt_date = dates.format_date(d, locale='mt_MT') mt_time = dates.format_time(t, locale='mt_MT') current_num = format_decimal(1.2345) current_cur = format_currency(1.2345, currency=current_currency) current_date = format_date(d) current_time = format_time(t) results = { 'us_num': us_num, 'us_cur': us_cur, 'us_date': us_date, 'us_time': us_time, 'se_num': se_num, 'se_cur': se_cur, 'se_date': se_date, 'se_time': se_time, 'mt_num': mt_num, 'mt_cur': mt_cur, 'mt_date': mt_date, 'mt_time': mt_time, 'current_num': current_num, 'current_cur': current_cur, 'current_date': current_date, 'current_time': current_time } return render_template('index.html', results=results, current_locale=current_locale, current=translate_current)
def price_to_str(price): return format_currency(number=price, currency='VND')