Exemple #1
0
def environment(request, template_name="manage/information/environment.html"):
    """Displays miscellaneous information about the evnironment.
    """
    apps = []
    for app in settings.INSTALLED_APPS:
        if app in ["muecke"] or \
           app.startswith("muecke.") or \
           app.startswith("django."):
            continue

        try:
            version = import_symbol("%s.__version__" % app)
        except AttributeError:
            version = "N/A"

        apps.append({
            "name": app,
            "version": version,
        })

    apps.sort(lambda a, b: cmp(a["name"], b["name"]))

    return render_to_response(template_name, RequestContext(request, {
        "muecke_version": muecke_version,
        "muecke_theme_version": muecke_theme_version,
        "apps": apps,
    }))
Exemple #2
0
    def save_criteria(self, request):
        """
        Saves all passed criteria (via request.POST) to the object.
        """
        # First we delete all existing criteria objects for the given object.
        for co in self.get_criteria():
            co.delete()

        # Then we add all passed criteria to the object.
        for key, model in request.POST.items():
            if key.startswith("type"):
                try:
                    id = key.split("-")[1]
                except KeyError:
                    continue

                # Get the values for the criterion
                operator = request.POST.get("operator-%s" % id)
                position = request.POST.get("position-%s" % id)

                criterion_class = import_symbol(model)
                criterion = criterion_class.objects.create(content=self, operator=operator, position=position)

                if criterion.get_value_type() == criterion.MULTIPLE_SELECT:
                    value = request.POST.getlist("value-%s" % id)
                else:
                    value = request.POST.get("value-%s" % id)

                criterion.update(value)
Exemple #3
0
def environment(request, template_name="manage/information/environment.html"):
    """Displays miscellaneous information about the evnironment.
    """
    apps = []
    for app in settings.INSTALLED_APPS:
        if app in ["muecke"] or \
           app.startswith("muecke.") or \
           app.startswith("django."):
            continue

        try:
            version = import_symbol("%s.__version__" % app)
        except AttributeError:
            version = "N/A"

        apps.append({
            "name": app,
            "version": version,
        })

    apps.sort(lambda a, b: cmp(a["name"], b["name"]))

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "muecke_version": muecke_version,
                "muecke_theme_version": muecke_theme_version,
                "apps": apps,
            }))
Exemple #4
0
def save_order_numbers_tab(request):
    """Saves the order number tab of the default shop.
    """
    shop = muecke.core.utils.get_default_shop()

    ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
    order_number = ong.objects.get(id="order_number")
    form = order_number.get_form(instance=order_number, data=request.POST)

    if form.is_valid():
        form.save()
        shop_changed.send(shop)
        message = _(u"Order numbers has been saved.")
    else:
        message = _(u"Please correct the indicated errors.")

    result = simplejson.dumps(
        {
            "html":
            [["#order_numbers",
              order_numbers_tab(request, shop, form)]],
            "message": message,
        },
        cls=LazyEncoder)

    return HttpResponse(result)
Exemple #5
0
 def get_tax(self, request):
     """
     Returns the absolute tax of the shipping method.
     """
     if self.price_calculator:
         price_class = import_symbol(self.price_calculator)
         return price_class(request, self).get_tax()
     else:
         return self.tax.rate
Exemple #6
0
 def get_price_net(self, request):
     """
     Returns the default price of the shipping method.
     """
     if self.price_calculator:
         price_class = import_symbol(self.price_calculator)
         return price_class(request, self).get_price_net()
     else:
         return self.price
Exemple #7
0
    def get_price(self, request):
        """Returns the gross price of the shipping method.

        This method is DEPRECATED.
        """
        if self.price_calculator:
            price_class = import_symbol(self.price_calculator)
            return price_class(request, self).get_price()
        else:
            return self.price
