Exemplo n.º 1
0
 def auction_history(cls, request):
     # DZIALA - aukcje które założył użyszkodnik
     current_user = ShopUser.objects.get(user__pk=request.user.pk)
     list = AuctionItem.objects.filter(created_by__pk=current_user.pk)
     return render_to_response("auctionitem_list.html",
                               {'items': list, 'search_form': SearchForm(),
                                'categories': BaseView.get_categories()},
                               context_instance=RequestContext(request))
Exemplo n.º 2
0
 def auction_history(cls, request):
     # DZIALA - aukcje które założył użyszkodnik
     current_user = ShopUser.objects.get(user__pk=request.user.pk)
     list = AuctionItem.objects.filter(created_by__pk=current_user.pk)
     return render_to_response("auctionitem_list.html", {
         'items': list,
         'search_form': SearchForm(),
         'categories': BaseView.get_categories()
     },
                               context_instance=RequestContext(request))
Exemplo n.º 3
0
    def shopping_cart(cls, request):
        # DZIALA
        current_user = request.user
        #raise Http404(current_user)
        current_user = ShopUser.objects.get(user__pk=current_user.pk)

        # if ShoppingCart.objects.get(user=current_user):
        try:
            cart = ShoppingCart.objects.get_or_create(
                user__pk=current_user.pk)[0]
        except Exception:
            cart = ShoppingCart.objects.create(user=current_user)
            cart.save()

        cart_items = []
        formset_data = []

        for item in cart.items.all():
            try:
                concrete = EShopItem.objects.get(base__pk=item.item.pk)
                cart_items.append(
                    CartItem(base=item.item,
                             concrete=concrete,
                             type="eshop",
                             quantity=item.quantity))
            except EShopItem.DoesNotExist:
                concrete = GroupOffer.objects.get(base__pk=item.item.pk)
                cart_items.append(
                    CartItem(base=item.item,
                             concrete=concrete,
                             type="group",
                             quantity=item.quantity))

            formset_data.append({"quantity": item.quantity})

        formset = CartFormset(initial=formset_data)
        data = zip(cart_items, formset)

        total = sum([
            float(item.concrete.price * item.quantity) for item in cart_items
        ])
        total = "%.2f" % total

        return render_to_response("shopping_cart.html", {
            'cart': cart,
            'search_form': SearchForm(),
            "data": data,
            'categories': BaseView.get_categories(),
            'total': total,
            'formset': formset
        },
                                  context_instance=RequestContext(request))
Exemplo n.º 4
0
    def shopping_cart(cls, request):
        # DZIALA
        current_user = request.user
        #raise Http404(current_user)
        current_user = ShopUser.objects.get(user__pk=current_user.pk)

        # if ShoppingCart.objects.get(user=current_user):
        try:
            cart = ShoppingCart.objects.get_or_create(
                user__pk=current_user.pk)[0]
        except Exception:
            cart = ShoppingCart.objects.create(user=current_user)
            cart.save()

        cart_items = []
        formset_data = []

        for item in cart.items.all():
            try:
                concrete = EShopItem.objects.get(base__pk=item.item.pk)
                cart_items.append(CartItem(base=item.item, concrete=concrete,
                                           type="eshop", quantity=item.quantity))
            except EShopItem.DoesNotExist:
                concrete = GroupOffer.objects.get(base__pk=item.item.pk)
                cart_items.append(CartItem(base=item.item, concrete=concrete,
                                           type="group", quantity=item.quantity))

            formset_data.append({"quantity": item.quantity})

        formset = CartFormset(initial=formset_data)
        data = zip(cart_items, formset)

        total = sum([float(item.concrete.price * item.quantity)
                    for item in cart_items])
        total = "%.2f" % total

        return render_to_response("shopping_cart.html",
                                  {'cart': cart, 'search_form': SearchForm(), "data": data,
                                   'categories': BaseView.get_categories(), 'total': total,
                                   'formset': formset},
                                  context_instance=RequestContext(request))
