本文整理汇总了Python中django.core.cache.cache.get方法的典型用法代码示例。如果您正苦于以下问题:Python cache.get方法的具体用法?Python cache.get怎么用?Python cache.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.cache.cache
的用法示例。
在下文中一共展示了cache.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choose_product
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def choose_product(request, order_id, product_id=None, target_url="orders-add_product"):
"""
order_id can be either Service Order or Purchase Order
"""
data = {'order': order_id}
data['action'] = request.path
data['target_url'] = target_url
if request.method == "POST":
query = request.POST.get('q')
if len(query) > 2:
products = Product.objects.filter(
Q(code__icontains=query) | Q(title__icontains=query)
)
data['products'] = products
return render(request, 'products/choose-list.html', data)
return render(request, 'products/choose.html', data)
示例2: get_customer
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def get_customer(request):
"""Return the selected customer data."""
if not request.user.is_authenticated():
raise PermissionDenied
if not request.GET.get('c'):
return
customer = get_object_or_404(Customer, pk=request.GET['c'])
request.session['checkin_customer'] = customer.pk
fdata = {'fname': customer.firstname, 'lname': customer.lastname}
fdata['city'] = customer.city
fdata['email'] = customer.email
fdata['phone'] = customer.phone
fdata['country'] = customer.country
fdata['postal_code'] = customer.zip_code
fdata['address'] = customer.street_address
return json_response(fdata)
示例3: model_from_slug
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def model_from_slug(product_line, model=None):
"""
Returns product description for model slug or models dict for
the specified product line
"""
if not cache.get("slugmap"):
slugmap = {} # Map model slug to corresponding product description
product_lines = gsxws.products.models()
for k, v in product_lines.items():
d = {}
for p in v['models']:
slug = slugify(p)
d[slug] = p
slugmap[k] = d
cache.set("slugmap", slugmap)
models = cache.get("slugmap").get(product_line)
if model is not None:
return models.get(model)
return models
示例4: update_gsx_details
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def update_gsx_details(request, pk):
"""
Updates devices GSX warranty details
"""
device = get_object_or_404(Device, pk=pk)
try:
GsxAccount.default(request.user)
device.update_gsx_details()
messages.success(request, _("Warranty status updated successfully"))
except Exception as e:
messages.error(request, e)
if request.session.get('return_to'):
return redirect(request.session['return_to'])
return redirect(device)
示例5: close
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def close(request, pk):
"""Close this Service Order."""
order = get_object_or_404(Order, pk=pk)
if request.method == 'POST':
try:
order.close(request.user)
except Exception as e:
messages.error(request, e)
return redirect(order)
if request.session.get("current_order_id"):
del(request.session['current_order_id'])
del(request.session['current_order_code'])
del(request.session['current_order_customer'])
messages.success(request, _('Order %s closed') % order.code)
return redirect(order)
data = {'order': order, 'action': reverse(close, args=[pk])}
return render(request, "orders/close.html", data)
示例6: accessories
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def accessories(request, pk, device_id):
from django.utils import safestring
if request.POST.get('name'):
a = Accessory(name=request.POST['name'])
a.order_id = pk
a.device_id = device_id
a.save()
choice_list = []
choices = Accessory.objects.distinct('name')
for c in choices:
choice_list.append(c.name)
action = reverse('orders-accessories', args=[pk, device_id])
selected = Accessory.objects.filter(order_id=pk, device_id=device_id)
choices_json = safestring.mark_safe(json.dumps(choice_list))
return render(request, 'devices/accessories_edit.html', locals())
示例7: choose_customer
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def choose_customer(request, pk):
"""
Lets the user search for a customer for this order
"""
if request.method == "POST":
customers = Customer.objects.none()
kind = request.POST.get('kind')
query = request.POST.get('name')
if len(query) > 2:
customers = Customer.objects.filter(
Q(fullname__icontains=query) | Q(email__icontains=query) | Q(phone__contains=query)
)
if kind == 'companies':
customers = customers.filter(is_company=True)
if kind == 'contacts':
customers = customers.filter(is_company=False)
data = {'customers': customers, 'order_id': pk}
return render(request, "customers/choose-list.html", data)
data = {'action': request.path}
return render(request, 'customers/choose.html', data)
示例8: calculate_price
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def calculate_price(self, price, shipping=0.0):
"""
Calculates price and returns it w/ and w/o tax
"""
conf = Configuration.conf()
shipping = shipping or 0.0
if not isinstance(shipping, Decimal):
shipping = Decimal(shipping)
margin = get_margin(price)
vat = Decimal(conf.get("pct_vat", 0.0))
# TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
# @TODO: make rounding configurable!
wo_tax = ((price*100)/(100-margin)+shipping).to_integral_exact(rounding=ROUND_CEILING)
with_tax = (wo_tax*(vat+100)/100).to_integral_exact(rounding=ROUND_CEILING)
return wo_tax, with_tax
示例9: sell
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def sell(self, amount, location):
"""
Deduct product from inventory with specified location
"""
if not self.track_inventory():
return
try:
inventory = Inventory.objects.get(product=self, location=location)
try:
inventory.amount_stocked = inventory.amount_stocked - amount
inventory.amount_reserved = inventory.amount_reserved - amount
except Exception as e:
# @TODO: Would be nice to trigger a warning
pass
inventory.save()
except Inventory.DoesNotExist:
raise ValueError(_(u"Product %s not found in inventory.") % self.code)
示例10: add_cleanup_pod
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def add_cleanup_pod(url):
"""populate the cleanup pod list"""
# variance allows a pod to stay alive past grace period
variance = random.uniform(0.1, 1.5)
grace = round(settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS * variance)
# save
pods = cache.get('cleanup_pods', {})
pods[url] = (datetime.utcnow() + timedelta(seconds=grace))
cache.set('cleanup_pods', pods)
# add grace period timestamp
pod = cache.get(url)
grace = settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS
pd = datetime.utcnow() + timedelta(seconds=grace)
timestamp = str(pd.strftime(MockSchedulerClient.DATETIME_FORMAT))
pod['metadata']['deletionTimestamp'] = timestamp
cache.set(url, pod)
示例11: remove_cache_item
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def remove_cache_item(url, resource_type):
# remove data object from individual cache
cache.delete(url)
# get rid of log element as well for pods
if resource_type == 'pod':
cache.delete(url + '_log')
# remove from the resource type global scope
items = cache.get(resource_type, [])
if url in items:
items.remove(url)
cache.set(resource_type, items, None)
# remove from namespace specific scope
# sneaky way of getting data up to the resource type without too much magic
cache_url = ''.join(url.partition(resource_type)[0:2])
items = cache.get(cache_url, [])
if url in items:
items.remove(url)
cache.set(cache_url, items, None)
示例12: get_annotation_tree
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def get_annotation_tree():
ann_path = ServerSettings.annotation_path(None)
filename = os.path.join(ann_path, 'covered.json')
if not os.path.exists(filename):
return None
tree = cache.get('ui_ann', None)
if tree is None:
tree = XPathTree('/', None)
with open(filename, 'r') as f:
profile = json.load(f)
for line in profile.get('data', []):
tree.insert(line, profile.get('annotate', None))
cache.set('ui_ann', tree)
else:
print 'From cache..'
return tree
示例13: annotate
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def annotate(nodes, tree=None):
"""
Args:
nodes: list lxml element tree nodes with lazy tree instance
Returns:
Annotated nodes with attribute and value specified in annotation file
"""
if not tree:
tree = get_annotation_tree()
if tree and nodes:
for node in nodes:
xpath = node.get('path', '')
instance = tree.search(xpath)
if not instance:
continue
for attr, value in instance.attrib.items():
node.set(attr, value)
annotate(list(node), tree)
return nodes
示例14: test_no_querylist
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def test_no_querylist(self):
"""
A view with no querylist and no `get_querylist` overwrite should raise
an assertion error with the appropriate message
"""
view = NoQuerylistView.as_view()
request = factory.get('/')
with self.assertRaises(AssertionError) as error:
view(request).render()
self.assertEqual(str(error.exception), (
'NoQuerylistView should either include a `querylist` attribute, '
'or override the `get_querylist()` method.'
))
示例15: test_no_queryset
# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import get [as 别名]
def test_no_queryset(self):
"""
A querylist with no `queryset` key should raise a ValidationError with the
appropriate message
"""
view = NoQuerysetView.as_view()
request = factory.get('/')
with self.assertRaises(ValidationError) as error:
view(request).render()
self.assertEqual(error.exception.message, (
'All items in the NoQuerysetView querylist attribute '
'should contain a `queryset` key'
))