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


Python NestedObjects.nested方法代码示例

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


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

示例1: get_related_objects

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
 def get_related_objects(self, flatten=False):
     """
     Returns all objects related to the current.
     """
     collector = NestedObjects(using='default')
     collector.collect([self])
     if flatten:
         return list(utils.flatten(collector.nested()))
     return collector.nested()
开发者ID:charlierm,项目名称:muroc,代码行数:11,代码来源:models.py

示例2: deletion_tree

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def deletion_tree(obj):
    ''' Return a list of all nested objects that will be deleted '''
    collector = NestedObjects(using=obj._state.db)
    collector.collect([obj])
    def format_callback(obj):
        return u'%s: %s' % (force_text(obj._meta.verbose_name), force_text(obj))
    return collector.nested(format_callback)
开发者ID:gloggi,项目名称:etat,代码行数:9,代码来源:deletion.py

示例3: get_context_data

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
 def get_context_data(self, *args, **kwargs):
     context = super(DeleteView, self).get_context_data(*args, **kwargs)
     using = router.db_for_write(self.model)
     collector = NestedObjects(using=using)
     collector.collect([self.object])
     context["related_objects"] = collector.nested()
     return context
开发者ID:jericksanjuan,项目名称:django-crudwrapper,代码行数:9,代码来源:views.py

示例4: delete_user

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def delete_user(request, uid):
    user = get_object_or_404(Dojo_User, id=uid)
    form = DeleteUserForm(instance=user)

    from django.contrib.admin.util import NestedObjects
    from django.db import DEFAULT_DB_ALIAS

    collector = NestedObjects(using=DEFAULT_DB_ALIAS)
    collector.collect([user])
    rels = collector.nested()

    if user.id == request.user.id:
        messages.add_message(request,
                             messages.ERROR,
                             'You may not delete yourself.',
                             extra_tags='alert-danger')
        return HttpResponseRedirect(reverse('edit_user', args=(user.id,)))

    if request.method == 'POST':
        if 'id' in request.POST and str(user.id) == request.POST['id']:
            form = DeleteUserForm(request.POST, instance=user)
            if form.is_valid():
                user.delete()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'User and relationships removed.',
                                     extra_tags='alert-success')
                return HttpResponseRedirect(reverse('users'))
    add_breadcrumb(title="Delete User", top_level=False, request=request)
    return render(request, 'dojo/delete_user.html',
                  {'to_delete': user,
                   'form': form,
                   'rels': rels,
                   })
开发者ID:YSaxon,项目名称:django-DefectDojo,代码行数:36,代码来源:views.py

示例5: ui_model_delete_device

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def ui_model_delete_device(request, umdid):
    uim_device = UIModelDevice.objects.get(id=umdid)

    if uim_device.uimodel.is_frozen:
        return render(request, 'mcms/uimodels/frozen.html',
                      dict(uimodel=uim_device.uimodel))

    collector = NestedObjects(using='default')
    collector.collect([uim_device, ])
    to_delete = collector.nested()

    if request.method == 'POST':  # The user has already confirmed the delete.
        uim_device.delete()

        return HttpResponseRedirect(
            reverse('mcms:uimodels:details', kwargs={
                'mid': uim_device.uimodel.id}))

    opts = uim_device._meta
    object_name = force_unicode(opts.verbose_name)
    title = ('Are you sure?')

    context = {
        'title': title,
        'object_name': object_name,
        'object': uim_device,
        'deleted_objects': to_delete,
        'opts': opts,
        'app_label': opts.app_label,
    }

    return TemplateResponse(
        request,
        'mcms/uimodels/delete_confirmation.html', context, current_app='Test')
开发者ID:dlparker,项目名称:mcms-proto,代码行数:36,代码来源:views.py

示例6: delete_engagement

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def delete_engagement(request, eid):
    engagement = get_object_or_404(Engagement, pk=eid)
    product = engagement.product
    form = DeleteEngagementForm(instance=engagement)

    from django.contrib.admin.util import NestedObjects
    from django.db import DEFAULT_DB_ALIAS

    collector = NestedObjects(using=DEFAULT_DB_ALIAS)
    collector.collect([engagement])
    rels = collector.nested()

    if request.method == 'POST':
        if 'id' in request.POST and str(engagement.id) == request.POST['id']:
            form = DeleteEngagementForm(request.POST, instance=engagement)
            if form.is_valid():
                engagement.delete()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Engagement and relationships removed.',
                                     extra_tags='alert-success')
                return HttpResponseRedirect(reverse('view_product', args=(product.id,)))

    add_breadcrumb(parent=engagement, title="Delete", top_level=False, request=request)

    return render(request, 'dojo/delete_engagement.html',
                  {'engagement': engagement,
                   'form': form,
                   'rels': rels,
                   })