Exemple #8
0
def save_order_numbers_tab(request):
    """Saves the order number tab of the default shop.
    """
    shop = muecke.core.utils.get_default_shop()

    ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
    order_number = ong.objects.get(id="order_number")
    form = order_number.get_form(instance=order_number, data=request.POST)

    if form.is_valid():
        form.save()
        shop_changed.send(shop)
        message = _(u"Order numbers has been saved.")
    else:
        message = _(u"Please correct the indicated errors.")

    result = simplejson.dumps({
        "html": [["#order_numbers", order_numbers_tab(request, shop, form)]],
        "message": message,
    }, cls=LazyEncoder)

    return HttpResponse(result)
Exemple #9
0
    def handle(self, *args, **options):
        from muecke.core.models import ActionGroup
        from muecke.core.models import Action
        from muecke.core.models import Application
        from muecke.core.models import Country
        from muecke.core.models import Shop
        from muecke.core.utils import import_symbol

        from portlets.models import Slot
        from portlets.models import PortletAssignment

        from muecke.portlet.models import CartPortlet
        from muecke.portlet.models import CategoriesPortlet
        from muecke.portlet.models import PagesPortlet
        from muecke.payment.models import PaymentMethod
        from muecke.payment.settings import PM_BANK
        from muecke.page.models import Page
        from muecke.shipping.models import ShippingMethod

        # Country
        usa = Country.objects.create(code="us", name="USA")

        # Shop
        shop = Shop.objects.create(name="LFS",
                                   shop_owner="John Doe",
                                   from_email="*****@*****.**",
                                   notification_emails="*****@*****.**",
                                   description=SHOP_DESCRIPTION,
                                   default_country=usa)
        shop.invoice_countries.add(usa)
        shop.shipping_countries.add(usa)

        # Actions
        tabs = ActionGroup.objects.create(name="Tabs")
        footer = ActionGroup.objects.create(name="Footer")
        Action.objects.create(group=tabs,
                              title="Contact",
                              link="/contact",
                              active=True,
                              position=1)
        Action.objects.create(group=footer,
                              title="Terms and Conditions",
                              link="/page/terms-and-conditions",
                              active=True,
                              position=1)
        Action.objects.create(group=footer,
                              title="Imprint",
                              link="/page/imprint",
                              active=True,
                              position=2)

        # Portlets
        left_slot = Slot.objects.create(name="Left")
        right_slot = Slot.objects.create(name="Right")

        cart_portlet = CartPortlet.objects.create(title="Cart")
        PortletAssignment.objects.create(slot=right_slot,
                                         content=shop,
                                         portlet=cart_portlet)

        categories_portlet = CategoriesPortlet.objects.create(
            title="Categories")
        PortletAssignment.objects.create(slot=left_slot,
                                         content=shop,
                                         portlet=categories_portlet)

        pages_portlet = PagesPortlet.objects.create(title="Information")
        PortletAssignment.objects.create(slot=left_slot,
                                         content=shop,
                                         portlet=pages_portlet)

        # Payment methods
        pm = PaymentMethod.objects.create(name="Direct debit",
                                          priority=1,
                                          active=1,
                                          deletable=0,
                                          type=PM_BANK)
        pm.id = 1
        pm.save()
        pm = PaymentMethod.objects.create(name="Cash on delivery",
                                          priority=2,
                                          active=1,
                                          deletable=0)
        pm.id = 2
        pm.save()
        pm = PaymentMethod.objects.create(name="PayPal",
                                          priority=3,
                                          active=1,
                                          deletable=0)
        pm.id = 3
        pm.save()
        pm = PaymentMethod.objects.create(name="Prepayment",
                                          priority=4,
                                          active=1,
                                          deletable=0)
        pm.id = 4
        pm.save()

        # Shipping methods
        ShippingMethod.objects.create(name="Standard", priority=1, active=1)

        # Pages
        p = Page.objects.create(title="Root",
                                slug="",
                                active=1,
                                exclude_from_navigation=1)
        p.id = 1
        p.save()
        p = Page.objects.create(title="Terms and Conditions",
                                slug="terms-and-conditions",
                                active=1,
                                body="Enter your terms and conditions here.")
        p.id = 2
        p.save()
        p = Page.objects.create(title="Imprint",
                                slug="imprint",
                                active=1,
                                body="Enter your imprint here.")
        p.id = 3
        p.save()

        # Order Numbers
        ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
        ong.objects.create(id="order_number")

        # Application object
        Application.objects.create(version="0.7")