Exemplo n.º 5
0
    def checkout(cls, request):
        data = {
            'search_form': SearchForm(), 'categories': BaseView.get_categories()}
        cart = ShoppingCart.objects.get(user__user__pk=request.user.pk)
        if request.method == "POST":
            order_form = OrderForm(request.POST)
            if order_form.is_valid():
                order = Order()

                order.placed_by = ShopUser.objects.get(
                    user__pk=request.user.pk)
                order.status = OrderStatus.objects.get(name="przyjete")
                order.shipment_method = order_form.cleaned_data[
                    "shipment_method"]
                order.details = order_form.cleaned_data["details"]
                order.save()

                for item in cart.items.all():
                    try:
                        offer = GroupOffer.objects.get(base__pk=item.pk)
                        offer.buyers.add(order.placed_by)
                        offer.save()
                    except Exception:
                        pass
                    order.items.add(item)

                user = ShopUser.objects.get(user__pk=request.user.pk)
                total = 0
                html_mail_content = '<p>Witaj' + user.user.first_name + ' ' + user.user.last_name + '</p>' + '<p>Potwierdzamy przyjęcie zamówienia nr ' + \
                    str(order.pk) + '<p>' + \
                    '<p>Szczegóły zamówienia<p><table border="1" rules="typ"><tr><td>Nazwa</td><td>ilość</td><td>cena</td></tr>'
                for item in order.items.all():
                    shop_item = EShopItem.objects.get(base__pk=item.item.pk)
                    html_mail_content = html_mail_content + '<tr><td>' + \
                        str(item.item.name) + '</td><td>' + str(
                            item.quantity) + '</td><td>' + str(shop_item.price) + '</td></tr>'
                    total = total + item.quantity * shop_item.price
                html_mail_content = html_mail_content + '</table></br>' + '<p>Razem: ' + \
                    str(total) + '</p>' + '<p>Adres do wysyłki:</p>' + \
                    user.address + \
                    '<p>Z poważaniem </br> Ekipa UberShop</p>'

                # Wysylka maila z potwierdzeniem
                try:
                    mandrill_client = mandrill.Mandrill(
                        'x03KMKaNVHHoV3g0APQt4g')
                    message = {'to': [{'email': user.user.email,
                                       'name': user.user.first_name + ' ' + user.user.last_name,
                                       'type': 'to'}],
                               #'bcc_address':'*****@*****.**',
                               'from_email': '*****@*****.**',
                               'from_name': 'Ubershop',
                               'subject': 'Potwierdzenie zamówienia numer ' + str(order.pk),
                               'headers': {'Reply-To': '*****@*****.**'},
                               'html': html_mail_content,
                               }
                    result = mandrill_client.messages.send(
                        message=message, async=False)
                except mandrill.Error, e:
                    return render_to_response(
                        "error.html", {
                            "search_form": SearchForm(), "categories": BaseView.get_categories()},
                        context_instance=RequestContext(request))

                dummy=ShopUser.objects.get(user__username='******')#na chama
                for item in order.items.all():
                    item.belongs_to=dummy
                    item.save()

                cart.items.clear()

                cart.save()
                order.save()

                return render_to_response(
                    "thankyou.html", {
                        "search_form": SearchForm(), "categories": BaseView.get_categories()},
                    context_instance=RequestContext(request))
            data["order_form"] = order_form
            return render_to_response("checkout.html", data,
                                      context_instance=RequestContext(request))
Exemplo n.º 6
0
from django.conf.urls import patterns, include, url
from django.contrib import admin

from base.views import BaseView

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'valres.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', BaseView.as_view()),
)
Exemplo n.º 7
0
    def checkout(cls, request):
        data = {
            'search_form': SearchForm(),
            'categories': BaseView.get_categories()
        }
        cart = ShoppingCart.objects.get(user__user__pk=request.user.pk)
        if request.method == "POST":
            order_form = OrderForm(request.POST)
            if order_form.is_valid():
                order = Order()

                order.placed_by = ShopUser.objects.get(
                    user__pk=request.user.pk)
                order.status = OrderStatus.objects.get(name="przyjete")
                order.shipment_method = order_form.cleaned_data[
                    "shipment_method"]
                order.details = order_form.cleaned_data["details"]
                order.save()

                for item in cart.items.all():
                    try:
                        offer = GroupOffer.objects.get(base__pk=item.pk)
                        offer.buyers.add(order.placed_by)
                        offer.save()
                    except Exception:
                        pass
                    order.items.add(item)

                user = ShopUser.objects.get(user__pk=request.user.pk)
                total = 0
                html_mail_content = '<p>Witaj' + user.user.first_name + ' ' + user.user.last_name + '</p>' + '<p>Potwierdzamy przyjęcie zamówienia nr ' + \
                    str(order.pk) + '<p>' + \
                    '<p>Szczegóły zamówienia<p><table border="1" rules="typ"><tr><td>Nazwa</td><td>ilość</td><td>cena</td></tr>'
                for item in order.items.all():
                    shop_item = EShopItem.objects.get(base__pk=item.item.pk)
                    html_mail_content = html_mail_content + '<tr><td>' + \
                        str(item.item.name) + '</td><td>' + str(
                            item.quantity) + '</td><td>' + str(shop_item.price) + '</td></tr>'
                    total = total + item.quantity * shop_item.price
                html_mail_content = html_mail_content + '</table></br>' + '<p>Razem: ' + \
                    str(total) + '</p>' + '<p>Adres do wysyłki:</p>' + \
                    user.address + \
                    '<p>Z poważaniem </br> Ekipa UberShop</p>'

                # Wysylka maila z potwierdzeniem
                try:
                    mandrill_client = mandrill.Mandrill(
                        'x03KMKaNVHHoV3g0APQt4g')
                    message = {
                        'to': [{
                            'email': user.user.email,
                            'name':
                            user.user.first_name + ' ' + user.user.last_name,
                            'type': 'to'
                        }],
                        #'bcc_address':'*****@*****.**',
                        'from_email':
                        '*****@*****.**',
                        'from_name':
                        'Ubershop',
                        'subject':
                        'Potwierdzenie zamówienia numer ' + str(order.pk),
                        'headers': {
                            'Reply-To': '*****@*****.**'
                        },
                        'html':
                        html_mail_content,
                    }
                    result = mandrill_client.messages.send(message=message,
                                                           async=False)
                except mandrill.Error, e:
                    return render_to_response(
                        "error.html", {
                            "search_form": SearchForm(),
                            "categories": BaseView.get_categories()
                        },
                        context_instance=RequestContext(request))

                dummy = ShopUser.objects.get(user__username='******')  #na chama
                for item in order.items.all():
                    item.belongs_to = dummy
                    item.save()

                cart.items.clear()

                cart.save()
                order.save()

                return render_to_response(
                    "thankyou.html", {
                        "search_form": SearchForm(),
                        "categories": BaseView.get_categories()
                    },
                    context_instance=RequestContext(request))
            data["order_form"] = order_form
            return render_to_response("checkout.html",
                                      data,
                                      context_instance=RequestContext(request))