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


Python Bundle.obj方法代码示例

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


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

示例1: save

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import obj [as 别名]
    def save(self):
        """ Implements the save method so this form can be used in regular django views.

            It does the same validation that it usually does for the API, but instead of
            creating a JSON response, it just creates the object and then returns it.
        """
        assert hasattr(self, 'request')
        assert self.type == 'create' or self.type == 'update'

        # Use the form's cleaned_data to create a bundle
        bundle = Bundle()
        bundle.data = self.cleaned_data
        if hasattr(self, 'request'):
            bundle.request = self.request
        if hasattr(self, 'instance'):
            bundle.obj = self.instance

        # Use the resource's methods to save the bundle
        self.resource.request = self.request
        if self.type == 'create':
            bundle = self.resource.obj_create(bundle)
        elif self.type == 'update':
            assert self.request != None
            assert bundle.obj != None
            bundle = self.resource.obj_update(bundle, self.request)

        # Return the object
        return bundle.obj
开发者ID:mliu7,项目名称:tastypie-extensions,代码行数:30,代码来源:forms.py

示例2: dehydrate

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import obj [as 别名]
 def dehydrate(self, bundle, for_list=False):
     print 1
     if not bundle.obj or not bundle.obj.pk:
         print 2
         if not self.null:
             raise ApiFieldError("The model '%r' does not have a primary key and can not be d in a ToMany context." % bundle.obj)
         return []
     if not getattr(bundle.obj, self.attribute):
         print 3
         if not self.null:
             raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't all a null value." % (bundle.obj, self.attribute))
         return []
     self.m2m_resources = []
     m2m_dehydrated = []
     # TODO: Also model-specific and leaky. Relies on there being a
     # ``Manager`` there.
     # NOTE: only had to remove .all()
     print 4
     for m2m in getattr(bundle.obj, self.attribute):
         print 5
         m2m_resource = self.get_related_resource(m2m)
         m2m_bundle = Bundle(obj=m2m)
         self.m2m_resources.append(m2m_resource)
         # youhou, dirty hack again baby!
         m2m_bundle.obj = type("DummyContainer", (object,), {'pk': m2m_bundle.obj})
         m2m_dehydrated.append(self.dehydrate_related(m2m_bundle, m2m_resource))
     return m2m_dehydrated
开发者ID:Psycojoker,项目名称:django-tastypie-nonrel,代码行数:29,代码来源:fields.py

示例3: hydrate_lang

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import obj [as 别名]
    def hydrate_lang(self, bundle):
        translated_bundle = Bundle()
        translation_resource = I4pProjectTranslationEditResource()

        for language_code, language_data in bundle.data["lang"].iteritems():
            if language_code not in dict(LANGUAGES):
                continue
            translated_bundle.data = language_data
            translated_bundle.obj = bundle.obj.translate(language_code)
            translation_resource.obj_create(translated_bundle)

        return bundle
开发者ID:LittleFancy,项目名称:imaginationforpeople,代码行数:14,代码来源:project.py

示例4: delete_detail

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import obj [as 别名]
    def delete_detail(self, request, **kwargs):
        from freenasUI.freeadmin.navtree import navtree
        bundle = Bundle(request=request)
        bundle.obj = self.obj_get(bundle=bundle, **self.remove_api_resource_names(kwargs))
        if bundle.obj._meta.model._admin.delete_form:
            deserialized = self.deserialize(
                request,
                request.body or '{}',
                format=request.META.get('CONTENT_TYPE', 'application/json'),
            )

            Form = __import__(
                f'{bundle.obj._meta.app_label}.forms',
                globals(),
                locals(),
                [bundle.obj._meta.model._admin.delete_form],
                0,
            )
            Form = getattr(Form, bundle.obj._meta.model._admin.delete_form)

            form = Form(data=deserialized, instance=bundle.obj)
            if not form.is_valid():
                raise ImmediateHttpResponse(
                    response=self.error_response(request, form.errors)
                )

        # Grab the form to call delete on same as in freeadmin
        m = bundle.obj._meta.model
        mf = None
        if not isinstance(navtree._modelforms[m], dict):
            mf = navtree._modelforms[m]
        else:
            if mf is None:
                try:
                    mf = navtree._modelforms[m][m._admin.edit_modelform]
                except Exception:
                    mf = list(navtree._modelforms[m].values())[-1]
            else:
                mf = navtree._modelforms[m][mf]

        if mf:
            form = mf(instance=bundle.obj)
            form.delete()
            return http.HttpNoContent()
        else:
            return super().delete_detail(request, **kwargs)
开发者ID:freenas,项目名称:freenas,代码行数:48,代码来源:utils.py


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