开发者ID:jdua,项目名称:django-DefectDojo,代码行数:32,代码来源:views.py

示例7: viewmap_delete_page

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def viewmap_delete_page(request, vsid):
    page = get_object_or_404(Page, pk=vsid)
    uim = page.uimodel

    if uim.is_frozen:
        return render(request, 'mcms/uimodels/frozen.html', dict(uimodel=uim))

    collector = NestedObjects(using='default')
    collector.collect([page])
    to_delete = collector.nested()

    if request.method == 'POST':
        page.delete()

        return HttpResponseRedirect(reverse('mcms:uimodels:edit_viewmap',
                                    kwargs={'vmid': page.viewmap.id}))

    opts = page._meta
    object_name = force_unicode(opts.verbose_name)
    title = ('Are you sure?')

    context = {
        'title': title,
        'object_name': object_name,
        'object': page,
        'deleted_objects': to_delete,
        'opts': opts,
        'app_label': opts.app_label,
    }

    return TemplateResponse(
        request,
        'mcms/uimodels/delete_confirmation.html', context, current_app='Test')
开发者ID:dlparker,项目名称:mcms-proto,代码行数:35,代码来源:views.py

示例8: delete_survey

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def delete_survey(request, sid):
    survey = get_object_or_404(Engagement_Survey, id=sid)
    form = Delete_Eng_Survey_Form(instance=survey)

    from django.contrib.admin.util import NestedObjects
    from django.db import DEFAULT_DB_ALIAS

    collector = NestedObjects(using=DEFAULT_DB_ALIAS)
    collector.collect([survey])
    rels = collector.nested()

    if request.method == 'POST':
        if 'id' in request.POST and str(survey.id) == request.POST['id']:
            form = Delete_Eng_Survey_Form(request.POST, instance=survey)
            if form.is_valid():
                survey.delete()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Survey and relationships removed.',
                                     extra_tags='alert-success')
                return HttpResponseRedirect(reverse('survey'))
    add_breadcrumb(title="Delete Survey", top_level=False, request=request)
    return render(request, 'defectDojo-engagement-survey/delete_survey.html',
                  {'survey': survey,
                   'form': form,
                   'rels': rels,
                   })
开发者ID:aaronweaver,项目名称:defectDojo-engagement-survey,代码行数:29,代码来源:views.py

示例9: get_deleted_objects

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def get_deleted_objects(obj, user):
    """
    Find all objects related to ``obj`` that should also be deleted. 

    Returns a nested list of strings suitable for display in the
    template with the ``unordered_list`` filter.
    
    Copied and updated from django.contrib.admin.util for front end display.

    """
    using = router.db_for_write(obj.__class__)
    collector = NestedObjects(using=using)
    collector.collect([obj])
    perms_needed = set()

    def format_callback(obj):
        opts = obj._meta

        if hasattr(obj, "get_absolute_url"):
            url = obj.get_absolute_url()
            p = "%s.%s" % (opts.app_label, opts.get_delete_permission())
            if not user.has_perm(p):
                perms_needed.add(opts.verbose_name)
            # Display a link to the admin page.
            return mark_safe(u'%s: <a href="%s">%s</a>' % (escape(capfirst(opts.verbose_name)), url, escape(obj)))
        else:
            # no link
            return u"%s: %s" % (capfirst(opts.verbose_name), force_unicode(obj))

    to_delete = collector.nested(format_callback)

    protected = [format_callback(obj) for obj in collector.protected]

    return to_delete, perms_needed, protected
开发者ID:kunthar,项目名称:tendenci,代码行数:36,代码来源:utils.py

示例10: list_deleted_objects

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def list_deleted_objects(obj):
    model = obj.__class__
    def format_callback(item):
        return u'%s: %s' % (item._meta.verbose_name.capitalize(), force_unicode(item))

    collector = NestedObjects(using=router.db_for_write(model))
    collector.collect(model.objects.filter(id=obj.id))
    to_delete = collector.nested(format_callback)

    return {'to_delete': to_delete}
开发者ID:artminster,项目名称:artminster,代码行数:12,代码来源:common_tags.py

示例11: make_mobile_numbers_unique

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def make_mobile_numbers_unique(users):
    for user in users:
        collector = NestedObjects(using=DEFAULT_DB_ALIAS)
        collector.collect([user])
        items = collector.nested()
        for item in items:
            if isinstance(item, User):
                continue
            else:
                unique_instances = set([str(instance.__class__.__name__) for instance in item])
                if len(unique_instances) == 1:
                    pass
