Beispiel #1
0
 def printable_amount(self):
     unit = self.unit
     if self.amount == 0:
         unit = 'OUNCE'
     if getattr(self.recipe, 'unit_system', None) == 'METRIC':
         return UnitConvert.to_str(*to_metric(self.amount, unit))
     return UnitConvert.to_str(self.amount, unit)
Beispiel #2
0
    def get_all(self):
        #
        # If you're not logged in, and you already have a trial recipe,
        # redirect to *that* recipe so you can't create another one.
        #
        recipe = request.context['trial_recipe']
        if request.context['user'] is None and recipe is not None:
            redirect(recipe.url(public=False))

        form = request.pecan['form']
        metric = request.context.get('metric') is True
        if request.context['user']:
            settings = request.context['user'].settings
            volume = settings['default_recipe_volume']
            if metric:
                volume = round(to_metric(*(volume, 'GALLON'))[0], 3)
            form.process(**{
                'type': settings['default_recipe_type'],
                'volume': format_volume(volume)
            })
        else:
            form.process(**{
                'volume': 20 if metric else 5,
                'unit': 'LITER' if metric else 'GALLON'
            })

        return dict(form=form)
Beispiel #3
0
 def printable_amount(self):
     unit = self.unit
     if self.amount == 0:
         unit = 'OUNCE'
     if getattr(self.recipe, 'unit_system', None) == 'METRIC':
         return UnitConvert.to_str(*to_metric(self.amount, unit))
     return UnitConvert.to_str(self.amount, unit)
Beispiel #4
0
    def test_passthrough(self):
        assert to_metric(*(5, "TSP")) == (5, "TSP")

        def test_ounces_to_kg(self):
            assert to_kg(*(16, "OUNCE")) == 2.2679618500000003

        def test_pound_to_kg(self):
            assert to_kg(*(5, "POUND")) == 2.2679618500000003

        def test_gram_to_kg(self):
            assert to_kg(*(5, "GRAM")) == 0.005

        def test_kg_to_kg(self):
            assert to_kg(*(5, "KILOGRAM")) == 5
Beispiel #5
0
    def test_passthrough(self):
        assert to_metric(*(5, 'TSP')) == (5, 'TSP')

        def test_ounces_to_kg(self):
            assert to_kg(*(16, 'OUNCE')) == 2.2679618500000003

        def test_pound_to_kg(self):
            assert to_kg(*(5, 'POUND')) == 2.2679618500000003

        def test_gram_to_kg(self):
            assert to_kg(*(5, 'GRAM')) == 0.005

        def test_kg_to_kg(self):
            assert to_kg(*(5, 'KILOGRAM')) == 5
Beispiel #6
0
    def test_passthrough(self):
        assert to_metric(*(5, 'TSP')) == (5, 'TSP')

	def test_ounces_to_kg(self):
		assert to_kg(*(16, 'OUNCE')) == 2.2679618500000003

	def test_pound_to_kg(self):
		assert to_kg(*(5, 'POUND')) == 2.2679618500000003

	def test_gram_to_kg(self):
		assert to_kg(*(5, 'GRAM')) == 0.005

	def test_kg_to_kg(self):
		assert to_kg(*(5, 'KILOGRAM')) == 5
Beispiel #7
0
 def test_ounce_to_gram(self):
     """Convert oz to g"""
     assert to_metric(*(1, 'OUNCE')) == (28.3495231, 'GRAM')
Beispiel #8
0
 def test_pound_to_g(self):
     """If the pound -> kg conversion is < 1kg, use grams instead"""
     assert to_metric(*(1, 'POUND')) == (453.59237000000002, 'GRAM')
Beispiel #9
0
 def test_pound_to_kg(self):
     """Convert pounds to kg"""
     assert to_metric(*(5, 'POUND')) == (2.2679618500000003, 'KILOGRAM')
Beispiel #10
0
    def printable_amount(self):
        if getattr(self.recipe, 'unit_system', None) == 'METRIC':
            return UnitConvert.to_str(*to_metric(self.amount, self.unit))

        return UnitConvert.to_str(self.amount, self.unit)
Beispiel #11
0
 def test_pound_to_g(self):
     """If the pound -> kg conversion is < 1kg, use grams instead"""
     assert to_metric(*(1, 'POUND')) == (453.59237000000002, 'GRAM')
Beispiel #12
0
    def printable_amount(self):
        if getattr(self.recipe, 'unit_system', None) == 'METRIC':
            return UnitConvert.to_str(*to_metric(self.amount, self.unit))

        return UnitConvert.to_str(self.amount, self.unit)
Beispiel #13
0
 def liters(self):
     liters = to_metric(*(self.gallons, "GALLON"))[0]
     return round(liters, 3)
Beispiel #14
0
 def test_gallon_to_liter(self):
     """Convert gallons to liters"""
     assert to_metric(*(10, 'GALLON')) == (37.854117799999997, 'LITER')
Beispiel #15
0
 def test_ounce_to_gram(self):
     """Convert oz to g"""
     assert to_metric(*(1, 'OUNCE')) == (28.3495231, 'GRAM')
Beispiel #16
0
 def test_gallon_to_liter(self):
     """Convert gallons to liters"""
     assert to_metric(*(10, 'GALLON')) == (37.854117799999997, 'LITER')
Beispiel #17
0
 def liters(self):
     liters = to_metric(*(self.gallons, "GALLON"))[0]
     return round(liters, 3)
Beispiel #18
0
 def test_pound_to_kg(self):
     """Convert pounds to kg"""
     assert to_metric(*(5, 'POUND')) == (2.2679618500000003, 'KILOGRAM')