Exemple #10
0
    def handle(self, *args, **options):
        from muecke.core.models import ActionGroup
        from muecke.core.models import Action
        from muecke.core.models import Application
        from muecke.core.models import Country
        from muecke.core.models import Shop
        from muecke.core.utils import import_symbol

        from portlets.models import Slot
        from portlets.models import PortletAssignment

        from muecke.portlet.models import CartPortlet
        from muecke.portlet.models import CategoriesPortlet
        from muecke.portlet.models import PagesPortlet
        from muecke.payment.models import PaymentMethod
        from muecke.payment.settings import PM_BANK
        from muecke.page.models import Page
        from muecke.shipping.models import ShippingMethod

        # Country
        usa = Country.objects.create(code="us", name="USA")

        # Shop
        shop = Shop.objects.create(name="LFS", shop_owner="John Doe",
            from_email="*****@*****.**", notification_emails="*****@*****.**", description=SHOP_DESCRIPTION, default_country=usa)
        shop.invoice_countries.add(usa)
        shop.shipping_countries.add(usa)

        # Actions
        tabs = ActionGroup.objects.create(name="Tabs")
        footer = ActionGroup.objects.create(name="Footer")
        Action.objects.create(group=tabs, title="Contact", link="/contact", active=True, position=1)
        Action.objects.create(group=footer, title="Terms and Conditions", link="/page/terms-and-conditions", active=True, position=1)
        Action.objects.create(group=footer, title="Imprint", link="/page/imprint", active=True, position=2)

        # Portlets
        left_slot = Slot.objects.create(name="Left")
        right_slot = Slot.objects.create(name="Right")

        cart_portlet = CartPortlet.objects.create(title="Cart")
        PortletAssignment.objects.create(slot=right_slot, content=shop, portlet=cart_portlet)

        categories_portlet = CategoriesPortlet.objects.create(title="Categories")
        PortletAssignment.objects.create(slot=left_slot, content=shop, portlet=categories_portlet)

        pages_portlet = PagesPortlet.objects.create(title="Information")
        PortletAssignment.objects.create(slot=left_slot, content=shop, portlet=pages_portlet)

        # Payment methods
        pm = PaymentMethod.objects.create(name="Direct debit", priority=1, active=1, deletable=0, type=PM_BANK)
        pm.id=1; pm.save()
        pm = PaymentMethod.objects.create(name="Cash on delivery", priority=2, active=1, deletable=0)
        pm.id=2; pm.save()
        pm = PaymentMethod.objects.create(name="PayPal", priority=3, active=1, deletable=0)
        pm.id=3; pm.save()
        pm = PaymentMethod.objects.create(name="Prepayment", priority=4, active=1, deletable=0)
        pm.id=4; pm.save()

        # Shipping methods
        ShippingMethod.objects.create(name="Standard", priority=1, active=1)

        # Pages
        p = Page.objects.create(title="Root", slug="", active=1, exclude_from_navigation=1)
        p.id = 1; p.save()
        p = Page.objects.create(title="Terms and Conditions", slug="terms-and-conditions", active=1, body="Enter your terms and conditions here.")
        p.id = 2; p.save()
        p = Page.objects.create(title="Imprint", slug="imprint", active=1, body="Enter your imprint here.")
        p.id = 3; p.save()

        # Order Numbers
        ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
        ong.objects.create(id="order_number")

        # Application object
        Application.objects.create(version="0.7")
