Пример #1
0
def delete_cart_item(request, cart_item_id):
    """
    Deletes the cart item with the given id.
    """
    muecke_get_object_or_404(CartItem, pk=cart_item_id).delete()

    cart = cart_utils.get_cart(request)
    cart_changed.send(cart, request=request)

    return HttpResponse(cart_inline(request))
Пример #2
0
def delete_cart_item(request, cart_item_id):
    """
    Deletes the cart item with the given id.
    """
    muecke_get_object_or_404(CartItem, pk=cart_item_id).delete()

    cart = cart_utils.get_cart(request)
    cart_changed.send(cart, request=request)

    return HttpResponse(cart_inline(request))
Пример #3
0
def customer_inline(request, customer_id, template_name="manage/customer/customer_inline.html"):
    """Displays customer with provided customer id.
    """
    customer_filters = request.session.get("customer-filters", {})
    customer = muecke_get_object_or_404(Customer, pk=customer_id)
    orders = Order.objects.filter(session=customer.session)

    try:
        cart = Cart.objects.get(session=customer.session)
        cart_price = cart.get_price_gross(request)
    except Cart.DoesNotExist:
        cart = None
        cart_price = None
    else:
        # Shipping
        selected_shipping_method = muecke.shipping.utils.get_selected_shipping_method(request)
        shipping_costs = muecke.shipping.utils.get_shipping_costs(request, selected_shipping_method)

        # Payment
        selected_payment_method = muecke.payment.utils.get_selected_payment_method(request)
        payment_costs = muecke.payment.utils.get_payment_costs(request, selected_payment_method)

        cart_price = cart.get_price_gross(request) + shipping_costs["price"] + payment_costs["price"]

    return render_to_string(template_name, RequestContext(request, {
        "customer": customer,
        "orders": orders,
        "cart": cart,
        "cart_price": cart_price,
    }))
