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


Python SerializerHelper.get_serialized方法代码示例

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


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

示例1: get_editing_dataset

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
    def get_editing_dataset(self, request):
        # Generate a pseudo-return when editing or creating a dataset.
        # Do not include the settings field; this will be set from the
        # input-form. Should approximately mirror the Visual API from rest-framework.

        dose_units = None
        try:
            dose_units = int(request.POST.get("dose_units"))
        except (TypeError, ValueError) as e:
            # TypeError if dose_units is None; ValueError if dose_units is ""
            pass

        data = {
            "title": request.POST.get("title"),
            "slug": request.POST.get("slug"),
            "caption": request.POST.get("caption"),
            "dose_units": dose_units,
            "created": datetime.now().isoformat(),
            "last_updated": datetime.now().isoformat()
        }

        data["endpoints"] = [
            SerializerHelper.get_serialized(e, json=False)
            for e in self.get_endpoints(request)
        ]

        data["studies"] = [
            SerializerHelper.get_serialized(s, json=False)
            for s in self.get_studies(request)
        ]

        return json.dumps(data)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:34,代码来源:models.py

示例2: to_representation

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret
开发者ID:shapiromatron,项目名称:hawc,代码行数:19,代码来源:serializers.py

示例3: get_json

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
开发者ID:liuduan,项目名称:hawc,代码行数:4,代码来源:models.py

示例4: get_docx_template_context

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
    def get_docx_template_context(cls, assessment, queryset):
        """
        Given a queryset of endpoints, invert the cached results to build
        a top-down data hierarchy from study to endpoint. We use this
        approach since our endpoints are cached, so while it may require
        more computation, its close to free on database access.
        """

        endpoints = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisEp in endpoints:
            thisAG = thisEp["animal_group"]
            thisExp = thisEp["animal_group"]["experiment"]
            thisStudy = thisEp["animal_group"]["experiment"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["exps"] = {}
                studies[study["id"]] = study

            exp = study["exps"].get(thisExp["id"])
            if exp is None:
                exp = thisExp
                exp["ags"] = {}
                study["exps"][exp["id"]] = exp

            ag = exp["ags"].get(thisAG["id"])
            if ag is None:
                ag = thisAG
                ag["eps"] = {}
                exp["ags"][ag["id"]] = ag

            ep = ag["eps"].get(thisEp["id"])
            if ep is None:
                ep = thisEp
                ag["eps"][ep["id"]] = ep

        # convert value dictionaries to lists
        studies = sorted(
            studies.values(),
            key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["exps"] = sorted(
                study["exps"].values(),
                key=lambda obj: (obj["name"].lower()))
            for exp in study["exps"]:
                exp["ags"] = sorted(
                    exp["ags"].values(),
                    key=lambda obj: (obj["name"].lower()))
                for ag in exp["ags"]:
                    ag["eps"] = sorted(
                        ag["eps"].values(),
                        key=lambda obj: (obj["name"].lower()))

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
开发者ID:JoshAddington,项目名称:hawc,代码行数:66,代码来源:models.py

示例5: d_response

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
 def d_response(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
开发者ID:JoshAddington,项目名称:hawc,代码行数:4,代码来源:models.py

示例6: get_docx_template_context

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
 def get_docx_template_context(assessment, queryset):
     studies = [SerializerHelper.get_serialized(study, json=False) for study in queryset]
     return {
         "assessment": AssessmentSerializer().to_representation(assessment),
         "studies": studies
     }
开发者ID:shapiromatron,项目名称:hawc,代码行数:8,代码来源:models.py

示例7: get_json

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import get_serialized [as 别名]
 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode, from_cache=False)
开发者ID:shapiromatron,项目名称:hawc,代码行数:4,代码来源:models.py


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