开发者ID:klpdotorg,项目名称:dubdubdub,代码行数:14,代码来源:create_user_accounts.py

示例12: NestedObjectsTests

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
class NestedObjectsTests(TestCase):
    """
    Tests for ``NestedObject`` utility collection.

    """

    def setUp(self):
        self.n = NestedObjects(using=DEFAULT_DB_ALIAS)
        self.objs = [Count.objects.create(num=i) for i in range(5)]

    def _check(self, target):
        self.assertEqual(self.n.nested(lambda obj: obj.num), target)

    def _connect(self, i, j):
        self.objs[i].parent = self.objs[j]
        self.objs[i].save()

    def _collect(self, *indices):
        self.n.collect([self.objs[i] for i in indices])

    def test_unrelated_roots(self):
        self._connect(2, 1)
        self._collect(0)
        self._collect(1)
        self._check([0, 1, [2]])

    def test_siblings(self):
        self._connect(1, 0)
        self._connect(2, 0)
        self._collect(0)
        self._check([0, [1, 2]])

    def test_non_added_parent(self):
        self._connect(0, 1)
        self._collect(0)
        self._check([0])

    def test_cyclic(self):
        self._connect(0, 2)
        self._connect(1, 0)
        self._connect(2, 1)
        self._collect(0)
        self._check([0, [1, [2]]])

    def test_queries(self):
        self._connect(1, 0)
        self._connect(2, 0)
        # 1 query to fetch all children of 0 (1 and 2)
        # 1 query to fetch all children of 1 and 2 (none)
        # Should not require additional queries to populate the nested graph.
        self.assertNumQueries(2, self._collect, 0)
开发者ID:nimbis,项目名称:django,代码行数:53,代码来源:tests.py

示例13: NestedObjectsTests

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
class NestedObjectsTests(TestCase):
    """
    Tests for ``NestedObject`` utility collection.

    """

    def setUp(self):
        self.n = NestedObjects()
        self.objs = [Count.objects.create(num=i) for i in range(5)]

    def _check(self, target):
        self.assertEquals(self.n.nested(lambda obj: obj.num), target)

    def _add(self, obj, parent=None):
        # don't bother providing the extra args that NestedObjects ignores
        self.n.add(None, None, obj, None, parent)

    def test_unrelated_roots(self):
        self._add(self.objs[0])
        self._add(self.objs[1])
        self._add(self.objs[2], self.objs[1])

        self._check([0, 1, [2]])

    def test_siblings(self):
        self._add(self.objs[0])
        self._add(self.objs[1], self.objs[0])
        self._add(self.objs[2], self.objs[0])

        self._check([0, [1, 2]])

    def test_duplicate_instances(self):
        self._add(self.objs[0])
        self._add(self.objs[1])
        dupe = Count.objects.get(num=1)
        self._add(dupe, self.objs[0])

        self._check([0, 1])

    def test_non_added_parent(self):
        self._add(self.objs[0], self.objs[1])

        self._check([0])

    def test_cyclic(self):
        self._add(self.objs[0], self.objs[2])
        self._add(self.objs[1], self.objs[0])
        self._add(self.objs[2], self.objs[1])
        self._add(self.objs[0], self.objs[2])

        self._check([0, [1, [2]]])
开发者ID:,项目名称:,代码行数:53,代码来源:

示例14: related_objects

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def related_objects(obj):
    """ Return a generator to the objects that would be deleted if we delete "obj" (excluding obj) """

    collector = NestedObjects(using=router.db_for_write(obj))
    collector.collect([obj])

    def flatten(elem):
        if isinstance(elem, list):
            return itertools.chain.from_iterable(map(flatten, elem))
        elif obj != elem:
            return (elem,)
        return ()

    return flatten(collector.nested())
开发者ID:Bazzinga,项目名称:django-safedelete,代码行数:16,代码来源:utils.py

示例15: _get_deleted_objects

# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import nested [as 别名]
def _get_deleted_objects(objs):
    """
    Slightly simplified version of the function used in the standard admin
    """

    if len(objs) == 0:
        return []

    collector = NestedObjects(using=router.db_for_write(objs[0]))
    collector.collect(objs)

    def format_callback(obj):
        return '%s: %s' % (obj.__class__.__name__, unicode(obj))

    return collector.nested(format_callback)
开发者ID:animekita,项目名称:selvbetjening,代码行数:17,代码来源:event.py


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