Пример #4
0
def manage_product(request, product_id, template_name="manage/product/product.html"):
    """
    Displays the whole manage/edit form for the product with the passed id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    products = _get_filtered_products_for_product_view(request)
    paginator = Paginator(products, 25)
    temp = product.parent if product.is_variant() else product
    page = get_current_page(request, products, temp, 25)

    try:
        page = paginator.page(page)
    except EmptyPage:
        page = paginator.page(1)

    return render_to_response(template_name, RequestContext(request, {
        "product": product,
        "product_filters": product_filters_inline(request, page, paginator, product_id),
        "pages_inline": pages_inline(request, page, paginator, product_id),
        "product_data": product_data_form(request, product_id),
        "images": manage_images(request, product_id, as_string=True),
        "attachments": manage_attachments(request, product_id, as_string=True),
        "selectable_products": selectable_products_inline(request, page, paginator, product.id),
        "seo": manage_seo(request, product_id),
        "stock": stock(request, product_id),
        "portlets": portlets_inline(request, product),
        "properties": manage_properties(request, product_id),
        "form": ProductSubTypeForm(instance=product),
        "name_filter_value": request.session.get("product_filters", {}).get("product_name", ""),
    }))
Пример #5
0
def add_accessory_to_cart(request, product_id, quantity=1):
    """
    Adds the product with passed product_id as an accessory to the cart and
    updates the added-to-cart view.
    """
    try:
        quantity = float(quantity)
    except TypeError:
        quantity = 1

    product = muecke_get_object_or_404(Product, pk=product_id)

    session_cart_items = request.session.get("cart_items", [])
    cart = cart_utils.get_cart(request)
    cart_item = cart.add(product=product, amount=quantity)

    # Update session
    if cart_item not in session_cart_items:
        session_cart_items.append(cart_item)
    else:
        for session_cart_item in session_cart_items:
            if cart_item.product == session_cart_item.product:
                session_cart_item.amount += quantity

    request.session["cart_items"] = session_cart_items

    cart_changed.send(cart, request=request)
    return HttpResponse(added_to_cart_items(request))
Пример #6
0
def add_accessory_to_cart(request, product_id, quantity=1):
    """
    Adds the product with passed product_id as an accessory to the cart and
    updates the added-to-cart view.
    """
    try:
        quantity = float(quantity)
    except TypeError:
        quantity = 1

    product = muecke_get_object_or_404(Product, pk=product_id)

    session_cart_items = request.session.get("cart_items", [])
    cart = cart_utils.get_cart(request)
    cart_item = cart.add(product=product, amount=quantity)

    # Update session
    if cart_item not in session_cart_items:
        session_cart_items.append(cart_item)
    else:
        for session_cart_item in session_cart_items:
            if cart_item.product == session_cart_item.product:
                session_cart_item.amount += quantity

    request.session["cart_items"] = session_cart_items

    cart_changed.send(cart, request=request)
    return HttpResponse(added_to_cart_items(request))
Пример #7
0
def remove_products(request, group_id):
    """Remove products from given property group with given property_group_id.
    """
    property_group = muecke_get_object_or_404(PropertyGroup, pk=group_id)

    for temp_id in request.POST.keys():
        if temp_id.startswith("product"):
            temp_id = temp_id.split("-")[1]
            product = Product.objects.get(pk=temp_id)
            property_group.products.remove(product)

            # Notify removing
            product_removed_property_group.send([property_group, product])

    html = [[
        "#products-inline",
        products_inline(request, group_id, as_string=True)
    ]]
    result = simplejson.dumps(
        {
            "html": html,
            "message": _(u"Products have been removed.")
        },
        cls=LazyEncoder)

    return HttpResponse(result)
Пример #8
0
def selectable_customers_inline(
        request,
        customer_id,
        template_name="manage/customer/selectable_customers_inline.html"):
    """Display selectable customers.
    """
    AMOUNT = 30
    customer = muecke_get_object_or_404(Customer, pk=customer_id)
    customer_filters = request.session.get("customer-filters", {})
    customers = _get_filtered_customers(request, customer_filters)

    page = get_current_page(request, customers, customer, AMOUNT)
    paginator = Paginator(customers, AMOUNT)

    try:
        page = paginator.page(page)
    except EmptyPage:
        page = paginator.page(1)

    return render_to_string(
        template_name,
        RequestContext(
            request, {
                "paginator": paginator,
                "page": page,
                "customer_id": int(customer_id),
            }))
Пример #9
0
def category_view(request, category_id, template_name="manage/category/view.html"):
    """Displays the view data for the category with passed category id.

    This is used as a part of the whole category form.
    """
    category = muecke_get_object_or_404(Category, pk=category_id)

    if request.method == "POST":
        form = ViewForm(instance=category, data=request.POST)
        if form.is_valid():
            form.save()
            message = _(u"View data has been saved.")
        else:
            message = _(u"Please correct the indicated errors.")
    else:
        form = ViewForm(instance=category)

    view_html = render_to_string(template_name, RequestContext(request, {
        "category": category,
        "form": form,
    }))

    if request.is_ajax():
        html = [["#view", view_html]]
        return HttpResponse(simplejson.dumps({
            "html": html,
            "message": message,
        }, cls=LazyEncoder))
    else:
        return view_html
Пример #10
0
    def get(self, request, id):
        """ Handle GET request
        """
        obj = muecke_get_object_or_404(self.model_klass, pk=id)

        form = self.form_klass(instance=obj)
        return self.render_to_response(form)
Пример #11
0
def cart_inline(request, cart_id, template_name="manage/cart/cart_inline.html"):
    """Displays cart with provided cart id.
    """
    cart = muecke_get_object_or_404(Cart, pk=cart_id)

    total = 0
    for item in cart.get_items():
        total += item.get_price_gross(request)

    try:
        if cart.user:
            customer = Customer.objects.get(user=cart.user)
        else:
            customer = Customer.objects.get(session=cart.session)
    except Customer.DoesNotExist:
        customer = None

    cart_filters = request.session.get("cart-filters", {})
    return render_to_string(template_name, RequestContext(request, {
        "cart": cart,
        "customer": customer,
        "total": total,
        "start": cart_filters.get("start", ""),
        "end": cart_filters.get("end", ""),
    }))
Пример #12
0
def popup_view(request, slug, template_name="muecke/page/popup.html"):
    """Displays page with passed slug
    """
    page = muecke_get_object_or_404(Page, slug=slug)

    return render_to_response(template_name,
                              RequestContext(request, {"page": page}))
Пример #13
0
 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)
Пример #14
0
def edit_seo(request, category_id, template_name="manage/category/seo.html"):
    """Displays an edit form for category seo fields and saves the entered
    values.

    If it is called by an ajax request it returns the result and a status
    message as json.

    This is used as a part of the whole category form.
    """
    category = muecke_get_object_or_404(Category, pk=category_id)

    if request.method == "POST":
        form = SEOForm(instance=category, data=request.POST)
        if form.is_valid():
            form.save()
            message = _(u"SEO data has been saved.")
        else:
            message = _(u"Please correct the indicated errors.")
    else:
        form = SEOForm(instance=category)

    seo_html = render_to_string(template_name, RequestContext(request, {
        "category": category,
        "form": form,
    }))

    if request.is_ajax():
        return HttpResponse(simplejson.dumps({
            "seo": seo_html,
            "message": message,
        }, cls=LazyEncoder))
    else:
        return seo_html
Пример #15
0
 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)
Пример #16
0
    def as_html(self, request, position):
        """Renders the criterion as html in order to be displayed within several
        forms.
        """
        shop = muecke_get_object_or_404(Shop, pk=1)

        countries = []
        for country in shop.shipping_countries.all():
            if country in self.countries.all():
                selected = True
            else:
                selected = False

            countries.append({
                "id": country.id,
                "name": country.name,
                "selected": selected,
            })

        return render_to_string(
            "manage/criteria/country_criterion.html",
            RequestContext(
                request, {
                    "id": "%s%s" % (self.content_type, self.id),
                    "operator": self.operator,
                    "value": self.value,
                    "position": position,
                    "countries": countries,
                }))
Пример #17
0
def change_criterion_form(request):
    """Changes the changed criterion form to the given type (via request body)
    form.

    This is called via an AJAX request. The result is injected into the right
    DOM node.
    """
    shop = muecke_get_object_or_404(Shop, pk=1)
    countries = shop.shipping_countries.all()

    type = request.POST.get("type", "price")
    template_name = "manage/criteria/%s_criterion.html" % type

    # create a (pseudo) unique id for the the new criterion form fields. This
    # are the seconds since Epoch
    now = datetime.now()
    return HttpResponse(
        render_to_string(
            template_name,
            RequestContext(
                request, {
                    "id": "%s%s" % (now.strftime("%s"), now.microsecond),
                    "countries": countries,
                    "payment_methods":
                    PaymentMethod.objects.filter(active=True),
                    "shipping_methods":
                    ShippingMethod.objects.filter(active=True),
                })))
Пример #18
0
    def as_html(self, request, position):
        """Renders the criterion as html in order to be displayed within several
        forms.
        """
        shop = muecke_get_object_or_404(Shop, pk=1)

        countries = []
        for country in shop.shipping_countries.all():
            if country in self.countries.all():
                selected = True
            else:
                selected = False

            countries.append({
                "id": country.id,
                "name": country.name,
                "selected": selected,
            })

        return render_to_string("manage/criteria/country_criterion.html", RequestContext(request, {
            "id": "%s%s" % (self.content_type, self.id),
            "operator": self.operator,
            "value": self.value,
            "position": position,
            "countries": countries,
        }))
Пример #19
0
def order_filters_inline(
        request,
        order_id,
        template_name="manage/order/order_filters_inline.html"):
    """Renders the filters section within the order view.
    """
    order_filters = request.session.get("order-filters", {})
    order = muecke_get_object_or_404(Order, pk=order_id)

    states = []
    state_id = order_filters.get("state")
    for state in muecke.order.settings.ORDER_STATES:
        states.append({
            "id": state[0],
            "name": state[1],
            "selected_filter": state_id == str(state[0]),
            "selected_order": order.state == state[0],
        })

    return render_to_string(
        template_name,
        RequestContext(
            request, {
                "current_order": order,
                "start": order_filters.get("start", ""),
                "end": order_filters.get("end", ""),
                "name": order_filters.get("name", ""),
                "states": states,
            }))
Пример #20
0
    def get(self, request, id):
        """ Handle GET request
        """
        obj = muecke_get_object_or_404(self.model_klass, pk=id)

        form = self.form_klass(instance=obj)
        return self.render_to_response(form)
Пример #21
0
def selectable_orders_inline(
        request,
        order_id,
        template_name="manage/order/selectable_orders_inline.html"):
    """Displays the selectable orders for the order view. (Used to switch
    quickly from one order to another.)
    """
    order = muecke_get_object_or_404(Order, pk=order_id)

    order_filters = request.session.get("order-filters", {})
    orders = _get_filtered_orders(order_filters)

    paginator = Paginator(orders, 20)

    try:
        page = int(request.REQUEST.get("page", 1))
    except TypeError:
        page = 1
    page = paginator.page(page)

    return render_to_string(
        template_name,
        RequestContext(
            request, {
                "current_order": order,
                "orders": orders,
                "paginator": paginator,
                "page": page,
            }))
Пример #22
0
def manage_categories(request, product_id, template_name="manage/product/categories.html"):
    """Displays the manage category view.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    product_category_ids = [p.id for p in product.get_categories()]

    categories = []
    for category in Category.objects.filter(parent=None):

        children = children_categories(request, category, product_category_ids)

        categories.append({
            "id": category.id,
            "slug": category.slug,
            "name": category.name,
            "url": category.get_absolute_url(),
            "checked": category.id in product_category_ids,
            "children": children,
        })

    result = render_to_string(template_name, RequestContext(request, {
        "product": product,
        "categories": categories
    }))

    return HttpResponse(result)
