当前位置: 首页>>代码示例>>Python>>正文


Python utils.make_template_fragment_key方法代码示例

本文整理汇总了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 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:23,代码来源:list.py

示例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))) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:19,代码来源:signals.py

示例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,))) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:19,代码来源:organization.py

示例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) 
开发者ID:WikipediaLibrary,项目名称:TWLight,代码行数:18,代码来源:models.py

示例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 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:8,代码来源:list.py

示例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) 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:4,代码来源:utils.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:cache.py

示例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) 
开发者ID:lmco,项目名称:dart,代码行数:14,代码来源:views.py

示例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 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:15,代码来源:jinja2ext.py

示例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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:34,代码来源:cache.py

示例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')})
        ) 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:32,代码来源:views.py

示例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) 
开发者ID:dissemin,项目名称:dissemin,代码行数:17,代码来源:models.py

示例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)]) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:10,代码来源:signals.py

示例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]) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:9,代码来源:signals.py

示例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,))) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:4,代码来源:signals.py


注:本文中的django.core.cache.utils.make_template_fragment_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。