本文整理汇总了Python中satchmo.configuration.config_value函数的典型用法代码示例。如果您正苦于以下问题:Python config_value函数的具体用法?Python config_value怎么用?Python config_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了config_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_with_akismet
def check_with_akismet(comment=None, request=None, **kwargs):
if config_value("PRODUCT", "AKISMET_ENABLE"):
key = config_value("PRODUCT", "AKISMET_KEY")
if key:
site = Site.objects.get_current()
shop = urlresolvers.reverse('satchmo_shop_home')
from akismet import Akismet
akismet = Akismet(
key=settings.AKISMET_API_KEY,
blog_url='http://%s' % url_join(site.domain, shop))
if akismet.verify_key():
akismet_data = { 'comment_type': 'comment',
'referrer': request.META.get('HTTP_REFERER', ""),
'user_ip': comment.ip_address,
'user_agent': '' }
if akismet_api.comment_check(smart_str(comment.comment), data=akismet_data, build_data=True):
comment.is_public=False
comment.save()
log.info("Akismet marked comment #%i as spam", comment.id)
else:
log.debug("Akismet accepted comment #%i", comment.id)
else:
log.warn("Akismet key '%s' not accepted by akismet service.", key)
else:
log.info("Akismet enabled, but no key found. Please put in your admin settings.")
示例2: process
def process(self, order=None):
"""
Calculate the tax and return it
"""
if order:
self.order = order
else:
order = self.order
percent = config_value("TAX", "PERCENT")
sub_total = Decimal("0.00")
for item in order.orderitem_set.filter(product__taxable=True):
sub_total += item.sub_total
itemtax = sub_total * (percent / 100)
taxrates = {"%i%%" % percent: itemtax}
if config_value("TAX", "TAX_SHIPPING"):
shipping = order.shipping_sub_total
sub_total += shipping
ship_tax = shipping * (percent / 100)
taxrates["Shipping"] = ship_tax
tax = sub_total * (percent / 100)
return tax, taxrates
示例3: order_payload
def order_payload(order):
data = {}
data["api_key"] = config_value("satchmo.fulfilment.modules.six", "API_KEY")
data["test"] = config_value("satchmo.fulfilment.modules.six", "TEST_MODE")
data["allow_preorder"] = config_value("satchmo.fulfilment.modules.six", "ALLOW_PREORDER")
data["update_stock"] = config_value("satchmo.fulfilment.modules.six", "UPDATE_STOCK")
data["order"] = {}
despatch_url = external_url(reverse("six_despatch", kwargs={"order_id": order.id, "verification_hash": order.verification_hash}))
data["order"]["client_ref"] = order.id
data["order"]["po_number"] = order.id
data["order"]["date_placed"] = unicode(order.time_stamp)
data["order"]["callback_url"] = despatch_url
data["order"]["postage_speed"] = order.shipping_postage_speed
data["order"]["postage_cost"] = float_price(order.shipping_cost)
data["order"]["total_amount"] = float_price(order.sub_total)
data["order"]["signed_for"] = order.shipping_signed_for
data["order"]["tracked"] = order.shipping_tracked
data["order"]["ShippingContact"] = {
"dear": order.contact.user.first_name,
"name": order.ship_addressee,
"email": order.contact.user.email,
"phone": get_phone_number(order),
"address": order.ship_street1,
"address_contd": order.ship_street2,
"city": order.ship_city,
"county": order.ship_state,
"country": unicode(order.ship_country),
"postcode": order.ship_postal_code,
}
data["order"]["BillingContact"] = {
"name": order.bill_addressee,
"email": order.contact.user.email,
"phone": get_phone_number(order),
"address": order.bill_street1,
"address_contd": order.bill_street2,
"city": order.bill_city,
"county": order.bill_state,
"country": unicode(order.bill_country),
"postcode": order.bill_postal_code,
}
data["order"]["items"] = [
{
# Six limits slugs to 40 characters. Six stores
# client_refs with a length of 40 characters (truncated
# silently). When passing a > 40 character slug, the
# whole slug is checked against the 40 character
# client_ref and doesn't match. So, we just truncate
# slugs to 40 characters.
"client_ref": item.product.slug[:40],
"quantity": item.quantity,
"price": float_price(item.unit_price),
}
for item in order.orderitem_set.all()
]
return json.dumps(data)
示例4: make_urlpatterns
def make_urlpatterns():
patterns = []
for key in config_value('PAYMENT', 'MODULES'):
cfg = config_get(key, 'MODULE')
modulename = cfg.editor_value
urlmodule = "%s.urls" % modulename
patterns.append(url(config_value(key, 'URL_BASE'), [urlmodule, modulename, '']))
return tuple(patterns)
示例5: test_custom_product
def test_custom_product(self):
"""
Verify that the custom product is working as expected.
"""
pm = config_get("PRODUCT", "PRODUCT_TYPES")
pm.update(
[
"product::ConfigurableProduct",
"product::ProductVariation",
"product::CustomProduct",
"product::SubscriptionProduct",
]
)
response = self.client.get(prefix + "/")
self.assertContains(response, "Computer", count=1)
response = self.client.get(prefix + "/product/satchmo-computer/")
self.assertContains(response, "Memory", count=1)
self.assertContains(response, "Case", count=1)
self.assertContains(response, "Monogram", count=1)
response = self.client.post(
prefix + "/cart/add/",
{"productname": "satchmo-computer", "5": "1.5gb", "6": "mid", "custom_monogram": "CBM", "quantity": 1},
)
self.assertRedirects(response, prefix + "/cart/", status_code=302, target_status_code=200)
response = self.client.get(prefix + "/cart/")
self.assertContains(response, '/satchmo-computer/">satchmo computer', count=1, status_code=200)
self.assertContains(response, smart_str("%s168.00" % config_value("SHOP", "CURRENCY")), count=3)
self.assertContains(response, smart_str("Monogram: CBM %s10.00" % config_value("SHOP", "CURRENCY")), count=1)
self.assertContains(
response, smart_str("Case - External Case: Mid %s10.00" % config_value("SHOP", "CURRENCY")), count=1
)
self.assertContains(
response, smart_str("Memory - Internal RAM: 1.5 GB %s25.00" % config_value("SHOP", "CURRENCY")), count=1
)
response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US))
self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200)
data = {
"credit_type": "Visa",
"credit_number": "4485079141095836",
"month_expires": "1",
"year_expires": "2012",
"ccv": "552",
"shipping": "FlatRate",
}
response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data)
self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200)
response = self.client.get(url("DUMMY_satchmo_checkout-step3"))
self.assertContains(
response,
smart_str("satchmo computer - %s168.00" % config_value("SHOP", "CURRENCY")),
count=1,
status_code=200,
)
response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"})
self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200)
self.assertEqual(len(mail.outbox), 1)
示例6: process
def process(self):
"""
Calculate the tax and return it
"""
subtotal = self.order.sub_total - self.order.discount
if config_value('TAX','TAX_SHIPPING'):
subtotal += self.order.shipping_cost
percent = config_value('TAX','PERCENT')
return subtotal * (percent/100)
示例7: test_checkout
def test_checkout(self):
"""
Run through a full checkout process
"""
cache_delete()
tax = config_get("TAX", "MODULE")
tax.update("satchmo.tax.modules.percent")
pcnt = config_get("TAX", "PERCENT")
pcnt.update("10")
shp = config_get("TAX", "TAX_SHIPPING")
shp.update(False)
self.test_cart_adding()
response = self.client.post(url("satchmo_checkout-step1"), get_step1_post_data(self.US))
self.assertRedirects(response, url("DUMMY_satchmo_checkout-step2"), status_code=302, target_status_code=200)
data = {
"credit_type": "Visa",
"credit_number": "4485079141095836",
"month_expires": "1",
"year_expires": "2009",
"ccv": "552",
"shipping": "FlatRate",
}
response = self.client.post(url("DUMMY_satchmo_checkout-step2"), data)
self.assertRedirects(response, url("DUMMY_satchmo_checkout-step3"), status_code=302, target_status_code=200)
response = self.client.get(url("DUMMY_satchmo_checkout-step3"))
self.assertContains(
response, smart_str("Shipping + %s4.00" % config_value("SHOP", "CURRENCY")), count=1, status_code=200
)
self.assertContains(
response, smart_str("Tax + %s4.60" % config_value("SHOP", "CURRENCY")), count=1, status_code=200
)
self.assertContains(
response, smart_str("Total = %s54.60" % config_value("SHOP", "CURRENCY")), count=1, status_code=200
)
response = self.client.post(url("DUMMY_satchmo_checkout-step3"), {"process": "True"})
self.assertRedirects(response, url("DUMMY_satchmo_checkout-success"), status_code=302, target_status_code=200)
self.assertEqual(len(mail.outbox), 1)
# Log in as a superuser
user = User.objects.create_user("fredsu", "[email protected]", "passwd")
user.is_staff = True
user.is_superuser = True
user.save()
self.client.login(username="fredsu", password="passwd")
# Test pdf generation
response = self.client.get("/admin/print/invoice/1/")
self.assertContains(response, "reportlab", status_code=200)
response = self.client.get("/admin/print/packingslip/1/")
self.assertContains(response, "reportlab", status_code=200)
response = self.client.get("/admin/print/shippinglabel/1/")
self.assertContains(response, "reportlab", status_code=200)
示例8: display_featured
def display_featured():
"""
Used by the index generic view to choose how the featured products are displayed.
Items can be displayed randomly or all in order
"""
random_display = config_value('SHOP','RANDOM_FEATURED')
num_to_display = config_value('SHOP','NUM_DISPLAY')
q = Product.objects.featured_by_site()
if not random_display:
return q[:num_to_display]
else:
return q.order_by('?')[:num_to_display]
示例9: _get_shipping_choices
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False):
"""Iterate through legal shipping modules, building the list for display to the user.
Returns the shipping choices list, along with a dictionary of shipping choices, useful
for building javascript that operates on shipping choices.
"""
shipping_options = []
shipping_dict = {}
if not cart.is_shippable:
methods = [shipping_method_by_key('NoShipping'), ]
else:
methods = shipping_methods()
valid_methods = []
for method in methods:
method.calculate(cart, contact)
if method.valid():
valid_methods.append((method, method.cost()))
# sort methods by cost
valid_methods.sort(key=lambda method_cost: int(method_cost[1]))
for method, shipcost in valid_methods:
template = lookup_template(paymentmodule, 'shipping_options.html')
t = loader.get_template(template)
shipping_tax = None
taxed_shipping_price = None
if config_value('TAX', 'TAX_SHIPPING'):
shipping_tax = config_value('TAX', 'TAX_CLASS')
taxer = _get_taxprocessor(request)
total = shipcost + taxer.by_price(shipping_tax, shipcost)
taxed_shipping_price = money_format(total)
data = {
'amount': shipcost,
'description': method.description(),
'method': method.method(),
'expected_delivery': method.expectedDelivery(),
'default_view_tax': default_view_tax,
'shipping_tax': shipping_tax,
'taxed_shipping_price': taxed_shipping_price
}
if hasattr(method, 'shipping_discount'):
data['discount'] = method.shipping_discount()
c = RequestContext(request, data)
shipping_options.append((method.id, t.render(c)))
shipping_dict[method.id] = shipcost
return shipping_options, shipping_dict
示例10: shipping
def shipping(self, subtotal=None):
if subtotal is None and self.order:
subtotal = self.order.shipping_sub_total
if subtotal:
subtotal = self.order.shipping_sub_total
if config_value("TAX", "TAX_SHIPPING"):
percent = config_value("TAX", "PERCENT")
t = subtotal * (percent / 100)
else:
t = Decimal("0.00")
else:
t = Decimal("0.00")
return t
示例11: get_newsletter_module
def get_newsletter_module():
try:
modulename = config_value("NEWSLETTER", "MODULE")
except AttributeError:
modulename = "satchmo.newsletter.ignore"
return load_module(modulename)
示例12: home
def home(request, template="base_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('SHOP','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, ctx)
示例13: cartitem_total
def cartitem_total(parser, token):
"""Returns the line total for the cartitem, possibly with tax added. If currency evaluates true,
then return the total formatted through money_format.
Example::
{% cartitem_total cartitem [show_tax] [currency] %}
"""
tokens = token.contents.split()
if len(tokens) < 2:
raise template.TemplateSyntaxError, "'%s' tag requires a cartitem argument" % tokens[0]
cartitem = tokens[1]
if len(tokens) > 2:
show_tax = tokens[2]
else:
show_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
if len(tokens) >3:
show_currency = tokens[3]
else:
show_currency = 'True'
return CartitemTotalNode(cartitem, show_currency, show_tax)
示例14: displayDoc
def displayDoc(request, id, doc):
# Create the HttpResponse object with the appropriate PDF headers for an invoice or a packing slip
order = get_object_or_404(Order, pk=id)
shopDetails = Config.objects.get_current()
filename_prefix = shopDetails.site.domain
if doc == "invoice":
filename = "%s-invoice.pdf" % filename_prefix
template = "invoice.rml"
elif doc == "packingslip":
filename = "%s-packingslip.pdf" % filename_prefix
template = "packing-slip.rml"
elif doc == "shippinglabel":
filename = "%s-shippinglabel.pdf" % filename_prefix
template = "shipping-label.rml"
else:
return HttpResponseRedirect('/admin')
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
icon_uri = config_value('SHOP', 'LOGO_URI')
t = loader.get_template(os.path.join('pdf', template))
c = Context({
'filename' : filename,
'iconURI' : icon_uri,
'shopDetails' : shopDetails,
'order' : order,
})
pdf = trml2pdf.parseString(smart_str(t.render(c)))
response.write(pdf)
return response
示例15: __init__
def __init__(self, request, payment_module):
self.request = request
self.paymentModule = payment_module
processor_module = payment_module.MODULE.load_module('processor')
self.processor = processor_module.PaymentProcessor(self.paymentModule)
self.viewTax = config_value('TAX', 'DEFAULT_VIEW_TAX')
self.order = None
self.cart = None
self.extra_context = {}
#to override the form_handler, set this
#otherwise it will use the built-in `_onForm`
self.onForm = self._onForm
#to override the success method, set this
#othewise it will use the built-in `_onSuccess`
self.onSuccess = self._onSuccess
#false on any "can not continue" error
self.valid = False
#the value to be returned from the view
#an HttpResponse or a HttpRedirect
self.response = None
self.processorMessage = ""
self.processorReasonCode = ""
self.processorResults = None
self.templates = {
'CONFIRM' : 'checkout/confirm.html',
'EMPTY_CART': 'checkout/empty_cart',
'404': 'shop_404.html',
}