Пример #23
0
def order_view(request, order_id, template_name="manage/order/order.html"):
    """Displays the management interface for the order with passed order id.
    """
    order_filters = request.session.get("order-filters", {})
    order = muecke_get_object_or_404(Order, pk=order_id)

    states = []
    state_id = order_filters.get("state")
    for state in muecke.order.settings.ORDER_STATES:
        states.append({
            "id": state[0],
            "name": state[1],
            "selected_filter": state_id == str(state[0]),
            "selected_order": order.state == state[0],
        })

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "order_inline": order_inline(request, order_id),
                "order_filters_inline": order_filters_inline(
                    request, order_id),
                "selectable_orders": selectable_orders_inline(
                    request, order_id),
                "current_order": order,
                "states": states,
            }))
Пример #24
0
def product_form_dispatcher(request):
    """Dispatches to the added-to-cart view or to the selected variant.

    This is needed as the product form can have several submit buttons:
       - The add-to-cart button
       - The switch to the selected variant button (only in the case the
         variants of of the product are displayed as select box. This may change
         in future, when the switch may made with an ajax request.)
    """
    if request.REQUEST.get("add-to-cart") is not None:
        return add_to_cart(request)
    else:
        product_id = request.POST.get("product_id")
        product = muecke_get_object_or_404(Product, pk=product_id)

        options = muecke_utils.parse_properties(request)
        variant = product.get_variant(options)

        if variant is None:
            variant = product.get_default_variant()

            return muecke.core.utils.set_message_cookie(
                variant.get_absolute_url(),
                msg=_(u"The choosen combination of properties is not deliverable.")
            )

        return HttpResponseRedirect(variant.get_absolute_url())
