Ejemplo n.º 1
0
	def create(self, validated_data):
		currency = Currency(**validated_data)
		currency.save()

		# If the instance updated is set to default, then unset "default"
		# from any other currency (there can only be 1 default).
		if currency.default:
			currencies = Currency.objects.all().exclude(pk=currency.pk)
			currencies.update(default=False)

		return currency
Ejemplo n.º 2
0
def get_cart(request):
	"""First see if current user already got a cart.
	If got cart, load it. else create a new one with default settings.
	"""
	if 'id_cart' in request.session:
		cart = Cart.objects.get(pk=request.session['id_cart'])
	else:
		# Get the current currency of the user, or default currency.
		currency = Currency.get_current_currency(request)

		cart = Cart(currency=currency)
		
		# If a Default Carrier exist, then add it to the cart
		# when the user creates his first cart.
		try: 
			carrier = Carrier.objects.get(default=True)
			cart.carrier = carrier
		except Carrier.DoesNotExist:
			pass

		cart.save()

		request.session['id_cart'] = cart.pk

	return cart
Ejemplo n.º 3
0
	def format_price(price, decimals=False, request=None):
		from lindshop.core.pricing.models import Currency
		if decimals:
			price = "{0:.2f}".format(float(price))
		elif price % 1 == 0:
			price = int(price)
		else:
			price = "{0:.2f}".format(float(price))

		currency = Currency.get_current_currency(request)
		return currency.format % price