Exemple #11
0
def add_order(request):
    """Adds an order based on current cart for the current customer.

    It assumes that the customer is prepared with all needed information. This
    is within the responsibility of the checkout form.
    """
    customer = customer_utils.get_customer(request)
    order = None

    invoice_address = customer.selected_invoice_address
    if request.POST.get("no_shipping"):
        shipping_address = customer.selected_invoice_address
    else:
        shipping_address = customer.selected_shipping_address

    cart = cart_utils.get_cart(request)
    if cart is None:
        return order

    shipping_method = shipping_utils.get_selected_shipping_method(request)
    shipping_costs = shipping_utils.get_shipping_costs(request,
                                                       shipping_method)

    payment_method = payment_utils.get_selected_payment_method(request)
    payment_costs = payment_utils.get_payment_costs(request, payment_method)

    # Set email dependend on login state. An anonymous customer doesn't  have a
    # django user account, so we set the name of the invoice address to the
    # customer name.

    # Note: After this has been processed the order's customer email has an
    # email in any case. That means you can use it to send emails to the
    # customer.
    if request.user.is_authenticated():
        user = request.user
        customer_email = user.email
    else:
        user = None
        customer_email = customer.selected_invoice_address.email

    # Calculate the totals
    price = cart.get_price_gross(
        request) + shipping_costs["price"] + payment_costs["price"]
    tax = cart.get_tax(request) + shipping_costs["tax"] + payment_costs["tax"]

    # Discounts
    discounts = muecke.discounts.utils.get_valid_discounts(request)
    for discount in discounts:
        price = price - discount["price_gross"]
        tax = tax - discount["tax"]

    # Add voucher if one exists
    try:
        voucher_number = muecke.voucher.utils.get_current_voucher_number(
            request)
        voucher = Voucher.objects.get(number=voucher_number)
    except Voucher.DoesNotExist:
        voucher = None
    else:
        is_voucher_effective, voucher_message = voucher.is_effective(
            request, cart)
        if is_voucher_effective:
            voucher_number = voucher.number
            voucher_price = voucher.get_price_gross(request, cart)
            voucher_tax = voucher.get_tax(request, cart)

            price -= voucher_price
            tax -= voucher_tax
        else:
            voucher = None

    order = Order.objects.create(
        user=user,
        session=request.session.session_key,
        price=price,
        tax=tax,
        customer_firstname=customer.selected_invoice_address.firstname,
        customer_lastname=customer.selected_invoice_address.lastname,
        customer_email=customer_email,
        shipping_method=shipping_method,
        shipping_price=shipping_costs["price"],
        shipping_tax=shipping_costs["tax"],
        payment_method=payment_method,
        payment_price=payment_costs["price"],
        payment_tax=payment_costs["tax"],
        invoice_firstname=customer.selected_invoice_address.firstname,
        invoice_lastname=customer.selected_invoice_address.lastname,
        invoice_company_name=customer.selected_invoice_address.company_name,
        invoice_line1=invoice_address.line1,
        invoice_line2=invoice_address.line2,
        invoice_city=invoice_address.city,
        invoice_state=invoice_address.state,
        invoice_code=invoice_address.zip_code,
        invoice_country=Country.objects.get(code=invoice_address.country.code),
        invoice_phone=customer.selected_invoice_address.phone,
        shipping_firstname=shipping_address.firstname,
        shipping_lastname=shipping_address.lastname,
        shipping_company_name=shipping_address.company_name,
        shipping_line1=shipping_address.line1,
        shipping_line2=shipping_address.line2,
        shipping_city=shipping_address.city,
        shipping_state=shipping_address.state,
        shipping_code=shipping_address.zip_code,
        shipping_country=Country.objects.get(
            code=shipping_address.country.code),
        shipping_phone=shipping_address.phone,
        message=request.POST.get("message", ""),
    )

    requested_delivery_date = request.POST.get("requested_delivery_date", None)
    if requested_delivery_date is not None:
        order.requested_delivery_date = requested_delivery_date
        order.save()

    if voucher:
        voucher.mark_as_used()
        order.voucher_number = voucher_number
        order.voucher_price = voucher_price
        order.voucher_tax = voucher_tax
        order.save()

    # Copy bank account if one exists
    if customer.selected_bank_account:
        bank_account = customer.selected_bank_account
        order.account_number = bank_account.account_number
        order.bank_identification_code = bank_account.bank_identification_code
        order.bank_name = bank_account.bank_name
        order.depositor = bank_account.depositor

    order.save()

    # Copy cart items
    for cart_item in cart.get_items():
        order_item = OrderItem.objects.create(
            order=order,
            price_net=cart_item.get_price_net(request),
            price_gross=cart_item.get_price_gross(request),
            tax=cart_item.get_tax(request),
            product=cart_item.product,
            product_sku=cart_item.product.sku,
            product_name=cart_item.product.get_name(),
            product_amount=cart_item.amount,
            product_price_net=cart_item.product.get_price_net(request),
            product_price_gross=cart_item.get_product_price_gross(request),
            product_tax=cart_item.product.get_tax(request),
        )

        cart_item.product.decrease_stock_amount(cart_item.amount)

        # Copy properties to order
        if cart_item.product.is_configurable_product():
            for cpv in cart_item.properties.all():
                OrderItemPropertyValue.objects.create(order_item=order_item,
                                                      property=cpv.property,
                                                      value=cpv.value)

    for discount in discounts:
        OrderItem.objects.create(
            order=order,
            price_net=-discount["price_net"],
            price_gross=-discount["price_gross"],
            tax=-discount["tax"],
            product_sku=discount["sku"],
            product_name=discount["name"],
            product_amount=1,
            product_price_net=-discount["price_net"],
            product_price_gross=-discount["price_gross"],
            product_tax=-discount["tax"],
        )

    # Send signal before cart is deleted.
    order_created.send({"order": order, "cart": cart, "request": request})

    cart.delete()

    # Note: Save order for later use in thank you page. The order will be
    # removed from the session if the thank you page has been called.
    request.session["order"] = order

    ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
    try:
        order_numbers = ong.objects.get(id="order_number")
    except ong.DoesNotExist:
        order_numbers = ong.objects.create(id="order_number")

    try:
        order_numbers.init(request, order)
    except AttributeError:
        pass

    order.number = order_numbers.get_next()
    order.save()

    return order