Пример #25
0
def popup_view(request, slug, template_name="muecke/page/popup.html"):
    """Displays page with passed slug
    """
    page = muecke_get_object_or_404(Page, slug=slug)

    return render_to_response(template_name, RequestContext(request, {
        "page": page
    }))
Пример #26
0
def file(request, language=None, id=None):
    """Delivers files to the browser.
    """
    file = muecke_get_object_or_404(File, pk=id)
    response = HttpResponse(file.file, mimetype='application/binary')
    response['Content-Disposition'] = 'attachment; filename=%s' % file.title

    return response
Пример #27
0
def delete_product(request, product_id):
    """Deletes product with passed id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    product.delete()

    url = reverse("muecke_manage_product_dispatcher")
    return HttpResponseRedirect(url)
Пример #28
0
def delete_product(request, product_id):
    """Deletes product with passed id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    product.delete()

    url = reverse("muecke_manage_product_dispatcher")
    return HttpResponseRedirect(url)
Пример #29
0
def shop_view(request, template_name="muecke/shop/shop.html"):
    """Displays the shop.
    """
    shop = muecke_get_object_or_404(Shop, pk=1)

    return render_to_response(template_name, RequestContext(request, {
        "shop": shop
    }))
Пример #30
0
def page_view_by_id(request, id, template_name="muecke/page/page.html"):
    """Displays page with passed id.
    """
    if id == 1:
        raise Http404()

    page = muecke_get_object_or_404(Page, pk=id)
    url = reverse("muecke_page_view", kwargs={"slug": page.slug})
    return HttpResponseRedirect(url)
Пример #31
0
def page_view_by_id(request, id, template_name="muecke/page/page.html"):
    """Displays page with passed id.
    """
    if id == 1:
        raise Http404()

    page = muecke_get_object_or_404(Page, pk=id)
    url = reverse("muecke_page_view", kwargs={"slug": page.slug})
    return HttpResponseRedirect(url)
