def test_login(self): """Tests the login view. """ from muecke.checkout.views import login from muecke.checkout.settings import CHECKOUT_TYPE_ANON from muecke.tests.utils import create_request request = create_request() # Anonymous from django.contrib.auth.models import AnonymousUser request.user = AnonymousUser() result = login(request) self.assertEqual(result.status_code, 200) # Set checkout_type shop = get_default_shop() shop.checkout_type = CHECKOUT_TYPE_ANON shop.save() # Fake a new reuqest request.shop = shop result = login(request) self.assertEqual(result.status_code, 302) # Authenticated request.user = self.user result = login(request) self.assertEqual(result.status_code, 302)
def get_parent_for_portlets(self): """Returns the parent for parents. """ if self.id == 1: return get_default_shop() else: return muecke_get_object_or_404(Page, pk=1)
def main(request): """context processor for muecke """ shop = get_default_shop(request) return { "SHOP": shop, "ANON_ONLY": shop.checkout_type == CHECKOUT_TYPE_ANON, "LFS_DOCS": settings.LFS_DOCS, }
def clean(self): """ """ msg = _(u"This field is required.") if self.data.get("is_anonymous") == "1" and \ getattr(settings, "LFS_INVOICE_EMAIL_REQUIRED") and \ self.cleaned_data.get("invoice_email") == "": self._errors["invoice_email"] = ErrorList([msg]) if not self.cleaned_data.get("no_shipping"): if self.cleaned_data.get("shipping_firstname") == "": self._errors["shipping_firstname"] = ErrorList([msg]) if self.cleaned_data.get("shipping_lastname") == "": self._errors["shipping_lastname"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_COMPANY_NAME_REQUIRED", False): if self.cleaned_data.get("shipping_company_name") == "": self._errors["shipping_company_name"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_PHONE_REQUIRED", False): if self.cleaned_data.get("shipping_phone") == "": self._errors["shipping_phone"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_EMAIL_REQUIRED", False): if self.cleaned_data.get("shipping_email") == "": self._errors["shipping_email"] = ErrorList([msg]) # check that shipping country is in the shops shipping countries list shop = get_default_shop() shipping_countries = shop.shipping_countries.all() shipping_country = None if not self.cleaned_data.get("no_shipping"): shipping_country_code = self.data.get("shipping-country", None) if shipping_country_code: shipping_country = Country.objects.get( code=shipping_country_code.lower()) if shipping_country: if shipping_country not in shipping_countries: msg = _(u"Invalid shipping country.") #self._errors["all"] = ErrorList([msg]) raise forms.ValidationError("Invalid Shipping Country") else: shipping_country_code = self.data.get("invoice-country", None) if shipping_country_code: shipping_country = Country.objects.get( code=shipping_country_code.lower()) # Check data of selected payment method payment_method_id = self.data.get("payment_method") payment_method = PaymentMethod.objects.get(pk=payment_method_id) if payment_method.type == muecke.payment.settings.PM_BANK: if self.cleaned_data.get("account_number", "") == "": self._errors["account_number"] = ErrorList([msg]) if self.cleaned_data.get("bank_identification_code", "") == "": self._errors["bank_identification_code"] = ErrorList([msg]) if self.cleaned_data.get("bank_name", "") == "": self._errors["bank_name"] = ErrorList([msg]) if self.cleaned_data.get("depositor", "") == "": self._errors["depositor"] = ErrorList([msg]) elif payment_method.type == muecke.payment.settings.PM_CREDIT_CARD: if self.cleaned_data.get("credit_card_owner", "") == "": self._errors["credit_card_owner"] = ErrorList([msg]) if self.cleaned_data.get("credit_card_number", "") == "": self._errors["credit_card_number"] = ErrorList([msg]) if self.cleaned_data.get("credit_card_verification", "") == "": self._errors["credit_card_verification"] = ErrorList([msg]) return self.cleaned_data
def clean(self): """ """ msg = _(u"This field is required.") if self.data.get("is_anonymous") == "1" and \ getattr(settings, "LFS_INVOICE_EMAIL_REQUIRED") and \ self.cleaned_data.get("invoice_email") == "": self._errors["invoice_email"] = ErrorList([msg]) if not self.cleaned_data.get("no_shipping"): if self.cleaned_data.get("shipping_firstname") == "": self._errors["shipping_firstname"] = ErrorList([msg]) if self.cleaned_data.get("shipping_lastname") == "": self._errors["shipping_lastname"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_COMPANY_NAME_REQUIRED", False): if self.cleaned_data.get("shipping_company_name") == "": self._errors["shipping_company_name"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_PHONE_REQUIRED", False): if self.cleaned_data.get("shipping_phone") == "": self._errors["shipping_phone"] = ErrorList([msg]) if getattr(settings, "LFS_SHIPPING_EMAIL_REQUIRED", False): if self.cleaned_data.get("shipping_email") == "": self._errors["shipping_email"] = ErrorList([msg]) # check that shipping country is in the shops shipping countries list shop = get_default_shop() shipping_countries = shop.shipping_countries.all() shipping_country = None if not self.cleaned_data.get("no_shipping"): shipping_country_code = self.data.get("shipping-country", None) if shipping_country_code: shipping_country = Country.objects.get(code=shipping_country_code.lower()) if shipping_country: if shipping_country not in shipping_countries: msg = _(u"Invalid shipping country.") #self._errors["all"] = ErrorList([msg]) raise forms.ValidationError("Invalid Shipping Country") else: shipping_country_code = self.data.get("invoice-country", None) if shipping_country_code: shipping_country = Country.objects.get(code=shipping_country_code.lower()) # Check data of selected payment method payment_method_id = self.data.get("payment_method") payment_method = PaymentMethod.objects.get(pk=payment_method_id) if payment_method.type == muecke.payment.settings.PM_BANK: if self.cleaned_data.get("account_number", "") == "": self._errors["account_number"] = ErrorList([msg]) if self.cleaned_data.get("bank_identification_code", "") == "": self._errors["bank_identification_code"] = ErrorList([msg]) if self.cleaned_data.get("bank_name", "") == "": self._errors["bank_name"] = ErrorList([msg]) if self.cleaned_data.get("depositor", "") == "": self._errors["depositor"] = ErrorList([msg]) elif payment_method.type == muecke.payment.settings.PM_CREDIT_CARD: if self.cleaned_data.get("credit_card_owner", "") == "": self._errors["credit_card_owner"] = ErrorList([msg]) if self.cleaned_data.get("credit_card_number", "") == "": self._errors["credit_card_number"] = ErrorList([msg]) if self.cleaned_data.get("credit_card_verification", "") == "": self._errors["credit_card_verification"] = ErrorList([msg]) return self.cleaned_data
def setUp(self): """ """ ie = Country.objects.get(code="ie") gb = Country.objects.get(code="gb") de = Country.objects.get(code="de") us = Country.objects.get(code="us") fr = Country.objects.get(code="fr") nl = Country.objects.get(code="nl") shop = get_default_shop() for ic in Country.objects.all(): shop.invoice_countries.add(ic) shop.shipping_countries.add(nl) shop.save() tax = Tax.objects.create(rate=19) shipping_method = ShippingMethod.objects.create( name="Standard", active=True, price=1.0, tax=tax ) self.by_invoice = PaymentMethod.objects.get(pk=BY_INVOICE) address1 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="2342", state="Gotham City", country=gb, ) address2 = Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="2443", state="Smallville", country=fr, ) self.username = '******' self.password = '******' new_user = User(username=self.username) new_user.set_password(self.password) new_user.save() self.user = new_user self.customer = Customer.objects.create( user=new_user, selected_shipping_method=shipping_method, selected_payment_method=self.by_invoice, selected_shipping_address=address1, selected_invoice_address=address2, ) self.PRODUCT1_NAME = "Surfboard" p1 = Product.objects.create( name=self.PRODUCT1_NAME, slug="product-1", sku="sku-1", price=1.1, tax=tax, stock_amount=100, active=True, ) p2 = Product.objects.create( name="Product 2", slug="product-2", sku="sku-2", price=2.2, tax=tax, stock_amount=50, active=True, ) cart = Cart.objects.create( user=new_user ) self.item1 = CartItem.objects.create( cart=cart, product=p1, amount=2, ) self.item2 = CartItem.objects.create( cart=cart, product=p2, amount=3, ) self.c = Client()
def cart_inline(request, template_name="muecke/cart/cart_inline.html"): """ The actual content of the cart. This is factored out to be reused within 'normal' and ajax requests. """ cart = cart_utils.get_cart(request) shopping_url = muecke.cart.utils.get_go_on_shopping_url(request) if cart is None: return render_to_string(template_name, RequestContext(request, { "shopping_url": shopping_url, })) shop = core_utils.get_default_shop(request) countries = shop.shipping_countries.all() selected_country = shipping_utils.get_selected_shipping_country(request) # Get default shipping method, so that we have a one in any case. selected_shipping_method = shipping_utils.get_selected_shipping_method(request) selected_payment_method = payment_utils.get_selected_payment_method(request) shipping_costs = shipping_utils.get_shipping_costs(request, selected_shipping_method) # Payment payment_costs = payment_utils.get_payment_costs(request, selected_payment_method) # Cart costs cart_price = cart.get_price_gross(request) + shipping_costs["price"] + payment_costs["price"] cart_tax = cart.get_tax(request) + shipping_costs["tax"] + payment_costs["tax"] # Discounts discounts = muecke.discounts.utils.get_valid_discounts(request) for discount in discounts: cart_price = cart_price - discount["price_gross"] # Voucher voucher_number = muecke.voucher.utils.get_current_voucher_number(request) try: voucher = Voucher.objects.get(number=voucher_number) except Voucher.DoesNotExist: display_voucher = False voucher_value = 0 voucher_tax = 0 voucher_message = MESSAGES[6] else: muecke.voucher.utils.set_current_voucher_number(request, voucher_number) is_voucher_effective, voucher_message = voucher.is_effective(request, cart) if is_voucher_effective: display_voucher = True voucher_value = voucher.get_price_gross(request, cart) cart_price = cart_price - voucher_value voucher_tax = voucher.get_tax(request, cart) else: display_voucher = False voucher_value = 0 voucher_tax = 0 # Calc delivery time for cart (which is the maximum of all cart items) max_delivery_time = cart.get_delivery_time(request) cart_items = [] for cart_item in cart.get_items(): product = cart_item.product quantity = product.get_clean_quantity(cart_item.amount) cart_items.append({ "obj": cart_item, "quantity": quantity, "product": product, "product_price_net": cart_item.get_price_net(request), "product_price_gross": cart_item.get_price_gross(request), "product_tax": cart_item.get_tax(request), }) return render_to_string(template_name, RequestContext(request, { "cart_items": cart_items, "cart_price": cart_price, "cart_tax": cart_tax, "shipping_methods": shipping_utils.get_valid_shipping_methods(request), "selected_shipping_method": selected_shipping_method, "shipping_price": shipping_costs["price"], "payment_methods": payment_utils.get_valid_payment_methods(request), "selected_payment_method": selected_payment_method, "payment_price": payment_costs["price"], "countries": countries, "selected_country": selected_country, "max_delivery_time": max_delivery_time, "shopping_url": shopping_url, "discounts": discounts, "display_voucher": display_voucher, "voucher_number": voucher_number, "voucher_value": voucher_value, "voucher_tax": voucher_tax, "voucher_number": muecke.voucher.utils.get_current_voucher_number(request), "voucher_message": voucher_message, }))
def setUp(self): """ """ ie = Country.objects.get(code="ie") gb = Country.objects.get(code="gb") de = Country.objects.get(code="de") us = Country.objects.get(code="us") shop = get_default_shop() for ic in Country.objects.all(): shop.invoice_countries.add(ic) shop.save() tax = Tax.objects.create(rate=19) shipping_method = ShippingMethod.objects.create( name="Standard", active=True, price=1.0, tax=tax ) self.by_invoice = PaymentMethod.objects.get(pk=BY_INVOICE) address1 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=ie, ) address2 = Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="Smallville", zip_code="2443", country=us, ) self.username = '******' self.password = '******' new_user = User(username=self.username) new_user.set_password(self.password) new_user.save() self.customer = Customer.objects.create( user=new_user, selected_shipping_method=shipping_method, selected_payment_method=self.by_invoice, selected_shipping_address=address1, selected_invoice_address=address2, ) self.PRODUCT1_NAME = "Surfboard" p1 = Product.objects.create( name=self.PRODUCT1_NAME, slug="product-1", sku="sku-1", price=1.1, tax=tax, active=True, ) p2 = Product.objects.create( name="Product 2", slug="product-2", sku="sku-2", price=2.2, tax=tax, active=True, ) cart = Cart.objects.create( user=new_user ) item = CartItem.objects.create( cart=cart, product=p1, amount=2, ) item = CartItem.objects.create( cart=cart, product=p2, amount=3, ) self.c = Client()
def migrate_to_07(self, application, version): from muecke.catalog.models import Product from muecke.catalog.settings import VARIANT from muecke.core.utils import get_default_shop from muecke.customer.models import Address from muecke.page.models import Page from muecke.shipping.models import ShippingMethod from muecke_order_numbers.models import OrderNumberGenerator # Product from muecke.catalog.settings import QUANTITY_FIELD_INTEGER from muecke.catalog.settings import QUANTITY_FIELD_TYPES db.add_column("catalog_product", "type_of_quantity_field", models.PositiveSmallIntegerField(_(u"Type of quantity field"), null=True, blank=True, choices=QUANTITY_FIELD_TYPES)) db.add_column("catalog_product", "category_variant", models.SmallIntegerField(_(u"Category variant"), blank=True, null=True)) db.add_column("catalog_product", "active_base_price", models.PositiveSmallIntegerField(_(u"Active base price"), default=0)) db.add_column("catalog_product", "base_price_unit", models.CharField(_(u"Base price unit"), blank=True, null=True, max_length=30, choices=settings.LFS_BASE_PRICE_UNITS)) db.add_column("catalog_product", "base_price_amount", models.FloatField(_(u"Base price amount"), default=0.0, blank=True, null=True)) if db.backend_name == "postgres": db.execute('ALTER TABLE catalog_product ALTER active_packing_unit TYPE smallint USING CASE WHEN active_packing_unit=FALSE THEN 0 ELSE 1 END;') else: db.alter_column('catalog_product', 'active_packing_unit', models.PositiveSmallIntegerField(_(u"Active packing"), default=0)) for product in Product.objects.all(): if product.active_packing_unit != 0: product.active_packing_unit = 1 product.save() # Pages print "Migrating to 0.7" db.add_column("page_page", "meta_title", models.CharField(_(u"Meta title"), blank=True, default="<title>", max_length=80)) db.add_column("page_page", "meta_keywords", models.TextField(_(u"Meta keywords"), null=True, blank=True)) db.add_column("page_page", "meta_description", models.TextField(_(u"Meta description"), null=True, blank=True)) for page in Page.objects.all(): page.meta_title = "<title>" page.meta_keywords = "" page.meta_description = "" page.save() # Copy the old page with id=1 and create a new one with id=1, which # will act as the root of all pages. try: page = Page.objects.get(pk=1) except Page.DoesNotExist: pass else: new_page = deepcopy(page) new_page.id = None new_page.save() page.delete() Page.objects.create(id=1, title="Root", slug="", active=1, exclude_from_navigation=1) # Shop db.add_column("core_shop", "meta_title", models.CharField(_(u"Meta title"), blank=True, default="<name>", max_length=80)) db.add_column("core_shop", "meta_keywords", models.TextField(_(u"Meta keywords"), null=True, blank=True)) db.add_column("core_shop", "meta_description", models.TextField(_(u"Meta description"), null=True, blank=True)) shop = get_default_shop() shop.meta_keywords = "" shop.meta_description = "" shop.save() # Order db.add_column("order_order", "number", models.CharField(max_length=30, unique=True, null=True)) OrderNumberGenerator.objects.create(pk="1", last=0) # Add new lines db.add_column("order_order", "invoice_company_name", models.CharField(null=True, blank=True, max_length=100)) db.add_column("order_order", "shipping_company_name", models.CharField(null=True, blank=True, max_length=100)) # Shipping Method db.add_column("shipping_shippingmethod", "price_calculator", models.CharField(max_length=200, choices=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS, default=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[0][0])) for shipping_method in ShippingMethod.objects.all(): shipping_method.price_calculator = settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[0][0] shipping_method.save() # Static Block db.add_column("catalog_staticblock", "position", models.PositiveSmallIntegerField(_(u"Position"), default=999)) # Addresses db.add_column("customer_address", "line1", models.CharField(_("Line 1"), max_length=100, blank=True, null=True)) db.add_column("customer_address", "line2", models.CharField(_("Line 2"), max_length=100, blank=True, null=True)) cursor = connection.cursor() cursor.execute("""SELECT id, street FROM customer_address""") for row in cursor.fetchall(): address = Address.objects.get(pk=row[0]) address.line1 = row[1] address.save() db.delete_column("customer_address", "street") application.version = "0.7" application.save()
def cart_inline(request, template_name="muecke/cart/cart_inline.html"): """ The actual content of the cart. This is factored out to be reused within 'normal' and ajax requests. """ cart = cart_utils.get_cart(request) shopping_url = muecke.cart.utils.get_go_on_shopping_url(request) if cart is None: return render_to_string( template_name, RequestContext(request, { "shopping_url": shopping_url, })) shop = core_utils.get_default_shop(request) countries = shop.shipping_countries.all() selected_country = shipping_utils.get_selected_shipping_country(request) # Get default shipping method, so that we have a one in any case. selected_shipping_method = shipping_utils.get_selected_shipping_method( request) selected_payment_method = payment_utils.get_selected_payment_method( request) shipping_costs = shipping_utils.get_shipping_costs( request, selected_shipping_method) # Payment payment_costs = payment_utils.get_payment_costs(request, selected_payment_method) # Cart costs cart_price = cart.get_price_gross( request) + shipping_costs["price"] + payment_costs["price"] cart_tax = cart.get_tax( request) + shipping_costs["tax"] + payment_costs["tax"] # Discounts discounts = muecke.discounts.utils.get_valid_discounts(request) for discount in discounts: cart_price = cart_price - discount["price_gross"] # Voucher voucher_number = muecke.voucher.utils.get_current_voucher_number(request) try: voucher = Voucher.objects.get(number=voucher_number) except Voucher.DoesNotExist: display_voucher = False voucher_value = 0 voucher_tax = 0 voucher_message = MESSAGES[6] else: muecke.voucher.utils.set_current_voucher_number( request, voucher_number) is_voucher_effective, voucher_message = voucher.is_effective( request, cart) if is_voucher_effective: display_voucher = True voucher_value = voucher.get_price_gross(request, cart) cart_price = cart_price - voucher_value voucher_tax = voucher.get_tax(request, cart) else: display_voucher = False voucher_value = 0 voucher_tax = 0 # Calc delivery time for cart (which is the maximum of all cart items) max_delivery_time = cart.get_delivery_time(request) cart_items = [] for cart_item in cart.get_items(): product = cart_item.product quantity = product.get_clean_quantity(cart_item.amount) cart_items.append({ "obj": cart_item, "quantity": quantity, "product": product, "product_price_net": cart_item.get_price_net(request), "product_price_gross": cart_item.get_price_gross(request), "product_tax": cart_item.get_tax(request), }) return render_to_string( template_name, RequestContext( request, { "cart_items": cart_items, "cart_price": cart_price, "cart_tax": cart_tax, "shipping_methods": shipping_utils.get_valid_shipping_methods(request), "selected_shipping_method": selected_shipping_method, "shipping_price": shipping_costs["price"], "payment_methods": payment_utils.get_valid_payment_methods(request), "selected_payment_method": selected_payment_method, "payment_price": payment_costs["price"], "countries": countries, "selected_country": selected_country, "max_delivery_time": max_delivery_time, "shopping_url": shopping_url, "discounts": discounts, "display_voucher": display_voucher, "voucher_number": voucher_number, "voucher_value": voucher_value, "voucher_tax": voucher_tax, "voucher_number": muecke.voucher.utils.get_current_voucher_number(request), "voucher_message": voucher_message, }))