Beispiel #1
0
def form_view(request, pk):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        obj = Product.objects.get(id=pk)
        strategy = Selector().strategy()
        stock = strategy.fetch_for_product(obj)
        # data = {'product_quantity': obj.attr.MinQuantity}
        # create a form instance and populate it with data from the request:
        form = MyForm(request.POST, request.FILES)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            formobj = form.save(commit=False)
            formobj.product_name = obj.title
            formobj.product_supplier = stock.stockrecord.partner.name
            formobj.save()
            return HttpResponseRedirect('/thanks/')

    # if a GET (or any other method) we'll create a blank form
    else:
        obj = Product.objects.get(id=pk)
        strategy = Selector().strategy()
        stock = strategy.fetch_for_product(obj)
        data = {'product_quantity': obj.attr.MinQuantity}
        form = MyForm(initial=data)

    return render(
        request, 'partner/partner_form.html', {
            'form': form,
            'supplier_name': stock.stockrecord.partner.name,
            'product_name': obj.title
        })
Beispiel #2
0
 def get_context_data(self, **kwargs):
     ctx = {}
     ctx['summary'] = _("All products")
     search_context = self.search_handler.get_search_context_data(
         self.context_object_name)
     ctx.update(search_context)
     strategy = Selector().strategy()
     available_products = []
     for product in ctx['products']:
         info = strategy.fetch_for_product(product)
         if info.availability.is_available_to_buy:
             available_products.append(product)
     ctx['object_list'] = available_products
     ctx['products'] = available_products
     ctx['paginator'].count = len(available_products)
     return ctx
    def _update_seats(self, batch_seats, succeeded, failed):
        strategy = Selector().strategy()

        for seat in batch_seats:
            info = strategy.fetch_for_product(seat)

            try:
                course = Course.objects.get(id=seat.attr.course_key)
                course.create_or_update_seat(
                    seat.attr.certificate_type,
                    seat.attr.id_verification_required,
                    info.price.excl_tax,
                    expires=seat.expires,
                    sku=info.stockrecord.partner_sku)
                succeeded += 1
            except Exception:  # pylint: disable=broad-except
                logger.error(
                    'Could not update seat title="%s" in course_id="%s".',
                    seat.title, seat.attr.course_key)
                failed += 1

        return succeeded, failed