Пример #32
0
def send_order(request, order_id):
    """Sends order with passed order id to the customer of this order.
    """
    order = muecke_get_object_or_404(Order, pk=order_id)
    mail_utils.send_order_received_mail(order)

    return muecke.core.utils.set_message_cookie(
        url=reverse("muecke_manage_order", kwargs={"order_id": order.id}),
        msg=_(u"Order has been sent."),
    )
Пример #33
0
    def post(self, request, id):
        """ Handle POST request
        """
        obj = muecke_get_object_or_404(self.model_klass, pk=id)

        form = self.form_klass(instance=obj, data=request.POST)
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Пример #34
0
    def post(self, request, id):
        """ Handle POST request
        """
        obj = muecke_get_object_or_404(self.model_klass, pk=id)

        form = self.form_klass(instance=obj, data=request.POST)
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Пример #35
0
def delete_category(request, id):
    """Deletes category with given id.
    """
    category = muecke_get_object_or_404(Category, pk=id)
    parent = category.parent
    category.delete()
    manage_utils.update_category_positions(parent)

    url = reverse("muecke_manage_categories")
    return HttpResponseRedirect(url)
Пример #36
0
def customer_filters_inline(request, customer_id, template_name="manage/customer/customer_filters_inline.html"):
    """Renders the filters section of the customer view.
    """
    customer_filters = request.session.get("customer-filters", {})
    customer = muecke_get_object_or_404(Customer, pk=customer_id)

    return render_to_string(template_name, RequestContext(request, {
        "customer": customer,
        "name": customer_filters.get("name", ""),
    }))
Пример #37
0
def send_order(request, order_id):
    """Sends order with passed order id to the customer of this order.
    """
    order = muecke_get_object_or_404(Order, pk=order_id)
    mail_utils.send_order_received_mail(order)

    return muecke.core.utils.set_message_cookie(
        url=reverse("muecke_manage_order", kwargs={"order_id": order.id}),
        msg=_(u"Order has been sent."),
    )
Пример #38
0
def update_images(request, product_id):
    """Saves/deletes images with given ids (passed by request body).
    """
    product = muecke_get_object_or_404(Product, pk=product_id)

    action = request.POST.get("action")
    if action == "delete":
        message = _(u"Images has been deleted.")
        for key in request.POST.keys():
            if key.startswith("delete-"):
                try:
                    id = key.split("-")[1]
                    image = Image.objects.get(pk=id).delete()
                except (IndexError, ObjectDoesNotExist):
                    pass

    elif action == "update":
        message = _(u"Images has been updated.")
        for key, value in request.POST.items():
            if key.startswith("title-"):
                id = key.split("-")[1]
                try:
                    image = Image.objects.get(pk=id)
                except ObjectDoesNotExist:
                    pass
                else:
                    image.title = value
                    image.save()

            elif key.startswith("position-"):
                try:
                    id = key.split("-")[1]
                    image = Image.objects.get(pk=id)
                except (IndexError, ObjectDoesNotExist):
                    pass
                else:
                    image.position = value
                    image.save()

    # Refresh positions
    for i, image in enumerate(product.images.all()):
        image.position = (i + 1) * 10
        image.save()

    product_changed.send(product, request=request)

    html = [["#images", manage_images(request, product_id, as_string=True)]]
    result = simplejson.dumps({
        "html": html,
        "message": message,
    },
                              cls=LazyEncoder)

    return HttpResponse(result)
Пример #39
0
def review_filters_inline(request, review_id, template_name="manage/reviews/review_filters_inline.html"):
    """Renders the filter section of the review view.
    """
    review_filters = request.session.get("review-filters", {})
    review = muecke_get_object_or_404(Review, pk=review_id)

    return render_to_string(template_name, RequestContext(request, {
        "review": review,
        "name": review_filters.get("name", ""),
        "active": review_filters.get("active", ""),
    }))
Пример #40
0
def cart_filters_inline(request, cart_id, template_name="manage/cart/cart_filters_inline.html"):
    """Renders the filters section of the cart view.
    """
    cart = muecke_get_object_or_404(Cart, pk=cart_id)
    cart_filters = request.session.get("cart-filters", {})

    return render_to_string(template_name, RequestContext(request, {
        "cart": cart,
        "start": cart_filters.get("start", ""),
        "end": cart_filters.get("end", ""),
    }))
