Пример #1
0
def cart():
    orders = []
    if 'order_products' not in session:
        session['order_products'] = []
    else:
        for item in session['order_products']:
            orders.append({
                "product": list(get_product(item["id"]))[0],
                "number": item["number"]
            })

    D128_CTX = create_decimal128_context()
    with decimal.localcontext(D128_CTX):
        total_price = sum([
            order["product"]['price'].to_decimal() *
            Decimal128(order['number']).to_decimal() for order in orders
        ])

    if "order_products" not in session:
        session["order_products"] = []
    num = len(session["order_products"])

    return render_template('blog/cart.html',
                           orders=orders,
                           total_price=total_price,
                           badge_num=num)
Пример #2
0
 def __init__(self):
     self.version: str = ""
     self.ct_value_limit = decimal.Decimal(30)
     self.d128_context = create_decimal128_context()
     self.result_regex = re.compile(f"^{RESULT_VALUE_POSITIVE}",
                                    re.IGNORECASE)
     self.root_sample_id_control_regex: Optional[Pattern[str]] = None
     self.evaluate_ct_values = False
Пример #3
0
    class Decimal(Number):
        __foreign__ = 'decimal'

        DECIMAL_CONTEXT = create_decimal128_context()

        def to_native(self, obj, name, value):  # pylint:disable=unused-argument
            if hasattr(value, 'to_decimal'):
                return value.to_decimal()

            return dec(value)

        def to_foreign(self, obj, name, value):  # pylint:disable=unused-argument
            if not isinstance(value, dec):
                with localcontext(self.DECIMAL_CONTEXT) as ctx:
                    value = ctx.create_decimal(value)

            return Decimal128(value)
Пример #4
0
 def getNextSeqNum(cls):
     #db = cls.db
     #print('getNextSeqNum::cls.db',cls.db)
     print('getNextSeqNum::db', db)
     #db = cls.db
     D128_CTX = create_decimal128_context()
     with decimal.localcontext(D128_CTX):
         d1 = Decimal128('0.1')
     seqDoc = db.seq.find_one_and_update(
         filter={'_id': "version"},
         update={'$inc': {
             "seq": d1
         }},
         return_document=ReturnDocument.AFTER)
     print('seqDoc::', seqDoc)
     print("seqDoc::seqDoc['seq']", seqDoc['seq'])
     #print('seqDoc::seqDoc.seq',seqDoc.seq)
     return Decimal128(str(seqDoc['seq']))
Пример #5
0
 def test_decimal128_context(self):
     ctx = create_decimal128_context()
     self.assertEqual("NaN", str(ctx.copy().create_decimal(".13.1")))
     self.assertEqual("Infinity", str(ctx.copy().create_decimal("1E6145")))
     self.assertEqual("0E-6176", str(ctx.copy().create_decimal("1E-6177")))
Пример #6
0
 def test_conversion(self):
     with decimal.localcontext(create_decimal128_context()) as ctx:
         expected = Decimal128(ctx.create_decimal('42'))
     self.assertConversion(self.field, expected, 42)
     self.assertConversion(self.field, expected, '42')
     self.assertConversion(self.field, expected, decimal.Decimal('42'))
Пример #7
0
 def test_conversion(self):
     with decimal.localcontext(create_decimal128_context()) as ctx:
         expected = Decimal128(ctx.create_decimal('42'))
     self.assertConversion(self.field, expected, 42)
     self.assertConversion(self.field, expected, '42')
     self.assertConversion(self.field, expected, decimal.Decimal('42'))
 def test_decimal128_context(self):
     ctx = create_decimal128_context()
     self.assertEqual("NaN", str(ctx.copy().create_decimal(".13.1")))
     self.assertEqual("Infinity", str(ctx.copy().create_decimal("1E6145")))
     self.assertEqual("0E-6176", str(ctx.copy().create_decimal("1E-6177")))