本文整理汇总了Python中django.core.cache.utils.make_template_fragment_key方法的典型用法代码示例。如果您正苦于以下问题:Python utils.make_template_fragment_key方法的具体用法?Python utils.make_template_fragment_key怎么用?Python utils.make_template_fragment_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.cache.utils
的用法示例。
在下文中一共展示了utils.make_template_fragment_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_config
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def user_config(self, data):
newd = dict(
list_display=data.getlist('list_display'),
list_only_date=data.get('list_only_date', 1)
)
content = json.dumps(newd)
config = Configure.objects.filter(
content_type=get_content_type_for_model(self.model),
onidc_id=self.onidc_id, creator=self.request.user,
mark='list').order_by('-pk')
if config.exists():
config = config.update(content=content)
else:
config = Configure.objects.create(
content_type=get_content_type_for_model(self.model),
onidc_id=self.onidc_id, creator=self.request.user,
mark='list', content=content)
key = utils.make_template_fragment_key("{}.{}.{}".format(
self.request.user.id, self.model_name, 'list'))
cache.delete(key)
return config
示例2: problem_update
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def problem_update(sender, instance, **kwargs):
if hasattr(instance, '_updating_stats_only'):
return
cache.delete_many([
make_template_fragment_key('submission_problem', (instance.id,)),
make_template_fragment_key('problem_feed', (instance.id,)),
'problem_tls:%s' % instance.id, 'problem_mls:%s' % instance.id,
])
cache.delete_many([make_template_fragment_key('problem_html', (instance.id, engine, lang))
for lang, _ in settings.LANGUAGES for engine in EFFECTIVE_MATH_ENGINES])
cache.delete_many([make_template_fragment_key('problem_authors', (instance.id, lang))
for lang, _ in settings.LANGUAGES])
cache.delete_many(['generated-meta-problem:%s:%d' % (lang, instance.id) for lang, _ in settings.LANGUAGES])
for lang, _ in settings.LANGUAGES:
unlink_if_exists(get_pdf_path('%s.%s.pdf' % (instance.code, lang)))
示例3: handle
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def handle(self, request, org, profile):
if profile.organizations.filter(id=org.id).exists():
return generic_message(request, _('Joining organization'), _('You are already in the organization.'))
if not org.is_open:
return generic_message(request, _('Joining organization'), _('This organization is not open.'))
max_orgs = settings.DMOJ_USER_MAX_ORGANIZATION_COUNT
if profile.organizations.filter(is_open=True).count() >= max_orgs:
return generic_message(
request, _('Joining organization'),
_('You may not be part of more than {count} public organizations.').format(count=max_orgs),
)
profile.organizations.add(org)
profile.save()
cache.delete(make_template_fragment_key('org_member_count', (org.id,)))
示例4: save
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def save(self, *args, **kwargs):
super(Partner, self).save(*args, **kwargs)
"""Invalidate this partner's pandoc-rendered html from cache"""
for code in RESOURCE_LANGUAGE_CODES:
short_description_cache_key = make_template_fragment_key(
"partner_short_description", [code, self.pk]
)
description_cache_key = make_template_fragment_key(
"partner_description", [code, self.pk]
)
send_instructions_cache_key = make_template_fragment_key(
"partner_send_instructions", [code, self.pk]
)
cache.delete(short_description_cache_key)
cache.delete(description_cache_key)
cache.delete(send_instructions_cache_key)
示例5: _config
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def _config(self):
key = utils.make_template_fragment_key("{}.{}.{}".format(
self.request.user.id, self.model_name, 'list'))
data = cache.get_or_set(key,
get_user_config(self.request.user, 'list', self.model), 180)
return data
示例6: make_cache_key
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def make_cache_key(key):
return cache_key.make_template_fragment_key(key)
示例7: render
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def render(self, context):
try:
expire_time = self.expire_time_var.resolve(context)
except VariableDoesNotExist:
raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var)
try:
expire_time = int(expire_time)
except (ValueError, TypeError):
raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
if self.cache_name:
try:
cache_name = self.cache_name.resolve(context)
except VariableDoesNotExist:
raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var)
try:
fragment_cache = caches[cache_name]
except InvalidCacheBackendError:
raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name)
else:
try:
fragment_cache = caches['template_fragments']
except InvalidCacheBackendError:
fragment_cache = caches['default']
vary_on = [var.resolve(context) for var in self.vary_on]
cache_key = make_template_fragment_key(self.fragment_name, vary_on)
value = fragment_cache.get(cache_key)
if value is None:
value = self.nodelist.render(context)
fragment_cache.set(cache_key, value, expire_time)
return value
示例8: post
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def post(self, request, *args, **kwargs):
# Delete cached data for the legends
legend_top_key = make_template_fragment_key('legend_partial_top')
cache.delete(legend_top_key)
legend_bottom_key = make_template_fragment_key('legend_partial_bottom')
cache.delete(legend_bottom_key)
# Delete cached data for the host format string
cache.delete('host_output_format_string')
return super(UpdateDynamicSettingsView, self).post(request, *args, **kwargs)
示例9: cache
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def cache(self, *args, **kwargs):
cache_alias = kwargs.get('cache_alias', DEFAULT_CACHE_ALIAS)
cache_key = kwargs.get('cache_key', kwargs['default_cache_key'])
if cache_key is None:
raise ValueError(
'You must set `cache_key` when the template is not a file.')
cache_key = make_template_fragment_key(cache_key, args)
out = caches[cache_alias].get(cache_key)
if out is None:
out = kwargs['caller']()
caches[cache_alias].set(cache_key, out, kwargs.get('timeout'))
return out
示例10: render
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def render(self, context):
try:
expire_time = self.expire_time_var.resolve(context)
except VariableDoesNotExist:
raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var)
if expire_time is not None:
try:
expire_time = int(expire_time)
except (ValueError, TypeError):
raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
if self.cache_name:
try:
cache_name = self.cache_name.resolve(context)
except VariableDoesNotExist:
raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var)
try:
fragment_cache = caches[cache_name]
except InvalidCacheBackendError:
raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name)
else:
try:
fragment_cache = caches['template_fragments']
except InvalidCacheBackendError:
fragment_cache = caches['default']
vary_on = [var.resolve(context) for var in self.vary_on]
cache_key = make_template_fragment_key(self.fragment_name, vary_on)
value = fragment_cache.get(cache_key)
if value is None:
value = self.nodelist.render(context)
fragment_cache.set(cache_key, value, expire_time)
return value
示例11: get
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def get(self, request, *args, **kwargs):
"""
Method that handles the GET requests for this view. Sets all other ``DataProduct``s to unfeatured in the
database, and sets the specified ``DataProduct`` to featured. Caches the featured image. Deletes previously
featured images from the cache.
"""
product_id = kwargs.get('pk', None)
product = DataProduct.objects.get(pk=product_id)
try:
current_featured = DataProduct.objects.filter(
featured=True,
data_product_type=product.data_product_type,
target=product.target
)
for featured_image in current_featured:
featured_image.featured = False
featured_image.save()
featured_image_cache_key = make_template_fragment_key(
'featured_image',
str(featured_image.target.id)
)
cache.delete(featured_image_cache_key)
except DataProduct.DoesNotExist:
pass
product.featured = True
product.save()
return redirect(reverse(
'tom_targets:detail',
kwargs={'pk': request.GET.get('target_id')})
)
示例12: invalidate_cache
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def invalidate_cache(self):
"""
Invalidate the HTML cache for all the publications of this researcher.
"""
for a in self.authors+[None]:
rpk = None
if a:
if a.researcher_id is None:
continue
else:
rpk = a.researcher_id
for lang in settings.POSSIBLE_LANGUAGE_CODES:
key = make_template_fragment_key(
'publiListItem', [self.pk, lang, rpk])
cache.delete(key)
示例13: profile_update
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def profile_update(sender, instance, **kwargs):
if hasattr(instance, '_updating_stats_only'):
return
cache.delete_many([make_template_fragment_key('user_about', (instance.id, engine))
for engine in EFFECTIVE_MATH_ENGINES] +
[make_template_fragment_key('org_member_count', (org_id,))
for org_id in instance.organizations.values_list('id', flat=True)])
示例14: contest_update
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def contest_update(sender, instance, **kwargs):
if hasattr(instance, '_updating_stats_only'):
return
cache.delete_many(['generated-meta-contest:%d' % instance.id] +
[make_template_fragment_key('contest_html', (instance.id, engine))
for engine in EFFECTIVE_MATH_ENGINES])
示例15: license_update
# 需要导入模块: from django.core.cache import utils [as 别名]
# 或者: from django.core.cache.utils import make_template_fragment_key [as 别名]
def license_update(sender, instance, **kwargs):
cache.delete(make_template_fragment_key('license_html', (instance.id,)))