Пример #41
0
def review(request, review_id, template_name="manage/reviews/review.html"):
    """Displays review with provided review id.
    """
    review = muecke_get_object_or_404(Review, pk=review_id)

    return render_to_response(template_name, RequestContext(request, {
        "review_inline": review_inline(request, review_id),
        "review_filters_inline": review_filters_inline(request, review_id),
        "selectable_reviews_inline": selectable_reviews_inline(request, review_id),
        "review": review,
    }))
Пример #42
0
def page_view(request, slug, template_name="muecke/page/page.html"):
    """Displays page with passed slug
    """
    page = muecke_get_object_or_404(Page, slug=slug)
    if page.id == 1:
        raise Http404()

    if request.user.is_superuser or page.active:
        return render_to_response(template_name,
                                  RequestContext(request, {"page": page}))

    raise Http404('No Page matches the given query.')
Пример #43
0
def update_files(request, id):
    """
    """
    static_block = muecke_get_object_or_404(StaticBlock, pk=id)

    action = request.POST.get("action")
    if action == "delete":
        message = _(u"Files has been deleted.")
        for key in request.POST.keys():
            if key.startswith("delete-"):
                try:
                    id = key.split("-")[1]
                    file = File.objects.get(pk=id).delete()
                except (IndexError, ObjectDoesNotExist):
                    pass

    elif action == "update":
        message = _(u"Files has been updated.")
        for key, value in request.POST.items():
            if key.startswith("title-"):
                id = key.split("-")[1]
                try:
                    file = File.objects.get(pk=id)
                except File.ObjectDoesNotExist:
                    pass
                else:
                    file.title = value
                    file.save()

            elif key.startswith("position-"):
                try:
                    id = key.split("-")[1]
                    file = File.objects.get(pk=id)
                except (IndexError, ObjectDoesNotExist):
                    pass
                else:
                    file.position = value
                    file.save()

    for i, file in enumerate(static_block.files.all()):
        file.position = (i + 1) * 10
        file.save()

    html = (
        ("#files", files(request, static_block)),
    )

    result = simplejson.dumps({
        "html": html,
        "message": message,
    }, cls=LazyEncoder)

    return HttpResponse(result)
Пример #44
0
def reload_files(request, id):
    """
    """
    static_block = muecke_get_object_or_404(StaticBlock, pk=id)
    result = files(request, static_block)

    result = simplejson.dumps({
        "files": result,
        "message": _(u"Files has been added."),
    }, cls=LazyEncoder)

    return HttpResponse(result)
Пример #45
0
def update_images(request, product_id):
    """Saves/deletes images with given ids (passed by request body).
    """
    product = muecke_get_object_or_404(Product, pk=product_id)

    action = request.POST.get("action")
    if action == "delete":
        message = _(u"Images has been deleted.")
        for key in request.POST.keys():
            if key.startswith("delete-"):
                try:
                    id = key.split("-")[1]
                    image = Image.objects.get(pk=id).delete()
                except (IndexError, ObjectDoesNotExist):
                    pass

    elif action == "update":
        message = _(u"Images has been updated.")
        for key, value in request.POST.items():
            if key.startswith("title-"):
                id = key.split("-")[1]
                try:
                    image = Image.objects.get(pk=id)
                except ObjectDoesNotExist:
                    pass
                else:
                    image.title = value
                    image.save()

            elif key.startswith("position-"):
                try:
                    id = key.split("-")[1]
                    image = Image.objects.get(pk=id)
                except (IndexError, ObjectDoesNotExist):
                    pass
                else:
                    image.position = value
                    image.save()

    # Refresh positions
    for i, image in enumerate(product.images.all()):
        image.position = (i + 1) * 10
        image.save()

    product_changed.send(product, request=request)

    html = [["#images", manage_images(request, product_id, as_string=True)]]
    result = simplejson.dumps({
        "html": html,
        "message": message,
    }, cls=LazyEncoder)

    return HttpResponse(result)
Пример #46
0
def add_image(request, product_id):
    """Adds an image to product with passed product_id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    if request.method == "POST":
        for file_content in request.FILES.getlist("file"):
            image = Image(content=product, title=file_content.name)
            try:
                image.image.save(file_content.name, file_content, save=True)
            except Exception, e:
                logger.info("Upload image: %s %s" % (file_content.name, e))
                continue
Пример #47
0
def add_image(request, product_id):
    """Adds an image to product with passed product_id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    if request.method == "POST":
        for file_content in request.FILES.getlist("file"):
            image = Image(content=product, title=file_content.name)
            try:
                image.image.save(file_content.name, file_content, save=True)
            except Exception, e:
                logger.info("Upload image: %s %s" % (file_content.name, e))
                continue
