本文整理汇总了Python中satchmo_utils.views.bad_or_missing函数的典型用法代码示例。如果您正苦于以下问题:Python bad_or_missing函数的具体用法?Python bad_or_missing怎么用?Python bad_or_missing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bad_or_missing函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add
def add(request, id=0, redirect_to='satchmo_cart'):
"""Add an item to the cart."""
log.debug('FORM: %s', request.POST)
formdata = request.POST.copy()
productslug = None
cartplaces = config_value('SHOP', 'CART_PRECISION')
roundfactor = config_value('SHOP', 'CART_ROUNDING')
if formdata.has_key('productname'):
productslug = formdata['productname']
try:
product, details = product_from_post(productslug, formdata)
if not (product and product.active):
log.debug("product %s is not active" % productslug)
return bad_or_missing(request, _("That product is not available at the moment."))
else:
log.debug("product %s is active" % productslug)
except (Product.DoesNotExist, MultiValueDictKeyError):
log.debug("Could not find product: %s", productslug)
return bad_or_missing(request, _('The product you have requested does not exist.'))
# First we validate that the number isn't too big.
if decimal_too_big(formdata['quantity']):
return _product_error(request, product, _("Please enter a smaller number."))
# Then we validate that we can round it appropriately.
try:
quantity = round_decimal(formdata['quantity'], places=cartplaces, roundfactor=roundfactor)
except RoundedDecimalError, P:
return _product_error(request, product,
_("Invalid quantity."))
开发者ID:34,项目名称:T,代码行数:35,代码来源:cart.py
示例2: add
def add(request, id=0, redirect_to='satchmo_cart'):
"""Add an item to the cart."""
log.debug('FORM: %s', request.POST)
formdata = request.POST.copy()
productslug = None
cartplaces = config_value('SHOP', 'CART_PRECISION')
roundfactor = config_value('SHOP', 'CART_ROUNDING')
if formdata.has_key('productname'):
productslug = formdata['productname']
try:
product, details = product_from_post(productslug, formdata)
if not (product and product.active):
log.debug("product %s is not active" % productslug)
return bad_or_missing(request, _("That product is not available at the moment."))
else:
log.debug("product %s is active" % productslug)
except (Product.DoesNotExist, MultiValueDictKeyError):
log.debug("Could not find product: %s", productslug)
return bad_or_missing(request, _('The product you have requested does not exist.'))
# First we validate that the number isn't too big.
if decimal_too_big(formdata['quantity']):
return _product_error(request, product, _("Please enter a smaller number."))
# Then we validate that we can round it appropriately.
try:
quantity = round_decimal(formdata['quantity'], places=cartplaces, roundfactor=roundfactor)
except RoundedDecimalError:
return _product_error(request, product,
_("Invalid quantity."))
if quantity <= Decimal('0'):
return _product_error(request, product,
_("Please enter a positive number."))
cart = Cart.objects.from_request(request, create=True)
# send a signal so that listeners can update product details before we add it to the cart.
satchmo_cart_details_query.send(
cart,
product=product,
quantity=quantity,
details=details,
request=request,
form=formdata
)
try:
added_item = cart.add_item(product, number_added=quantity, details=details)
except CartAddProhibited, cap:
return _product_error(request, product, cap.message)
开发者ID:ThissDJ,项目名称:designhub,代码行数:55,代码来源:cart.py
示例3: category_view
def category_view(request, slug, parent_slugs='', template='product/category.html'):
"""Display the category, its child categories, and its products.
Parameters:
- slug: slug of category
- parent_slugs: ignored
"""
if request.method == "GET":
currpage = request.GET.get('page', 1)
else:
currpage = 1
try:
category = Category.objects.get_by_site(slug=slug)
products = list(category.active_products())
sale = find_best_auto_discount(products)
except Category.DoesNotExist:
return bad_or_missing(request, _('The category you have requested does not exist.'))
child_categories = category.get_all_children()
count = config_value('PRODUCT','NUM_PAGINATED')
paginator = Paginator(products, count)
try:
paginator.validate_number(currpage)
except InvalidPage:
return bad_or_missing(request, _("Invalid page number"))
page = paginator.page(currpage)
min_in_page = (count * (page.number - 1) + 1)
max_in_page = min_in_page + (len(page.object_list) - 1)
ctx = {
'category': category,
'child_categories': child_categories,
'sale': sale,
'products': page.object_list,
'page_obj': page,
'paginator': paginator,
'min_in_page': min_in_page,
'max_in_page': max_in_page
}
index_prerender.send(Product, request=request, context=ctx, category=category, object_list=products)
return render_to_response(template, context_instance=RequestContext(request, ctx))
开发者ID:tatenen,项目名称:store,代码行数:49,代码来源:views.py
示例4: success
def success(request):
"""
The order has been succesfully processed. This can be used to generate a receipt or some other confirmation
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request, _('Your order has already been processed.'))
# empty user cart
for cart in Cart.objects.filter(customer=order.contact):
cart.empty()
cart.delete()
cart = Cart.objects.from_request(request, create=False)
if isinstance(cart, NullCart):
pass
else:
cart.empty()
cart.delete()
del request.session['orderID']
context = RequestContext(request, {'order': order})
return render_to_response('shop/checkout/success.html',
context_instance=context)
开发者ID:eyeyunianto,项目名称:satchmo,代码行数:26,代码来源:views.py
示例5: home
def home(request, template="shop/index.html"):
# Display the category, its child categories, and its products.
if request.method == "GET":
currpage = request.GET.get('page', 1)
else:
currpage = 1
featured = display_featured()
count = config_value('PRODUCT','NUM_PAGINATED')
paginator = Paginator(featured, count)
is_paged = False
page = None
try:
paginator.validate_number(currpage)
except EmptyPage:
return bad_or_missing(request, _("Invalid page number"))
is_paged = paginator.num_pages > 1
page = paginator.page(currpage)
ctx = RequestContext(request, {
'all_products_list' : page.object_list,
'is_paginated' : is_paged,
'page_obj' : page,
'paginator' : paginator
})
return render_to_response(template, context_instance=ctx)
开发者ID:34,项目名称:T,代码行数:33,代码来源:home.py
示例6: category_view
def category_view(request, slug, parent_slugs='', template='product/category.html'):
"""Display the category, its child categories, and its products.
Parameters:
- slug: slug of category
- parent_slugs: ignored
"""
try:
category = Category.objects.get(slug=slug)
products = list(category.active_products())
sale = find_best_auto_discount(products)
except Category.DoesNotExist:
return bad_or_missing(request, _('The category you have requested does not exist.'))
child_categories = category.get_all_children()
ctx = {
'category': category,
'child_categories': child_categories,
'sale' : sale,
'products' : products,
}
index_prerender.send(Product, request=request, context=ctx, category=category, object_list=products)
return render_to_response(template, RequestContext(request, ctx))
开发者ID:hnejadi,项目名称:xerobis,代码行数:25,代码来源:__init__.py
示例7: success
def success(request):
"""
The order has been succesfully processed.
We clear out the cart but let the payment processing get called by IPN
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request, _("Your order has already been processed."))
# Added to track total sold for each product
for item in order.orderitem_set.all():
product = item.product
product.total_sold += item.quantity
product.items_in_stock -= item.quantity
product.save()
log.warning(_("The contact is %s") % order.contact)
# Clean up cart now, the rest of the order will be cleaned on paypal IPN
for cart in Cart.objects.filter(customer=order.contact):
log.warning(_("Processing cart item %s") % cart.pk)
cart.empty()
del request.session["orderID"]
log.warning(request.session)
context = RequestContext(request, {"order": order})
return render_to_response("shop/checkout/success.html", context)
开发者ID:kidaa30,项目名称:pops,代码行数:27,代码来源:views.py
示例8: success
def success(request):
"""
The order has been succesfully processed.
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request, _('Your order has already been processed.'))
# register the transaction
order.add_status(status='New', notes=_("Order placed on ")+STORE_NAME)
#processor = get_processor_by_key('PAYMENT_PAYMENTSPRO')
#payment = processor.record_payment(order=order, amount=gross, transaction_id=txn_id)
# Added to track total sold for each product
for item in order.orderitem_set.all():
product = item.product
product.total_sold += item.quantity
product.items_in_stock -= item.quantity
product.save()
# Clean up cart now, (TODO:the rest of the order will be cleaned on paypal IPN)
#for cart in Cart.objects.filter(customer=order.contact):
# cart.empty()
cart = Cart.objects.from_request(request)
cart.empty()
del request.session['orderID']
context = RequestContext(request, {'order': order})
return render_to_response('shop/checkout/success.html', context)
开发者ID:marconius,项目名称:Satchmo-PayPal--PaymentsPro-,代码行数:32,代码来源:views.py
示例9: multisuccess_view
def multisuccess_view(request):
"""
The order has been succesfully processed.
This can be used to generate a receipt or some other confirmation
"""
target_view = None
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request,
_('Your order has already been processed.'))
del request.session['orderID']
payments_completed = order.payments_completed()
if payments_completed:
payment_completed = payments_completed[0].payment
else:
payment_completed = ''
shop = Config.objects.get_current()
postal_code = shop.postal_code
city = shop.city
phone = shop.phone
fax = ""
store_email = shop.store_email
store_name = shop.store_name
street1 = shop.street1
state = shop.state
p_iva = config_value('SHOP_CONFIG','VAT')
iban = config_value('SHOP_CONFIG','IBAN')
# Cablare il campo per il rilevamento della tipologia
# di pagamento
target_view = []
if payment_completed:
target_view.append(
"shop/checkout/success_%s.html" % payment_completed.lower()
)
target_view.append("shop/checkout/success_generic.html")
return render_to_response(
target_view,
{
'order': order,
'payment': payment_completed,
'p_iva' : p_iva,
'iban' : iban,
'store_postal_code' : postal_code,
'store_phone' : phone,
'store_fax' : fax,
'store_email' : store_email,
'store_name' : store_name,
'store_street1' : street1,
'store_state' : state,
'store_city' : city,
},
context_instance=RequestContext(request)
)
开发者ID:abstract-open-solutions,项目名称:satchmo-utils,代码行数:60,代码来源:views.py
示例10: get_product
def get_product(request, product_slug=None, selected_options=(),
default_view_tax=None):
"""Basic product view"""
errors = [m for m in get_messages(request) if m.level == constants.ERROR]
try:
product = Product.objects.get_by_site(active=True, slug=product_slug)
except Product.DoesNotExist:
return bad_or_missing(request, _('The product you have requested does not exist.'))
if default_view_tax is None:
default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
subtype_names = product.get_subtypes()
# Save product id for xheaders, in case we display a ConfigurableProduct
product_id = product.id
# Clone product object in order to have current product variations in context (extra_context)
current_product = product
if 'ProductVariation' in subtype_names:
selected_options = product.productvariation.unique_option_ids
#Display the ConfigurableProduct that this ProductVariation belongs to.
product = product.productvariation.parent.product
subtype_names = product.get_subtypes()
best_discount = find_best_auto_discount(product)
if errors:
error_message = errors[0]
else:
error_message = None
extra_context = {
'product': product,
'current_product' : current_product,
'default_view_tax': default_view_tax,
'sale': best_discount,
'error_message' : error_message,
}
# Get the template context from the Product.
extra_context = product.add_template_context(context=extra_context,
request=request, selected_options=selected_options,
default_view_tax=default_view_tax)
template = find_product_template(product, producttypes=subtype_names)
context = RequestContext(request, extra_context)
response = http.HttpResponse(template.render(context))
try:
from django.core.xheaders import populate_xheaders
populate_xheaders(request, response, Product, product_id)
except ImportError:
pass
return response
开发者ID:DrOctogon,项目名称:Satchmo,代码行数:58,代码来源:__init__.py
示例11: charge_remaining_post
def charge_remaining_post(request):
if not request.method == 'POST':
return bad_or_missing(request, _("No form found in request."))
data = request.POST.copy()
form = CustomChargeForm(data)
if form.is_valid():
data = form.cleaned_data
try:
orderitem = OrderItem.objects.get(pk = data['orderitem'])
except OrderItem.DoesNotExist:
return bad_or_missing(request, _("The orderitem you have requested doesn't exist, or you don't have access to it."))
price = data['amount']
line_price = price*orderitem.quantity
orderitem.unit_price = price
orderitem.line_item_price = line_price
orderitem.save()
#print "Orderitem price now: %s" % orderitem.line_item_price
order = orderitem.order
if not order.shipping_cost:
order.shipping_cost = Decimal("0.00")
if data['shipping']:
order.shipping_cost += data['shipping']
order.recalculate_total()
messages.add_message(request, messages.INFO, 'Charged for custom product and recalculated totals.')
notes = data['notes']
if not notes:
notes = 'Updated total price'
order.add_status(notes=notes)
return HttpResponseRedirect('/admin/shop/order/%i' % order.id)
else:
ctx = RequestContext(request, {'form': form})
return render_to_response('admin/charge_remaining_confirm.html',
context_instance=ctx)
开发者ID:eyeyunianto,项目名称:satchmo,代码行数:44,代码来源:balance.py
示例12: success
def success(request):
try:
order = Order.objects.get(id=request.session['orderID'])
except Order.DoesNotExist:
return bad_or_missing(request, _('Your order has already been processed.'))
del request.session['orderID']
return render_to_response('shop/checkout/bank_transfer/success.html',
{'order': order},
context_instance=RequestContext(request))
开发者ID:danieltellez,项目名称:satchmo-bank-transfer,代码行数:10,代码来源:views.py
示例13: variation_manager
def variation_manager(self, request, product_id = ""):
# Slightly more complicated here, but again, only filter for the
# current user's site if he's not a superuser. Redirect the actual
# work to satchmo's original method. In essence this method here is
# merely an authorization wrapper for #adminviews.variation_manager.
try:
if not request.user.is_superuser:
Product.objects.get(id=product_id, site__exact=request.user.get_profile().site)
return self.satchmo_variation_manager(request, product_id)
except Product.DoesNotExist:
return bad_or_missing(request, _('The product you have requested does not exist.'))
开发者ID:mpango,项目名称:satchmo-multishop,代码行数:11,代码来源:middleware.py
示例14: variation_manager
def variation_manager(request, product_id = ""):
try:
product = Product.objects.get(id=product_id)
subtypes = product.get_subtypes()
if 'ProductVariation' in subtypes:
# got a variation, we want to work with its parent
product = product.productvariation.parent.product
if 'ConfigurableProduct' in product.get_subtypes():
url = urlresolvers.reverse("satchmo_admin_variation_manager",
kwargs = {'product_id' : product.id})
return HttpResponseRedirect(url)
if 'ConfigurableProduct' not in subtypes:
return bad_or_missing(request, _('The product you have requested is not a Configurable Product.'))
except Product.DoesNotExist:
return bad_or_missing(request, _('The product you have requested does not exist.'))
if request.method == 'POST':
new_data = request.POST.copy()
form = VariationManagerForm(new_data, product=product)
if form.is_valid():
log.debug("Saving form")
try:
form.save(request)
except IntegrityError:
messages.error(request, _('The product you are attempting to remove is linked to an order and can not be removed.'))
# rebuild the form
form = VariationManagerForm(product=product)
else:
log.debug('errors on form')
else:
form = VariationManagerForm(product=product)
ctx = RequestContext(request, {
'product' : product,
'form' : form,
})
return render_to_response('product/admin/variation_manager.html',
context_instance=ctx)
开发者ID:DrOctogon,项目名称:Satchmo,代码行数:41,代码来源:adminviews.py
示例15: failure
def failure(request):
try:
order = Order.objects.from_request(request)
account = Account.objects.get(user=order.contact.user)
except Order.DoesNotExist:
return bad_or_missing(request, _("Your order has already been processed."))
return render_to_response(
"shop/checkout/reward_points/failure.html",
{"order": order, "account": account},
context_instance=RequestContext(request),
)
开发者ID:ubiquitousthey,项目名称:django-rewards,代码行数:12,代码来源:views.py
示例16: error
def error(request):
"""
The order has been succesfully with errors.
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request, _('Your order has already been processed.'))
return render_to_response('shop/checkout/creditcard/error.html',
{'order': order,},
context_instance=RequestContext(request))
开发者ID:abstract-open-solutions,项目名称:satchmo-utils,代码行数:12,代码来源:views.py
示例17: add
def add(request, id=0, redirect_to='satchmo_cart'):
"""Add an item to the cart."""
log.debug('FORM: %s', request.POST)
formdata = request.POST.copy()
productslug = None
productslug = formdata['productname']
durationSLUG =formdata['durationSLUG']
product = Product.objects.get_by_site(slug=productslug)
DK= PricingDate.objects.get(durationSLUG=durationSLUG)
durationkey= DK.pk
try:
if not (product and product.active):
log.debug("product %s is not active" % productslug)
return bad_or_missing(request, _("Computer says no."))
else:
log.debug("product %s is active" % productslug)
except (Product.DoesNotExist, MultiValueDictKeyError):
log.debug("Could not find product: %s", productslug)
return bad_or_missing(request, _('A tiny (huge) mistake has been made and this product can\'t be found.'))
cart = Cart.objects.from_request(request, create=True)
# send a signal so that listeners can update product details before we add it to the cart.
satchmo_cart_details_query.send(
cart,
product=product,
duration=DK,
request=request,
form=formdata
)
try:
duration= PricingDate.objects.get(pk=durationkey)
added_item = cart.add_item(product, duration)
except CartAddProhibited, cap:
return _product_error(request, product, cap.message)
开发者ID:connerfitzgerald,项目名称:Satchmo2,代码行数:39,代码来源:cart.py
示例18: success
def success(request):
"""
The order has been succesfully processed. This can be used to generate a receipt or some other confirmation
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
return bad_or_missing(request, _('Your order has already been processed.'))
del request.session['orderID']
context = RequestContext(request, {'order': order})
return render_to_response('shop/checkout/success.html',
context_instance=context)
开发者ID:twidi,项目名称:satchmo,代码行数:13,代码来源:views.py
示例19: success
def success(request):
"""
The order has been succesfully processed.
This can be used to generate a receipt or some other confirmation
"""
try:
order = Order.objects.from_request(request)
except Order.DoesNotExist:
bad_or_missing_message = 'Your order has already been processed.'
return bad_or_missing(request, _(bad_or_missing_message))
amount = order.balance
payment_module = config_get_group('PAYMENT_CREDITCARD')
processor = get_processor_by_key('PAYMENT_CREDITCARD')
account = request.GET.get('a', '')
ecripted_string = request.GET.get('b', '')
gpc = GestPayCrypt()
gpc.SetShopLogin(account)
gpc.SetShopTransactionID(str(order.id))
gpc.SetAmount("%.2f" % order.total)
gpc.SetEncryptedString(str(ecripted_string))
# if gpc.Decrypt() == 1 --> Transaction is OK
if gpc.Decrypt() == 1:
processor.record_payment(
order = order,
amount = amount,
transaction_id = gpc.GetBankTransactionID(),
reason_code = gpc.GetAuthorizationCode()
)
if order.notes is None:
order.notes = ""
else:
order.notes += "\n\n"
order.save()
order.add_status(
status = 'New',
notes = "Pagato mediante BANCASELLA"
)
# Make cart empty
cart = Cart.objects.from_request(request)
if cart:
cart.empty()
return render_to_response('shop/checkout/success_creditcard.html',
{'order': order,},
context_instance=RequestContext(request))
开发者ID:abstract-open-solutions,项目名称:satchmo-utils,代码行数:49,代码来源:views.py
示例20: remove_ticket
def remove_ticket(request):
if not request.POST:
return bad_or_missing(request, "Please use a POST request")
success, cart, cartitem, errors = _set_quantity(request, force_delete=True)
if request.is_ajax():
if errors:
return _json_response({'errors': errors, 'results': _("Error")}, True)
else:
return _json_response({
'cart_total': str(cart.total),
'cart_count': str(cart.numItems),
'item_id': cartitem.id,
'results': success, # Legacy
})
开发者ID:yanchenko-igor,项目名称:shop-ticket,代码行数:16,代码来源:views.py
注:本文中的satchmo_utils.views.bad_or_missing函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论