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


Python cache.delete方法代码示例

本文整理汇总了Python中django.core.cache.cache.delete方法的典型用法代码示例。如果您正苦于以下问题:Python cache.delete方法的具体用法?Python cache.delete怎么用?Python cache.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.cache.cache的用法示例。


在下文中一共展示了cache.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete_user

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_user(request, user_id):
    user = get_object_or_404(User, pk=user_id)

    if request.method == "POST":
        if user == request.user:
            messages.error(request, _('Deleting yourself is not allowed'))
            return redirect(list_users)
        try:
            user.delete()
            messages.success(request, _("User deleted"))
        except Exception as e:
            messages.error(request, e)

        return redirect(list_users)

    return render(request, "admin/users/remove.html", locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:18,代码来源:admin.py

示例2: delete_location

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_location(request, pk):
    location = get_object_or_404(Location, pk=pk)

    if request.method == 'POST':
        try:
            location.delete()
            messages.success(request, _(u'%s deleted') % location.title)
        except Exception as e:
            messages.error(request, e)

        return redirect(locations)

    title = _(u'Really delete this location?')
    explanation = _(u'This will not delete the orders at this location')

    return render(request, 'generic/delete.html', locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:18,代码来源:admin.py

示例3: delete_pod

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_pod(url, data, request):
    # Try to determine the connected RC / RS to readjust pod count
    # One way is to look at annotations:kubernetes.io/created-by and read
    # the serialized reference but that looks clunky right now

    # Try RC first and then RS
    if 'pod-template-hash' in data['metadata']['labels']:
        controllers = filter_data({'labels': data['metadata']['labels']}, 'replicasets')
    else:
        controllers = filter_data({'labels': data['metadata']['labels']}, 'replicationcontrollers')

    if controllers:
        controller = controllers.pop()
        upsert_pods(controller, cache_key(request.path))
    else:
        # delete individual item
        delete_pods([url], 1, 0) 
开发者ID:deis,项目名称:controller,代码行数:19,代码来源:mock.py

示例4: remove_cache_item

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [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) 
开发者ID:deis,项目名称:controller,代码行数:22,代码来源:mock.py

示例5: user_config

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [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

示例6: business_area_handler

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def business_area_handler(request, pk):
    if request.method == 'POST':
        data = json.loads(request.body)
        if pk is None:
            # New business area
            BusinessArea.objects.create(name=data['name'])
            return JsonResponse(ReturnStatus(True, 'OK').to_dict())
        else:
            # existing business area update
            try:
                ba = BusinessArea.objects.get(pk=pk)
                ba.name = data['name']
                ba.save()
            except BusinessArea.DoesNotExist:
                return JsonResponse(ReturnStatus(False, 'Key does not exist').to_dict())
            return JsonResponse(ReturnStatus(True, 'OK').to_dict())
    elif request.method == 'DELETE':
        try:
            ba = BusinessArea.objects.get(pk=pk)
            if ba.mission_set.all().count() != 0:
                return JsonResponse(ReturnStatus(False, 'Business Areas can not be deleted while missions are still associated with them.').to_dict())
            ba.delete()
        except BusinessArea.DoesNotExist:
            return JsonResponse(ReturnStatus(False, 'Key does not exist').to_dict())
        return JsonResponse(ReturnStatus(True, 'OK').to_dict()) 
开发者ID:lmco,项目名称:dart,代码行数:27,代码来源:views.py

示例7: chunk_list_generator

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def chunk_list_generator(lst, chunksize):
    """ Generator that chunks a list ``lst`` into sublists of size ``chunksize`` """

    if lst:
        chunksize = max(chunksize, 1)
        for i in xrange(0, len(lst), chunksize):
            yield lst[i:i + chunksize]


#def queryset_batch_delete(queryset, batch_size=100000, show_progress=False):
    #""" Delete a large queryset, batching into smaller queries (sometimes huge
    #commands crash) """
    #if show_progress:
        #print 'queryset_batch_delete: fetching ids for %s' % queryset.model
    #ids = queryset.values_list('pk', flat=True)
    #if len(ids) <= batch_size:
        #queryset.delete()
    #else:
        #iterator = range(0, len(ids), batch_size)
        #if show_progress:
            #progress.bar(iterator)
        #for i in iterator:
            #queryset.filter(pk__in=ids[i:i+batch_size]).delete()
    #return len(ids) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:26,代码来源:utils.py

示例8: handle

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [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

示例9: delete

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete(self, *args, **kwargs):
        directory = self.directory

        # Just doing a plain delete will collect all related objects in memory
        # before deleting: translation projects, stores, units, quality checks,
        # suggestions, and submissions.
        # This can easily take down a process. If we do a translation project
        # at a time and force garbage collection, things stay much more
        # managable.
        import gc

        gc.collect()
        for tp in self.translationproject_set.iterator():
            tp.delete()
            gc.collect()

        super().delete(*args, **kwargs)

        directory.delete() 
开发者ID:evernote,项目名称:zing,代码行数:21,代码来源:models.py

示例10: invalidate_resources_cache

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def invalidate_resources_cache(**kwargs):
    instance = kwargs["instance"]
    if instance.__class__.__name__ not in ["Directory", "Store"]:
        return

    # Don't invalidate if the save didn't create new objects
    no_new_objects = ("created" in kwargs and "raw" in kwargs) and (
        not kwargs["created"] or kwargs["raw"]
    )

    if no_new_objects and instance.parent.get_children():
        return

    proj_code = split_pootle_path(instance.pootle_path)[1]
    if proj_code is not None:
        cache.delete(make_method_key(Project, "resources", proj_code)) 
开发者ID:evernote,项目名称:zing,代码行数:18,代码来源:models.py

示例11: update_organizations_dict

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def update_organizations_dict(cls, instance, **kwargs):
        if hasattr(instance, 'user'):
            user = instance.user
        else:
            user = instance.organization_user.user
        cache_key = 'user_{}_organizations'.format(user.pk)
        cache.delete(cache_key)
        # forces caching
        user.organizations_dict 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:11,代码来源:apps.py

示例12: edit_gsx_account

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def edit_gsx_account(request, pk=None):
    object_list = GsxAccount.objects.all()
    title = GsxAccount._meta.verbose_name_plural

    if pk is None:
        act = GsxAccount()
    else:
        act = GsxAccount.objects.get(pk=pk)

    form = GsxAccountForm(instance=act)

    if request.method == 'POST':
        form = GsxAccountForm(request.POST, instance=act)
        if form.is_valid():
            try:
                act = form.save()
                cache.delete('gsx_session')
                try:
                    act.test()
                    messages.success(request, _(u'%s saved') % act.title)
                    return redirect(list_gsx_accounts)
                except gsxws.GsxError as e:
                    messages.warning(request, e)
            except IntegrityError:
                transaction.rollback()
                msg = _('GSX account for this sold-to and environment already exists')
                messages.error(request, msg)

    return render(request, 'admin/gsx/form.html', locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:31,代码来源:admin.py

示例13: delete_gsx_account

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_gsx_account(request, pk=None):
    act = get_object_or_404(GsxAccount, pk=pk)
    if request.method == 'POST':
        try:
            act.delete()
            messages.success(request, _("GSX account deleted"))
        except Exception as e:
            messages.error(request, e)

        return redirect(list_gsx_accounts)

    return render(request, 'admin/gsx/remove.html', {'action': request.path}) 
开发者ID:fpsw,项目名称:Servo,代码行数:14,代码来源:admin.py

示例14: delete_checklist

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_checklist(request, pk):
    checklist = Checklist.objects.get(pk=pk)

    if request.method == 'POST':
        checklist.delete()
        messages.success(request, _('Checklist deleted'))
        return redirect(checklists)

    title = _('Really delete this checklist?')
    explanation = _('This will also delete all checklist values.')

    return render(request, 'generic/delete.html', locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:14,代码来源:admin.py

示例15: delete_tag

# 需要导入模块: from django.core.cache import cache [as 别名]
# 或者: from django.core.cache.cache import delete [as 别名]
def delete_tag(request, pk):
    tag = get_object_or_404(Tag, pk=pk)

    if request.method == 'POST':
        tag.delete()
        messages.success(request, _('Tag deleted'))
        return redirect(tags, type=tag.type)

    title = _('Really delete this tag?')
    action = str(request.path)

    return render(request, 'generic/delete.html', locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:14,代码来源:admin.py


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