Пример #48
0
def update_files(request, id):
    """
    """
    static_block = muecke_get_object_or_404(StaticBlock, pk=id)

    action = request.POST.get("action")
    if action == "delete":
        message = _(u"Files has been deleted.")
        for key in request.POST.keys():
            if key.startswith("delete-"):
                try:
                    id = key.split("-")[1]
                    file = File.objects.get(pk=id).delete()
                except (IndexError, ObjectDoesNotExist):
                    pass

    elif action == "update":
        message = _(u"Files has been updated.")
        for key, value in request.POST.items():
            if key.startswith("title-"):
                id = key.split("-")[1]
                try:
                    file = File.objects.get(pk=id)
                except File.ObjectDoesNotExist:
                    pass
                else:
                    file.title = value
                    file.save()

            elif key.startswith("position-"):
                try:
                    id = key.split("-")[1]
                    file = File.objects.get(pk=id)
                except (IndexError, ObjectDoesNotExist):
                    pass
                else:
                    file.position = value
                    file.save()

    for i, file in enumerate(static_block.files.all()):
        file.position = (i + 1) * 10
        file.save()

    html = (("#files", files(request, static_block)), )

    result = simplejson.dumps({
        "html": html,
        "message": message,
    },
                              cls=LazyEncoder)

    return HttpResponse(result)
Пример #49
0
def delete_order(request, order_id):
    """Deletes order with provided order id.
    """
    order = muecke_get_object_or_404(Order, pk=order_id)
    order.delete()

    try:
        order = Order.objects.all()[0]
        url = reverse("muecke_manage_order", kwargs={"order_id": order.id})
    except IndexError:
        url = reverse("muecke_manage_orders")

    return HttpResponseRedirect(url)
Пример #50
0
def page_view(request, slug, template_name="muecke/page/page.html"):
    """Displays page with passed slug
    """
    page = muecke_get_object_or_404(Page, slug=slug)
    if page.id == 1:
        raise Http404()

    if request.user.is_superuser or page.active:
        return render_to_response(template_name, RequestContext(request, {
            "page": page
        }))

    raise Http404('No Page matches the given query.')
Пример #51
0
def delete_order(request, order_id):
    """Deletes order with provided order id.
    """
    order = muecke_get_object_or_404(Order, pk=order_id)
    order.delete()

    try:
        order = Order.objects.all()[0]
        url = reverse("muecke_manage_order", kwargs={"order_id": order.id})
    except IndexError:
        url = reverse("muecke_manage_orders")

    return HttpResponseRedirect(url)
Пример #52
0
def manage_product(request,
                   product_id,
                   template_name="manage/product/product.html"):
    """
    Displays the whole manage/edit form for the product with the passed id.
    """
    product = muecke_get_object_or_404(Product, pk=product_id)
    products = _get_filtered_products_for_product_view(request)
    paginator = Paginator(products, 25)
    temp = product.parent if product.is_variant() else product
    page = get_current_page(request, products, temp, 25)

    try:
        page = paginator.page(page)
    except EmptyPage:
        page = paginator.page(1)

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "product":
                product,
                "product_filters":
                product_filters_inline(request, page, paginator, product_id),
                "pages_inline":
                pages_inline(request, page, paginator, product_id),
                "product_data":
                product_data_form(request, product_id),
                "images":
                manage_images(request, product_id, as_string=True),
                "attachments":
                manage_attachments(request, product_id, as_string=True),
                "selectable_products":
                selectable_products_inline(request, page, paginator,
                                           product.id),
                "seo":
                manage_seo(request, product_id),
                "stock":
                stock(request, product_id),
                "portlets":
                portlets_inline(request, product),
                "properties":
                manage_properties(request, product_id),
                "form":
                ProductSubTypeForm(instance=product),
                "name_filter_value":
                request.session.get("product_filters", {}).get(
                    "product_name", ""),
            }))
Пример #53
0
def reload_files(request, id):
    """
    """
    static_block = muecke_get_object_or_404(StaticBlock, pk=id)
    result = files(request, static_block)

    result = simplejson.dumps(
        {
            "files": result,
            "message": _(u"Files has been added."),
        },
        cls=LazyEncoder)

    return HttpResponse(result)