Exemple #12
0
def add_order(request):
    """Adds an order based on current cart for the current customer.

    It assumes that the customer is prepared with all needed information. This
    is within the responsibility of the checkout form.
    """
    customer = customer_utils.get_customer(request)
    order = None

    invoice_address = customer.selected_invoice_address
    if request.POST.get("no_shipping"):
        shipping_address = customer.selected_invoice_address
    else:
        shipping_address = customer.selected_shipping_address

    cart = cart_utils.get_cart(request)
    if cart is None:
        return order

    shipping_method = shipping_utils.get_selected_shipping_method(request)
    shipping_costs = shipping_utils.get_shipping_costs(request, shipping_method)

    payment_method = payment_utils.get_selected_payment_method(request)
    payment_costs = payment_utils.get_payment_costs(request, payment_method)

    # Set email dependend on login state. An anonymous customer doesn't  have a
    # django user account, so we set the name of the invoice address to the
    # customer name.

    # Note: After this has been processed the order's customer email has an
    # email in any case. That means you can use it to send emails to the
    # customer.
    if request.user.is_authenticated():
        user = request.user
        customer_email = user.email
    else:
        user = None
        customer_email = customer.selected_invoice_address.email

    # Calculate the totals
    price = cart.get_price_gross(request) + shipping_costs["price"] + payment_costs["price"]
    tax = cart.get_tax(request) + shipping_costs["tax"] + payment_costs["tax"]

    # Discounts
    discounts = muecke.discounts.utils.get_valid_discounts(request)
    for discount in discounts:
        price = price - discount["price_gross"]
        tax = tax - discount["tax"]

    # Add voucher if one exists
    try:
        voucher_number = muecke.voucher.utils.get_current_voucher_number(request)
        voucher = Voucher.objects.get(number=voucher_number)
    except Voucher.DoesNotExist:
        voucher = None
    else:
        is_voucher_effective, voucher_message = voucher.is_effective(request, cart)
        if is_voucher_effective:
            voucher_number = voucher.number
            voucher_price = voucher.get_price_gross(request, cart)
            voucher_tax = voucher.get_tax(request, cart)

            price -= voucher_price
            tax -= voucher_tax
        else:
            voucher = None

    order = Order.objects.create(
        user=user,
        session=request.session.session_key,
        price=price,
        tax=tax,

        customer_firstname=customer.selected_invoice_address.firstname,
        customer_lastname=customer.selected_invoice_address.lastname,
        customer_email=customer_email,

        shipping_method=shipping_method,
        shipping_price=shipping_costs["price"],
        shipping_tax=shipping_costs["tax"],
        payment_method=payment_method,
        payment_price=payment_costs["price"],
        payment_tax=payment_costs["tax"],

        invoice_firstname=customer.selected_invoice_address.firstname,
        invoice_lastname=customer.selected_invoice_address.lastname,
        invoice_company_name=customer.selected_invoice_address.company_name,
        invoice_line1=invoice_address.line1,
        invoice_line2=invoice_address.line2,
        invoice_city=invoice_address.city,
        invoice_state=invoice_address.state,
        invoice_code=invoice_address.zip_code,
        invoice_country=Country.objects.get(code=invoice_address.country.code),
        invoice_phone=customer.selected_invoice_address.phone,

        shipping_firstname=shipping_address.firstname,
        shipping_lastname=shipping_address.lastname,
        shipping_company_name=shipping_address.company_name,
        shipping_line1=shipping_address.line1,
        shipping_line2=shipping_address.line2,
        shipping_city=shipping_address.city,
        shipping_state=shipping_address.state,
        shipping_code=shipping_address.zip_code,
        shipping_country=Country.objects.get(code=shipping_address.country.code),
        shipping_phone=shipping_address.phone,

        message=request.POST.get("message", ""),
    )

    requested_delivery_date = request.POST.get("requested_delivery_date", None)
    if requested_delivery_date is not None:
        order.requested_delivery_date = requested_delivery_date
        order.save()

    if voucher:
        voucher.mark_as_used()
        order.voucher_number = voucher_number
        order.voucher_price = voucher_price
        order.voucher_tax = voucher_tax
        order.save()

    # Copy bank account if one exists
    if customer.selected_bank_account:
        bank_account = customer.selected_bank_account
        order.account_number = bank_account.account_number
        order.bank_identification_code = bank_account.bank_identification_code
        order.bank_name = bank_account.bank_name
        order.depositor = bank_account.depositor

    order.save()

    # Copy cart items
    for cart_item in cart.get_items():
        order_item = OrderItem.objects.create(
            order=order,

            price_net=cart_item.get_price_net(request),
            price_gross=cart_item.get_price_gross(request),
            tax=cart_item.get_tax(request),

            product=cart_item.product,
            product_sku=cart_item.product.sku,
            product_name=cart_item.product.get_name(),
            product_amount=cart_item.amount,
            product_price_net=cart_item.product.get_price_net(request),
            product_price_gross=cart_item.get_product_price_gross(request),
            product_tax=cart_item.product.get_tax(request),
        )

        cart_item.product.decrease_stock_amount(cart_item.amount)

        # Copy properties to order
        if cart_item.product.is_configurable_product():
            for cpv in cart_item.properties.all():
                OrderItemPropertyValue.objects.create(
                    order_item=order_item, property=cpv.property, value=cpv.value)

    for discount in discounts:
        OrderItem.objects.create(
            order=order,
            price_net=-discount["price_net"],
            price_gross=-discount["price_gross"],
            tax=-discount["tax"],
            product_sku=discount["sku"],
            product_name=discount["name"],
            product_amount=1,
            product_price_net=-discount["price_net"],
            product_price_gross=-discount["price_gross"],
            product_tax=-discount["tax"],
        )

    # Send signal before cart is deleted.
    order_created.send({"order":order, "cart": cart, "request": request})

    cart.delete()

    # Note: Save order for later use in thank you page. The order will be
    # removed from the session if the thank you page has been called.
    request.session["order"] = order

    ong = import_symbol(settings.LFS_ORDER_NUMBER_GENERATOR)
    try:
        order_numbers = ong.objects.get(id="order_number")
    except ong.DoesNotExist:
        order_numbers = ong.objects.create(id="order_number")

    try:
        order_numbers.init(request, order)
    except AttributeError:
        pass

    order.number = order_numbers.get_next()
    order.save()

    return order